Skip to content

Commit

Permalink
Add resource manager tags to GKE autopilot (GoogleCloudPlatform#10123)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxi-cit authored and pawelJas committed May 16, 2024
1 parent a4d694c commit 77ac575
Show file tree
Hide file tree
Showing 4 changed files with 502 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
if v,ok := nodeConfig["enable_confidential_storage"]; ok {
nc.EnableConfidentialStorage = v.(bool)
}

<% unless version == "ga" -%>
if v, ok := nodeConfig["host_maintenance_policy"]; ok {
nc.HostMaintenancePolicy = expandHostMaintenancePolicy(v)
Expand Down Expand Up @@ -1249,7 +1249,6 @@ func flattenResourceManagerTags(c *container.ResourceManagerTags) map[string]int
for k, v := range c.Tags {
rmt[k] = v
}

}

return rmt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,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 @@ -4162,6 +4167,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)

<% unless version == 'ga' -%>
Expand Down Expand Up @@ -5426,6 +5449,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 @@ -6234,6 +6261,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 77ac575

Please sign in to comment.