Skip to content

Commit

Permalink
Specify the orverride import order (#559)
Browse files Browse the repository at this point in the history
Merged PR #559.
  • Loading branch information
chrisst authored and modular-magician committed Oct 15, 2018
1 parent ba49edc commit ec787c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ overrides: !ruby/object:Provider::ResourceOverrides
default_from_api: true
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
sourceImage: !ruby/object:Provider::Terraform::PropertyOverride
# sourceImage must be overridden first because it creates the 'image' property
override_order: -1
name: image
diff_suppress_func: 'diskImageDiffSuppress'
image: !ruby/object:Provider::Terraform::PropertyOverride
override_order: 5
description: |
The image from which to initialize this disk. This can be
one of: the image's `self_link`, `projects/{project}/global/images/{image}`,
Expand Down
10 changes: 10 additions & 0 deletions provider/property_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ module Provider
class PropertyOverride < Api::Object
attr_reader :new_type

# Ordering of overrides can be important so this property makes the
# ordering more deterministic. It supports positive or negative numbers
# with the lowest number getting imported first.
# The default is equal to the negative depth of the metric. This makes
# sure that more deeply nested fields happen first.
# eg, for the compute.disk resource
# sourceSnapshotEncryptionKey.rawKey has an order of -2
# sourceSnapshotEncryptionKey has an order of -1
attr_reader :override_order

include Api::Type::Fields
# To allow overrides for type-specific fields, include those type's
# fields with an 'include' directive here.
Expand Down
2 changes: 1 addition & 1 deletion provider/resource_overrides.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def override_properties(api_object, override)
# before we have applied the overrides to its child properties (and
# therefore can no longer find the child property, since the
# parent name has changed)
sorted_props = override.properties.sort_by { |path, _| -path.count('.') }
sorted_props = override.properties.sort_by { |path, p| p.override_order || -path.count('.') }
sorted_props.each do |property_path, property_override|
check_property_value "properties['#{property_path}']",
property_override, Provider::PropertyOverride
Expand Down

0 comments on commit ec787c0

Please sign in to comment.