Skip to content

Commit

Permalink
Add resource manager tags to GKE autopilot (#10123) (#17715)
Browse files Browse the repository at this point in the history
[upstream:bfba12eddf8df83158695e72c68411967367e017]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Mar 28, 2024
1 parent 1ba50ab commit 853ecc6
Show file tree
Hide file tree
Showing 5 changed files with 504 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/10123.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: added `node_pool_auto_config.resource_manager_tags` field to `google_container_cluster` resource
```
1 change: 0 additions & 1 deletion google/services/container/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,6 @@ func flattenResourceManagerTags(c *container.ResourceManagerTags) map[string]int
for k, v := range c.Tags {
rmt[k] = v
}

}

return rmt
Expand Down
30 changes: 30 additions & 0 deletions google/services/container/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,11 @@ func ResourceContainerCluster() *schema.Resource {
},
},
},
"resource_manager_tags": {
Type: schema.TypeMap,
Optional: true,
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.`,
},
},
},
},
Expand Down Expand Up @@ -3818,6 +3823,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
log.Printf("[INFO] GKE cluster %s node pool auto config network tags have been updated", d.Id())
}

if d.HasChange("node_pool_auto_config.0.resource_manager_tags") {
rmtags := d.Get("node_pool_auto_config.0.resource_manager_tags")

req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredNodePoolAutoConfigResourceManagerTags: expandResourceManagerTags(rmtags),
},
}

updateF := updateFunc(req, "updating GKE cluster node pool auto config resource manager tags")
// Call update serially.
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s node pool auto config resource manager tags have been updated", d.Id())
}

d.Partial(false)

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

if v, ok := config["resource_manager_tags"]; ok && len(v.(map[string]interface{})) > 0 {
npac.ResourceManagerTags = expandResourceManagerTags(v)
}

return npac
}

Expand Down Expand Up @@ -5646,6 +5673,9 @@ func flattenNodePoolAutoConfig(c *container.NodePoolAutoConfig) []map[string]int
if c.NetworkTags != nil {
result["network_tags"] = flattenNodePoolAutoConfigNetworkTags(c.NetworkTags)
}
if c.ResourceManagerTags != nil {
result["resource_manager_tags"] = flattenResourceManagerTags(c.ResourceManagerTags)
}

return []map[string]interface{}{result}
}
Expand Down
Loading

0 comments on commit 853ecc6

Please sign in to comment.