Skip to content

Commit

Permalink
Add Resource Manager Tags support to 'google_container_cluster' (Goog…
Browse files Browse the repository at this point in the history
…leCloudPlatform#9531)

* resourceManagerTags added to Cluster Node Config schema

* update beta tag

* add cluster and node proto tests

* add expand and flatten proto

* removed beta tag

* added to documentation

* added resource manager tags to auto pilot

* migrating resourceManagerTags tests

* migrating node_pools test

* migrating additional tests

* minor fixes

* fixing tests

* add in-place update support

* fixed tests

* fixed annotations

* validated clusters and node pools tests. Isolated node pool auto config

* isolated resource manager tags from docs

* fixed permission issue

* fixed spaces

* fixed non determinism on tag keys

* removed auto_pilot rmts

* fixed time_sleep

* add depends_on to IAM policies
  • Loading branch information
maxi-cit authored and balanaguharsha committed Apr 19, 2024
1 parent 43c8da3 commit 0c4720d
Show file tree
Hide file tree
Showing 7 changed files with 635 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ func ResourceComputeInstance() *schema.Resource {
},
},

"params": {
"params": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Expand All @@ -673,7 +673,7 @@ func ResourceComputeInstance() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: `A set of key/value label pairs assigned to the instance.

**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
},
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error creating instance while setting the security policies: %s", err)
}
<% end -%>

err = waitUntilInstanceHasDesiredStatus(config, d)
if err != nil {
return fmt.Errorf("Error waiting for status: %s", err)
Expand Down Expand Up @@ -1936,7 +1936,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Instance had unexpected number of network interfaces: %d", len(instance.NetworkInterfaces))
}

<% unless version == 'ga' -%>
<% unless version == 'ga' -%>
updateSecurityPolicy := false
for i := 0; i < len(instance.NetworkInterfaces); i++ {
prefix := fmt.Sprintf("network_interface.%d", i)
Expand Down
40 changes: 38 additions & 2 deletions mmv1/third_party/terraform/services/container/node_config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@ func schemaNodeConfig() *schema.Schema {
},
},
},
"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.`,
},
<% unless version == 'ga' -%>
"enable_confidential_storage": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -884,6 +889,10 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
nc.ResourceLabels = m
}

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

if v, ok := nodeConfig["tags"]; ok {
tagsList := v.([]interface{})
tags := []string{}
Expand Down Expand Up @@ -974,7 +983,7 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
nc.EnableConfidentialStorage = v.(bool)
}
<% end -%>

<% unless version == "ga" -%>
if v, ok := nodeConfig["host_maintenance_policy"]; ok {
nc.HostMaintenancePolicy = expandHostMaintenancePolicy(v)
Expand All @@ -988,6 +997,19 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
return nc
}

func expandResourceManagerTags(v interface{}) *container.ResourceManagerTags {
rmts := make(map[string]string)

if v != nil {
rmts = tpgresource.ConvertStringMap(v.(map[string]interface{}))
}

return &container.ResourceManagerTags{
Tags: rmts,
ForceSendFields: []string{"Tags"},
}
}

func expandWorkloadMetadataConfig(v interface{}) *container.WorkloadMetadataConfig {
if v == nil {
return nil
Expand Down Expand Up @@ -1213,7 +1235,8 @@ func flattenNodeConfig(c *container.NodeConfig, v interface{}) []map[string]inte
"advanced_machine_features": flattenAdvancedMachineFeaturesConfig(c.AdvancedMachineFeatures),
"sole_tenant_config": flattenSoleTenantConfig(c.SoleTenantConfig),
"fast_socket": flattenFastSocket(c.FastSocket),
<% unless version == 'ga' -%>
"resource_manager_tags": flattenResourceManagerTags(c.ResourceManagerTags),
<% unless version == 'ga' -%>
"enable_confidential_storage": c.EnableConfidentialStorage,
<% end -%>
})
Expand All @@ -1225,6 +1248,19 @@ func flattenNodeConfig(c *container.NodeConfig, v interface{}) []map[string]inte
return config
}

func flattenResourceManagerTags(c *container.ResourceManagerTags) map[string]interface{} {
rmt := make(map[string]interface{})

if c != nil {
for k, v := range c.Tags {
rmt[k] = v
}

}

return rmt
}

func flattenAdvancedMachineFeaturesConfig(c *container.AdvancedMachineFeatures) []map[string]interface{} {
result := []map[string]interface{}{}
if c != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ var (
forceNewClusterNodeConfigFields = []string{
"labels",
"workload_metadata_config",
"resource_manager_tags",
}

suppressDiffForAutopilot = schema.SchemaDiffSuppressFunc(func(k, oldValue, newValue string, d *schema.ResourceData) bool {
Expand Down Expand Up @@ -1424,11 +1425,11 @@ func ResourceContainerCluster() *schema.Resource {
"node_pool_defaults": clusterSchemaNodePoolDefaults(),

"node_pool_auto_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Description: `Node pool configs that apply to all auto-provisioned node pools in autopilot clusters and node auto-provisioning enabled clusters.`,
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Description: `Node pool configs that apply to all auto-provisioned node pools in autopilot clusters and node auto-provisioning enabled clusters.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network_tags": {
Expand Down Expand Up @@ -5266,7 +5267,7 @@ func expandFleet(configured interface{}) *container.Fleet {
return &container.Fleet{
Project: config["project"].(string),
}
}
}

func expandEnableK8sBetaApis(configured interface{}, enabledAPIs []string) *container.K8sBetaAPIConfig {
l := configured.([]interface{})
Expand Down Expand Up @@ -5424,6 +5425,7 @@ func expandNodePoolAutoConfig(configured interface{}) *container.NodePoolAutoCon
if v, ok := config["network_tags"]; ok && len(v.([]interface{})) > 0 {
npac.NetworkTags = expandNodePoolAutoConfigNetworkTags(v)
}

return npac
}

Expand Down Expand Up @@ -6129,7 +6131,7 @@ func flattenFleet(c *container.Fleet) []map[string]interface{} {
membership_id = match[4]
membership_location = match[3]
}

return []map[string]interface{}{
{
"project": c.Project,
Expand Down
Loading

0 comments on commit 0c4720d

Please sign in to comment.