Skip to content
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

Default values on properties #148

Merged
merged 1 commit into from
May 16, 2018

Conversation

rambleraptor
Copy link
Contributor

Default values on properties + support for them in Ansible


[all]

Default values on properties

[terraform]

[puppet]

[puppet-dns]

[puppet-sql]

[puppet-compute]

[chef]

@rosbo
Copy link
Contributor

rosbo commented May 2, 2018

Can you put the base for this PR to #145? This way, I will only see the diff related to this change.

Let me know if you need help with that.

@rambleraptor rambleraptor force-pushed the prop-default branch 3 times, most recently from ec75e71 to f9272c3 Compare May 4, 2018 20:21
api/type.rb Outdated
@@ -22,6 +22,7 @@ class Type < Api::Object::Named
module Fields
include Api::Object::Named::Properties

attr_reader :default
Copy link
Contributor

@rosbo rosbo May 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename it to default_value to be more specific?

We have a similar concept in Terraform where the default value can be either a value defined here or at runtime by the API using another boolean field default_from_api. Once you change is in, I will update terraform to use your default_value and keep the default_from_api specific to Terraform.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be type-checked without too much difficulty, and that might be a good idea. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can steal my validation method I wrote for Terraform: https://github.com/GoogleCloudPlatform/magic-modules/blob/master/provider/terraform/property_override.rb#L74

Again, once you check-in this code, I will update the Terraform code to use the api.yaml defined default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call on the validation. All three nodes addressed.

@modular-magician
Copy link
Collaborator

modular-magician commented May 4, 2018

I am a robot that works on MagicModules PRs!

I built this PR into one or more PRs on other repositories, and when those are closed, this PR will also be merged and closed.

(terraform removed because of unrelated change)

api/type.rb Outdated
clazz = ::Symbol
else
raise "Update 'check_default_value_property' method to support " \
"default value for type #{api_property.class}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace #{api_property.class} by #{self.class}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

(I also had a Rubocop fix)

@rambleraptor rambleraptor force-pushed the prop-default branch 2 times, most recently from 9ab70c7 to 4714509 Compare May 9, 2018 21:11
class Type < Api::Object::Named
# The list of properties (attr_reader) that can be overridden in
# <provider>.yaml.
module Fields
include Api::Object::Named::Properties

attr_reader :default_value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it is common to have a unit associated with the value. like for example a timeout you could do: timeout_ms=long, or instead timeout=TimeUnit (where the type holds both the number and unit)

api/type.rb Outdated
def check_default_value_property
return if @default_value.nil?

if is_a?(Api::Type::String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use case...when...else instead

Change-Id: I480dba6f5e173b781091a5179919b8022769fb7e
@modular-magician
Copy link
Collaborator

I am a robot that works on MagicModules PRs!
I checked the downstream repositories (see README.md for which ones I can write to), and none of them seem to have any changes.

Once this PR is approved, you can feel free to merge it without taking any further steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants