Skip to content

Commit

Permalink
Moving Ansible fingerprint to match TF (#2787)
Browse files Browse the repository at this point in the history
Merged PR #2787.
  • Loading branch information
rambleraptor authored and modular-magician committed Dec 6, 2019
1 parent 5d5f51e commit 91fbba4
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build/ansible
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
2 changes: 1 addition & 1 deletion build/terraform-mapper
3 changes: 0 additions & 3 deletions products/compute/ansible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion provider/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
16 changes: 15 additions & 1 deletion templates/ansible/resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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? -%>
Expand Down
8 changes: 7 additions & 1 deletion templates/terraform/extra_schema_entry/subnetwork.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
"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.",
},

0 comments on commit 91fbba4

Please sign in to comment.