@@ -19,12 +19,30 @@ import (
1919 "log"
2020 "reflect"
2121 "strconv"
22+ "strings"
2223 "time"
2324
2425 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2526 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
2627)
2728
29+ const notebooksInstanceGoogleProvidedLabel = "goog-caip-notebook"
30+
31+ func NotebooksInstanceLabelDiffSuppress (k , old , new string , d * schema.ResourceData ) bool {
32+ // Suppress diffs for the label provided by Google
33+ if strings .Contains (k , notebooksInstanceGoogleProvidedLabel ) && new == "" {
34+ return true
35+ }
36+
37+ // Let diff be determined by labels (above)
38+ if strings .Contains (k , "labels.%" ) {
39+ return true
40+ }
41+
42+ // For other keys, don't suppress diff.
43+ return false
44+ }
45+
2846func resourceNotebooksInstance () * schema.Resource {
2947 return & schema.Resource {
3048 Create : resourceNotebooksInstanceCreate ,
@@ -190,8 +208,10 @@ your VM instance's service account can use the instance.`,
190208Format: projects/{project_id}/locations/{location}/keyRings/{key_ring_id}/cryptoKeys/{key_id}` ,
191209 },
192210 "labels" : {
193- Type : schema .TypeMap ,
194- Optional : true ,
211+ Type : schema .TypeMap ,
212+ Computed : true ,
213+ Optional : true ,
214+ DiffSuppressFunc : NotebooksInstanceLabelDiffSuppress ,
195215 Description : `Labels to apply to this instance. These can be later modified by the setLabels method.
196216An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.` ,
197217 Elem : & schema.Schema {Type : schema .TypeString },
0 commit comments