Skip to content

Commit 853ecc6

Browse files
Add resource manager tags to GKE autopilot (#10123) (#17715)
[upstream:bfba12eddf8df83158695e72c68411967367e017] Signed-off-by: Modular Magician <[email protected]>
1 parent 1ba50ab commit 853ecc6

File tree

5 files changed

+504
-2
lines changed

5 files changed

+504
-2
lines changed

.changelog/10123.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: added `node_pool_auto_config.resource_manager_tags` field to `google_container_cluster` resource
3+
```

google/services/container/node_config.go

-1
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,6 @@ func flattenResourceManagerTags(c *container.ResourceManagerTags) map[string]int
11401140
for k, v := range c.Tags {
11411141
rmt[k] = v
11421142
}
1143-
11441143
}
11451144

11461145
return rmt

google/services/container/resource_container_cluster.go

+30
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,11 @@ func ResourceContainerCluster() *schema.Resource {
13011301
},
13021302
},
13031303
},
1304+
"resource_manager_tags": {
1305+
Type: schema.TypeMap,
1306+
Optional: true,
1307+
Description: `A map of resource manager tags. Resource manager tag keys and values have the same definition as resource manager tags. Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/456. The field is ignored (both PUT & PATCH) when empty.`,
1308+
},
13041309
},
13051310
},
13061311
},
@@ -3818,6 +3823,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
38183823
log.Printf("[INFO] GKE cluster %s node pool auto config network tags have been updated", d.Id())
38193824
}
38203825

3826+
if d.HasChange("node_pool_auto_config.0.resource_manager_tags") {
3827+
rmtags := d.Get("node_pool_auto_config.0.resource_manager_tags")
3828+
3829+
req := &container.UpdateClusterRequest{
3830+
Update: &container.ClusterUpdate{
3831+
DesiredNodePoolAutoConfigResourceManagerTags: expandResourceManagerTags(rmtags),
3832+
},
3833+
}
3834+
3835+
updateF := updateFunc(req, "updating GKE cluster node pool auto config resource manager tags")
3836+
// Call update serially.
3837+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
3838+
return err
3839+
}
3840+
3841+
log.Printf("[INFO] GKE cluster %s node pool auto config resource manager tags have been updated", d.Id())
3842+
}
3843+
38213844
d.Partial(false)
38223845

38233846
if _, err := containerClusterAwaitRestingState(config, project, location, clusterName, userAgent, d.Timeout(schema.TimeoutUpdate)); err != nil {
@@ -4903,6 +4926,10 @@ func expandNodePoolAutoConfig(configured interface{}) *container.NodePoolAutoCon
49034926
npac.NetworkTags = expandNodePoolAutoConfigNetworkTags(v)
49044927
}
49054928

4929+
if v, ok := config["resource_manager_tags"]; ok && len(v.(map[string]interface{})) > 0 {
4930+
npac.ResourceManagerTags = expandResourceManagerTags(v)
4931+
}
4932+
49064933
return npac
49074934
}
49084935

@@ -5646,6 +5673,9 @@ func flattenNodePoolAutoConfig(c *container.NodePoolAutoConfig) []map[string]int
56465673
if c.NetworkTags != nil {
56475674
result["network_tags"] = flattenNodePoolAutoConfigNetworkTags(c.NetworkTags)
56485675
}
5676+
if c.ResourceManagerTags != nil {
5677+
result["resource_manager_tags"] = flattenResourceManagerTags(c.ResourceManagerTags)
5678+
}
56495679

56505680
return []map[string]interface{}{result}
56515681
}

0 commit comments

Comments
 (0)