From 91fbba4d1b2d45f993734d0e76b68ffd60b333ea Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Fri, 6 Dec 2019 15:41:39 -0800 Subject: [PATCH] Moving Ansible fingerprint to match TF (#2787) Merged PR #2787. --- build/ansible | 2 +- build/inspec | 2 +- build/terraform | 2 +- build/terraform-beta | 2 +- build/terraform-mapper | 2 +- products/compute/ansible.yaml | 3 --- products/compute/api.yaml | 6 ------ products/compute/terraform.yaml | 2 -- provider/core.rb | 2 +- templates/ansible/resource.erb | 16 +++++++++++++++- .../terraform/extra_schema_entry/subnetwork.erb | 8 +++++++- 11 files changed, 28 insertions(+), 19 deletions(-) diff --git a/build/ansible b/build/ansible index e3afbd58f321..561dddd734b7 160000 --- a/build/ansible +++ b/build/ansible @@ -1 +1 @@ -Subproject commit e3afbd58f3211743fbfa0ee1e7d205505114847f +Subproject commit 561dddd734b758a02b6d018c1e4a42150d7f04c5 diff --git a/build/inspec b/build/inspec index 8e8b7c0231b4..afd143c24ebc 160000 --- a/build/inspec +++ b/build/inspec @@ -1 +1 @@ -Subproject commit 8e8b7c0231b4dcc737825afe8e0e5d5e47b10dec +Subproject commit afd143c24ebc714729a9ede884cdf0ae8e2be45e diff --git a/build/terraform b/build/terraform index 789f50dea63f..a660276d910f 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 789f50dea63f395ee4f1161f7c16fb08cf159c56 +Subproject commit a660276d910fa152238abb3557ad816e708bbef6 diff --git a/build/terraform-beta b/build/terraform-beta index 72bdd64371dc..b7a96bf4d051 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 72bdd64371dc4dd623377e0f2a2205819c15d04a +Subproject commit b7a96bf4d051672a38eaaceea086f01f0f37bd76 diff --git a/build/terraform-mapper b/build/terraform-mapper index d3b0dd6f4daa..daa9a44fb16f 160000 --- a/build/terraform-mapper +++ b/build/terraform-mapper @@ -1 +1 @@ -Subproject commit d3b0dd6f4daa141b2365fdf5ba815e9290e8bde3 +Subproject commit daa9a44fb16f74f116d633a57e92f24cce7c37a5 diff --git a/products/compute/ansible.yaml b/products/compute/ansible.yaml index 5669f9081db1..f55daacef737 100644 --- a/products/compute/ansible.yaml +++ b/products/compute/ansible.yaml @@ -286,9 +286,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides * global/gateways/default-internet-gateway Subnetwork: !ruby/object:Overrides::Ansible::ResourceOverride properties: - fingerprint: !ruby/object:Overrides::Ansible::PropertyOverride - update_verb: :PATCH - update_url: projects/{{project}}/regions/{{region}}/subnetworks/{{name}} logConfig: !ruby/object:Overrides::Ansible::PropertyOverride exclude: true TargetPool: !ruby/object:Overrides::Ansible::ResourceOverride diff --git a/products/compute/api.yaml b/products/compute/api.yaml index a0f1243ccb26..0884d2c2976e 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -10316,12 +10316,6 @@ objects: Only networks that are in the distributed mode can have subnetworks. input: true required: true - # TODO(rileykarson): Work with rambleraptor to remove this field from downstreams. - - !ruby/object:Api::Type::Fingerprint - name: 'fingerprint' - description: | - Fingerprint of this resource. This field is used internally during - updates of this resource. - !ruby/object:Api::Type::Enum name: 'purpose' min_version: beta diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index 2775cb2c663e..ee51b4a48a23 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -1726,8 +1726,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides secondaryIpRanges.ipCidrRange: !ruby/object:Overrides::Terraform::PropertyOverride validation: !ruby/object:Provider::Terraform::Validation function: 'validateIpCidrRange' - fingerprint: !ruby/object:Overrides::Terraform::PropertyOverride - exclude: false logConfig: !ruby/object:Overrides::Terraform::PropertyOverride send_empty_value: true custom_expand: 'templates/terraform/custom_expand/subnetwork_log_config.go.erb' diff --git a/provider/core.rb b/provider/core.rb index 8cf273f19ebf..26ce08ee92cf 100644 --- a/provider/core.rb +++ b/provider/core.rb @@ -290,7 +290,7 @@ def properties_by_custom_update(properties, behavior = :new) # TODO(rambleraptor): Add support to Ansible for one-at-a-time updates. if behavior == :old update_props.group_by do |p| - { update_url: p.update_url, update_verb: p.update_verb } + { update_url: p.update_url, update_verb: p.update_verb, fingerprint: p.fingerprint_name } end else update_props.group_by do |p| diff --git a/templates/ansible/resource.erb b/templates/ansible/resource.erb index ec4e12aafb53..51ecd909b5e4 100644 --- a/templates/ansible/resource.erb +++ b/templates/ansible/resource.erb @@ -269,12 +269,26 @@ def update_fields(module, request, response): <% unless object.hidden.include?(func_name) -%> def <%= func_name -%>(module, request, response): auth = GcpSession(module, <%= quote_string(prod_name) -%>) +<% if key[:fingerprint_name] -%> + new_resource = <%= method_call('fetch_resource', ['module', 'self_link(module)', + ('kind' if object.kind?), + ]) + %> + fingerprint = new_resource[:<%= key[:fingerprint_name] -%>] +<% end -%> +<% + request_props = if key[:fingerprint_name] + request_properties(props).merge({fingerprint_name => Google::PythonUtils::PythonCode.new("new_resource[:#{key[:fingerprint_name]}]")}) + else + request_properties(props) + end +-%> auth.<%= key[:update_verb].downcase -%>( ''.join([ "<%= object.__product.base_url -%>", "<%= key[:update_url].gsub('{{', '{').gsub('}}', '}') -%>" ]).format(**module.params), -<%= lines(python_literal(request_properties(props), use_hash_brackets: true)) -%> +<%= lines(python_literal(request_props, use_hash_brackets: true)) -%> ) <% end # unless object.hidden.include? -%> diff --git a/templates/terraform/extra_schema_entry/subnetwork.erb b/templates/terraform/extra_schema_entry/subnetwork.erb index 87ad70ed4de9..f9a451f81aba 100644 --- a/templates/terraform/extra_schema_entry/subnetwork.erb +++ b/templates/terraform/extra_schema_entry/subnetwork.erb @@ -17,4 +17,10 @@ Computed: true, Optional: true, Removed: "This field is being removed in favor of log_config. If log_config is present, flow logs are enabled. Please remove this field", -}, \ No newline at end of file +}, +"fingerprint": { + Type: schema.TypeString, + Computed: true, + Description: "Fingerprint of this resource. This field is used internally during updates of this resource.", + Deprecated: "This field is not useful for users, and has been removed as an output.", +},