From da6c57dc08493d1ef08d8c8f30dbf89cecfdc81b Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Wed, 13 Sep 2023 22:12:58 -0700 Subject: [PATCH] Handle labels field inside flatten object --- mmv1/api/resource.rb | 8 ++++---- mmv1/api/type.rb | 2 +- mmv1/products/bigquery/Job.yaml | 2 +- mmv1/provider/terraform.rb | 2 +- mmv1/templates/terraform/expand_property_method.erb | 1 + .../services/bigquery/resource_bigquery_job_test.go | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/mmv1/api/resource.rb b/mmv1/api/resource.rb index bf97e331a466..df7e6b495def 100644 --- a/mmv1/api/resource.rb +++ b/mmv1/api/resource.rb @@ -460,7 +460,7 @@ def add_labels_related_fields(props, parent) elsif p.is_a? Api::Type::KeyValueAnnotations add_annotations_fields(props, parent, p) elsif (p.is_a? Api::Type::NestedObject) && !p.all_properties.nil? - p.properties = add_labels_related_fields(p.all_properties, p.name) + p.properties = add_labels_related_fields(p.all_properties, p) end end props @@ -471,9 +471,9 @@ def add_labels_fields(props, parent, labels) labels.ignore_write = true @custom_diff ||= [] - if parent.nil? + if parent.nil? || parent.flatten_object @custom_diff.append('tpgresource.SetLabelsDiff') - elsif parent == 'metadata' + elsif parent.name == 'metadata' @custom_diff.append('tpgresource.SetMetadataLabelsDiff') end @@ -489,7 +489,7 @@ def add_annotations_fields(props, parent, annotations) @custom_diff ||= [] if parent.nil? @custom_diff.append('tpgresource.SetAnnotationsDiff') - elsif parent == 'metadata' + elsif parent.name == 'metadata' @custom_diff.append('tpgresource.SetMetadataAnnotationsDiff') end diff --git a/mmv1/api/type.rb b/mmv1/api/type.rb index 803fa476549f..0d81c8335929 100644 --- a/mmv1/api/type.rb +++ b/mmv1/api/type.rb @@ -269,7 +269,7 @@ def lineage # Prints the access path of the field in the configration eg: metadata.0.labels # The only intended purpose is to get the value of the labes field by calling d.Get(). def terraform_lineage - return name&.underscore if __parent.nil? + return name&.underscore if __parent.nil? || __parent.flatten_object "#{__parent.terraform_lineage}.0.#{name&.underscore}" end diff --git a/mmv1/products/bigquery/Job.yaml b/mmv1/products/bigquery/Job.yaml index cf12ae9fdf3d..016f76d03a72 100644 --- a/mmv1/products/bigquery/Job.yaml +++ b/mmv1/products/bigquery/Job.yaml @@ -168,7 +168,7 @@ properties: name: 'jobTimeoutMs' description: | Job timeout in milliseconds. If this time limit is exceeded, BigQuery may attempt to terminate the job. - - !ruby/object:Api::Type::KeyValuePairs + - !ruby/object:Api::Type::KeyValueLabels name: 'labels' description: | The labels associated with this job. You can use these to organize and group your jobs. diff --git a/mmv1/provider/terraform.rb b/mmv1/provider/terraform.rb index 4b89fb535374..512a26b353bf 100644 --- a/mmv1/provider/terraform.rb +++ b/mmv1/provider/terraform.rb @@ -105,7 +105,7 @@ def updatable?(resource, properties) end def force_new?(property, resource) - !property.output && + (!property.output || property.is_a?(Api::Type::KeyValueEffectiveLabels)) && (property.immutable || (resource.immutable && property.update_url.nil? && property.immutable.nil? && (property.parent.nil? || diff --git a/mmv1/templates/terraform/expand_property_method.erb b/mmv1/templates/terraform/expand_property_method.erb index 880242320bd5..d74d7bcc777c 100644 --- a/mmv1/templates/terraform/expand_property_method.erb +++ b/mmv1/templates/terraform/expand_property_method.erb @@ -75,6 +75,7 @@ func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d t func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { transformed := make(map[string]interface{}) <% property.nested_properties.each do |prop| -%> +<% next if prop.is_a?(Api::Type::KeyValuePairs) && prop.ignore_write -%> <% schemaPrefix = prop.flatten_object ? "nil" : "d.Get( \"#{prop.name.underscore}\" )" -%> transformed<%= titlelize_property(prop) -%>, err := expand<%= prefix -%><%= titlelize_property(property) -%><%= titlelize_property(prop) -%>(<%= schemaPrefix -%>, d, config) if err != nil { diff --git a/mmv1/third_party/terraform/services/bigquery/resource_bigquery_job_test.go b/mmv1/third_party/terraform/services/bigquery/resource_bigquery_job_test.go index 9de93bb6a2f7..3e8b4b832e3f 100644 --- a/mmv1/third_party/terraform/services/bigquery/resource_bigquery_job_test.go +++ b/mmv1/third_party/terraform/services/bigquery/resource_bigquery_job_test.go @@ -32,7 +32,7 @@ func TestAccBigQueryJob_withLocation(t *testing.T) { ImportStateId: importID, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"etag", "status.0.state"}, + ImportStateVerifyIgnore: []string{"etag", "status.0.state", "labels", "terraform_labels"}, }, }, })