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

provisioner/file: refactor the provisioner validation function #15273

Merged
merged 1 commit into from
Jun 15, 2017
Merged

provisioner/file: refactor the provisioner validation function #15273

merged 1 commit into from
Jun 15, 2017

Conversation

svanharmelen
Copy link
Contributor

@svanharmelen svanharmelen commented Jun 13, 2017

It turns out that d.GetOk also returns false when the user did actually supply a value for it in the config, but the value itself needs to be evaluated before it can be used.

So instead of passing a ResourceData we now pass a ResourceConfig
which makes much more sense for doing the validation anyway.

numSrc := 0
if _, ok := d.GetOk("source"); ok == true {
numSrc++
if d.Get("source").(string) == "" && d.Get("content").(string) == "" {
Copy link

Choose a reason for hiding this comment

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

this will not catch the situation when you have both source and content defined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is not needed, as that will be catched by the ConflictsWith configs defined in the schema.

Copy link

Choose a reason for hiding this comment

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

What about tests? This functionality was broken for 2 releases since 0.9.6, and this is core functionality. Would be nice to catch this, so far I can see current tests are not catching the problem described in #15177

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just added a test to the latest revision of this fix...

@svanharmelen
Copy link
Contributor Author

Working on an improved version of this fix... Will update later this evening.

@svanharmelen
Copy link
Contributor Author

@apparentlymart could you have a look at this one? I refactored it after the chat we had yesterday and I think the current solution is a very clean one that circumvents all the issues we talked about...

Copy link
Contributor

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

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

Using ResourceConfig instead of ResourceData here seems reasonable, since we know we're only looking at config and so no strong reason to force us through all the compromises the ResourceData API makes.

It'd be good to have some tests for this, to make sure that the right result comes out the other side after going through the various layers here.

@svanharmelen
Copy link
Contributor Author

Of course... Now were happy with the solution, I'll add some tests tomorrow before merging the PR. Thx!

@svanharmelen
Copy link
Contributor Author

@apparentlymart added a test that fails with the reported error when not using this patch... Guess that wraps up this PR right?

Copy link
Contributor

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

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

Aside from a minor nit inline, this looks good to me. Thanks!

@@ -48,6 +48,21 @@ func TestResourceProvider_Validate_good_content(t *testing.T) {
}
}

func TestResourceProvider_Validate_good_unknown_variable_value(t *testing.T) {
c := testConfig(t, map[string]interface{}{
"content": "74D93920-ED26-11E3-AC10-0800200C9A66",
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is the "unknown variable value". If possible, it'd be preferable to use one of the global variables that contain this, so that in future when this stops being a magic string we'll be able to track down uses of it to update them.

It's available in a few places, though off the top of my head I'm not sure what's the most convenient to access from here. It's a global variable called UnknownValue or UnknownVariableValue in a few different packages.

It turns out that `d.GetOk` also returns `false` when the user _did_ actually supply a value for it in the config, but the value itself needs to be evaluated before it can be used.

So instead of passing a `ResourceData` we now pass a `ResourceConfig`
which makes much more sense for doing the validation anyway.
@svanharmelen
Copy link
Contributor Author

@apparentlymart that's actually a very good point... Thx! Updated the test so it uses the constant config.UnknownVariableValue instead 👍

@svanharmelen svanharmelen merged commit 7e180ae into hashicorp:master Jun 15, 2017
@svanharmelen svanharmelen deleted the b-file-provisioner branch June 15, 2017 17:57
@svanharmelen svanharmelen changed the title provisioner/file: don’t use d.GetOk in validation functions provisioner/file: refactor the provisioner validation function Jun 15, 2017
catsby pushed a commit that referenced this pull request Jun 23, 2017
It turns out that `d.GetOk` also returns `false` when the user _did_ actually supply a value for it in the config, but the value itself needs to be evaluated before it can be used.

So instead of passing a `ResourceData` we now pass a `ResourceConfig`
which makes much more sense for doing the validation anyway.
apparentlymart pushed a commit that referenced this pull request Jun 26, 2017
It turns out that `d.GetOk` also returns `false` when the user _did_ actually supply a value for it in the config, but the value itself needs to be evaluated before it can be used.

So instead of passing a `ResourceData` we now pass a `ResourceConfig`
which makes much more sense for doing the validation anyway.
@shantanugadgil
Copy link

Hi,
I was wondering if this fixes #15186 ?
I can't get to my test setup for a while, so thought would ask!

Regards,
Shantanu

@svanharmelen
Copy link
Contributor Author

Yes, indeed. Thanks for the pointer, updated and closed the other issue as well.

@ghost
Copy link

ghost commented Apr 8, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants