-
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
Use helpers.shema.Provisoner
in Chef provisioner V2
#14681
Conversation
1. Migrate `chef` provisioner to `schema.Provisioner`: * `chef.Provisioner` structure was renamed to `ProvisionerS`and now it's decoded from `schema.ResourceData` instead of `terraform.ResourceConfig` using simple copy-paste-based solution; * Added simple schema without any validation yet. 2. Support `ValidateFunc` validate function : implemented in `file` and `chef` provisioners.
The tests did pass, but that was because they only tested part of the changes. By using the `schema.TestResourceDataRaw` function the schema and config are better tested and so they pointed out a problem with the schema of the Chef provisioner. The `Elem` fields did not have a `*schema.Schema` but a `schema.Schema` and in an `Elem` schema only the `Type` field may (and must) be set. Any other fields like `Optional` are not allowed here. Next to fixing that problem I also did a little refactoring and cleaning up. Mainly making the `ProvisionerS` private (`provisioner`) and removing the deprecated fields.
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.
LGTM, may warrant another look-over from @mitchellh though.
Thx, @grubernaut! @mitchellh I guess @grubernaut is referring to you for the change made in I found it a very helpful addition that we should/could maybe also add to the The rest of the changes are mainly updates and some refactoring of existing stuff, so I don't think there's anything exciting in the other parts... Thx! |
@grubernaut @mitchellh @stack72 can we move this one forward? Even though this PR isn't open for that long, the PR that is included in this PR was open since February. So it would be nice to get this one merged before the next release... Thx! |
This actually broken file provisioning, since release 0.9.7 till 0.9.8 (up until now): |
if _, ok := d.GetOk("source"); ok == true { | ||
numSrc++ | ||
} | ||
if _, ok := d.GetOk("content"); ok == true { |
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.
it seems GetOk fail to return ok
in the following part:
https://github.com/hashicorp/terraform/blob/master/helper/schema/resource_data.go#L91
The struct is:
r: {${data.template_file.config.rendered} <nil> true true 0xc4203c12c0}
Which means r.Exists
and r.Computed
but expecting r.Exists && !r.Computed
I was able to make a workaround with following code:
func validateFn(d *schema.ResourceData) (ws []string, es []error) {
numSrc := 0
content := d.Get("content").(string)
source := d.Get("source").(string)
if content != "" {
numSrc++
}
if source != "" {
numSrc++
}
if numSrc != 1 {
es = append(es, fmt.Errorf("Must provide one of 'content' or 'source'"))
}
log.Printf("Numsrc is: %v", numSrc)
return
}
@onorua Sorry for causing the issue, seems functions not working the way I expected. And seems tests are not coveting such scenario. It would be nice if you could also add test case in your pull request which fixes problem. |
@VladRassokhin yeah, I was amused with behavior of |
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. |
Done by @VladRassokhin:
chef
provisioner toschema.Provisioner
:chef.Provisioner
structure was renamed toProvisionerS
and now it's decoded fromschema.ResourceData
instead ofterraform.ResourceConfig
using simple copy-paste-based solution;ValidateFunc
validate function : implemented infile
andchef
provisioners.Done by @svanharmelen:
The tests did pass, but that was because they only tested part of the changes. By using the
schema.TestResourceDataRaw
function the schema and config are better tested and so they pointed out a problem with the schema of the Chef provisioner.So fixed the
Elem
fields that did not have a*schema.Schema
but aschema.Schema
and in anElem
schema only theType
field may (and must) be set. Any other fields likeOptional
are not allowed here.Next to fixing that problem I also did a little refactoring and cleaning up. Mainly making the
ProvisionerS
private (provisioner
) and removing the deprecated fields.