Skip to content

Commit 950f2d7

Browse files
Fixed labels permadiff in notebooks instance (#4615) (#3096)
* Fixed labels permadiff in notebooks instance * Corrected variable names for suppress func Signed-off-by: Modular Magician <[email protected]>
1 parent a89cc88 commit 950f2d7

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

.changelog/4615.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
notebooks: Fixed permadiff on labels for `google_notebook_instance`
3+
```

google-beta/resource_dataproc_cluster_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import (
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1515

16-
dataproc "google.golang.org/api/dataproc/v1beta2"
1716
"google.golang.org/api/googleapi"
17+
18+
dataproc "google.golang.org/api/dataproc/v1beta2"
1819
)
1920

2021
func TestDataprocExtractInitTimeout(t *testing.T) {

google-beta/resource_notebooks_instance.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2846
func resourceNotebooksInstance() *schema.Resource {
2947
return &schema.Resource{
3048
Create: resourceNotebooksInstanceCreate,
@@ -190,8 +208,10 @@ your VM instance's service account can use the instance.`,
190208
Format: 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.
196216
An 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

Comments
 (0)