-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Use the new default value feature in api.yaml in terraform #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ class Terraform < Provider::AbstractCore | |
| module OverrideFields | ||
| attr_reader :diff_suppress_func # Adds a DiffSuppressFunc to the schema | ||
| attr_reader :state_func # Adds a StateFunc to the schema | ||
| attr_reader :default | ||
| attr_reader :sensitive # Adds `Sensitive: true` to the schema | ||
| attr_reader :validation # Adds a ValidateFunc to the schema | ||
|
|
||
|
|
@@ -32,6 +31,11 @@ module OverrideFields | |
| # schema.HashSchema are used. | ||
| attr_reader :set_hash_func | ||
|
|
||
| # if true, then we get the default value from the Google API if no value | ||
| # is set in the terraform configuration for this field. | ||
| # It translates to setting the field to Computed & Optional in the schema. | ||
| attr_reader :default_from_api | ||
|
|
||
| # =========== | ||
| # Custom code | ||
| # =========== | ||
|
|
@@ -79,79 +83,36 @@ def validate | |
| end | ||
| end | ||
|
|
||
| # Default value for the property if any. | ||
| class Default < Api::Object | ||
| # the attributes below are mutually exclusive. | ||
|
|
||
| # if specified, then this will be set as the default value in the schema | ||
| attr_reader :value | ||
| # if true, then we get the default value from the Google API if no value | ||
| # is set in the terraform configuration for this field. | ||
| # It translates to setting the field to Computed & Optional in the schema. | ||
| attr_reader :from_api | ||
|
|
||
| def validate | ||
| super | ||
|
|
||
| # Ensure boolean values are set to false if nil | ||
| @from_api ||= false | ||
|
|
||
| check_property :from_api, :boolean | ||
|
|
||
| raise "'value' and 'from_api' cannot be both set for 'default'" \ | ||
| if from_api && !value.nil? | ||
|
|
||
| check_optional_property :update_statement, String | ||
| check_optional_property :custom_flatten, String | ||
| check_optional_property :custom_expand, String | ||
| end | ||
|
|
||
| def apply(api_property) | ||
| # This can't be done in validate because we don't have access to the | ||
| # api.yaml property yet. | ||
| check_default_value_property api_property | ||
| end | ||
|
|
||
| def check_default_value_property(api_property) | ||
| return if @default_value.nil? | ||
|
|
||
| if api_property.is_a?(Api::Type::String) | ||
| clazz = String | ||
| elsif api_property.is_a?(Api::Type::Integer) | ||
| clazz = Integer | ||
| elsif api_property.is_a?(Api::Type::Enum) | ||
| clazz = Symbol | ||
| else | ||
| raise "Update 'check_default_value_property' method to support " \ | ||
| "default value for type #{api_property.class}" | ||
| end | ||
|
|
||
| check_optional_property :value, clazz | ||
| end | ||
| end | ||
|
|
||
| # Terraform-specific overrides to api.yaml. | ||
| class PropertyOverride < Provider::PropertyOverride | ||
| include OverrideFields | ||
|
|
||
| # rubocop:disable Metrics/MethodLength | ||
| def validate | ||
| super | ||
|
|
||
| # Ensures boolean values are set to false if nil | ||
| @sensitive ||= false | ||
| @is_set ||= false | ||
|
|
||
| @default ||= Provider::Terraform::Default.new | ||
| @default_from_api ||= false | ||
|
|
||
| check_property :sensitive, :boolean | ||
| check_property :is_set, :boolean | ||
| check_property :default, Provider::Terraform::Default | ||
| check_property :default_from_api, :boolean | ||
|
|
||
| check_optional_property :diff_suppress_func, String | ||
| check_optional_property :state_func, String | ||
| check_optional_property :validation, Provider::Terraform::Validation | ||
| check_optional_property :set_hash_func, String | ||
|
|
||
| check_optional_property :update_statement, String | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also fixed a bug where these lines where in the wrong validate method |
||
| check_optional_property :custom_flatten, String | ||
| check_optional_property :custom_expand, String | ||
|
|
||
| raise "'default_value' and 'default_from_api' cannot be both set" \ | ||
| if default_from_api && !default_value.nil? | ||
| end | ||
| # rubocop:enable Metrics/MethodLength | ||
|
|
||
| def apply(api_property) | ||
| unless description.nil? | ||
|
|
@@ -167,8 +128,6 @@ def apply(api_property) | |
| end | ||
| end | ||
|
|
||
| @default.apply(api_property) | ||
|
|
||
| super | ||
| end | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also set in api.yaml. Any idea whether that was intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you put that stuff in the PR description, cool. We'll talk about it another time :)