Skip to content

Commit bf15b60

Browse files
modular-magicianslevenick
authored andcommitted
Add DSF on resource_labels in node_config (#12877) (#21082)
[upstream:8e47ba07a90f6b6aa3376fda0fcd7529e99a529b] Signed-off-by: Modular Magician <[email protected]>
1 parent c875b30 commit bf15b60

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

.changelog/12877.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
container: fixed a diff caused by server-side set values for `node_config.resource_labels`
3+
```

google/services/container/node_config.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
package container
44

55
import (
6+
"strings"
7+
68
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
79
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
810

@@ -234,10 +236,11 @@ func schemaNodeConfig() *schema.Schema {
234236
},
235237

236238
"resource_labels": {
237-
Type: schema.TypeMap,
238-
Optional: true,
239-
Elem: &schema.Schema{Type: schema.TypeString},
240-
Description: `The GCE resource labels (a map of key/value pairs) to be applied to the node pool.`,
239+
Type: schema.TypeMap,
240+
Optional: true,
241+
Elem: &schema.Schema{Type: schema.TypeString},
242+
DiffSuppressFunc: containerNodePoolResourceLabelsDiffSuppress,
243+
Description: `The GCE resource labels (a map of key/value pairs) to be applied to the node pool.`,
241244
},
242245

243246
"local_ssd_count": {
@@ -1572,6 +1575,21 @@ func flattenWorkloadMetadataConfig(c *container.WorkloadMetadataConfig) []map[st
15721575
return result
15731576
}
15741577

1578+
func containerNodePoolResourceLabelsDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
1579+
// Suppress diffs for server-specified labels prefixed with "goog-gke"
1580+
if strings.Contains(k, "resource_labels.goog-gke") && new == "" {
1581+
return true
1582+
}
1583+
1584+
// Let diff be determined by resource_labels (above)
1585+
if strings.Contains(k, "resource_labels.%") {
1586+
return true
1587+
}
1588+
1589+
// For other keys, don't suppress diff.
1590+
return false
1591+
}
1592+
15751593
func flattenKubeletConfig(c *container.NodeKubeletConfig) []map[string]interface{} {
15761594
result := []map[string]interface{}{}
15771595
if c != nil {

0 commit comments

Comments
 (0)