-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Fix chef provisioner validateFn #17147
Fix chef provisioner validateFn #17147
Conversation
Thanks for your PR @jeremiahsnapp! I see what you are trying to do, but I wonder if this isn't actually a bug in Terraform core instead. @apparentlymart the schema clearly specifies the |
Thanks for looking at this @svanharmelen and @apparentlymart. I'm new to the terraform code so I'm not certain if their is a bug in the core code. I will say that the Booleans docs gives me the impression that using string values for a boolean variable is preferred and that TF should automatically convert the value internally to a boolean as needed. The chef provisioner's validateFn function is being passed a Contrast this with how the chef provisioner's decodeConfig function is passed a So while the Thanks! |
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.
Your absolutely right! I didn't look good enough and responded to quickly I guess. So your fix does indeed seem to be needed 👍
I do have a suggestion for your switch
statement. Most important changes are adding a default
case and return when getting an error.
To me it feels a bit wierd/wrong to check config fields that are dependent on a field we already know isn't used correctly.
Let me know your thoughts! And thanks again for your elaborate update and the PR!
} | ||
case bool: | ||
usePolicyFile = usePolicyFileRaw | ||
} |
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.
May I suggest a small rewrite of your switch
statement to make it just a bit more idiomatic Go?
switch usePolicyFileRaw := usePolicyFileRaw.(type) {
case bool:
usePolicyFile = usePolicyFileRaw
case string:
usePolicyFileBool, err := strconv.ParseBool(usePolicyFileRaw)
if err != nil {
return append(es, errors.New("\"use_policyfile\" must be a boolean"))
}
usePolicyFile = usePolicyFileBool
default:
return append(es, errors.New("\"use_policyfile\" must be a boolean"))
}
Correctly validate Chef provisioner's `use_policyfile` field even if its value is a string type. Signed-off-by: Jeremiah Snapp <jeremiah@chef.io>
b363193
to
7595e27
Compare
Thanks a lot for the idiomatic Go advice @svanharmelen. I like it a lot. I only made a minor change to your return statements so they return the correct number of arguments. Thanks! |
Again thanks for the PR and your inputs! LGTM! 🎉 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Correctly validate Chef provisioner's
use_policyfile
field even if its value is a string type.This fixes #16655