diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index bed28d1ab815..e7655a39ce31 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -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}`, diff --git a/provider/property_override.rb b/provider/property_override.rb index 6b222d750b4f..53559ac3429d 100644 --- a/provider/property_override.rb +++ b/provider/property_override.rb @@ -20,6 +20,16 @@ module Provider class PropertyOverride < Api::Object attr_reader :new_type + # Ordering of imports can be important so this property can make 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: + # 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. diff --git a/provider/resource_overrides.rb b/provider/resource_overrides.rb index c020de23d09b..a15b405a8ef1 100644 --- a/provider/resource_overrides.rb +++ b/provider/resource_overrides.rb @@ -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