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

terraform: Relax provider config ref constraints #25420

Merged
merged 1 commit into from
Jun 29, 2020

Conversation

alisdair
Copy link
Contributor

@alisdair alisdair commented Jun 26, 2020

When configuring providers, it is normally valid to refer to any value which is known at apply time. This can include resource instance attributes, variables, locals, and so on.

The import command has a simpler graph evaluation, which means that many of these values are unknown. We previously prevented this from happening by restricting provider configuration references to input variables (#22862), but this was more restrictive than is necessary.

This commit changes how we verify provider configuration for import. We no longer inspect the configuration references during graph building, because this is too early to determine if these values will become known
or not.

Instead, when the provider is configured during evaluation, we check if the configuration value is wholly known. If not, we fail with a diagnostic error.

Includes a test case which verifies that providers can now be configured using locals as well as vars, and an updated test case which verifies that providers cannot be configured with references to resources.

Fixes #25407

Copy link
Contributor Author

@alisdair alisdair left a comment

Choose a reason for hiding this comment

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

📝

},
},
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this step was redundant with the "everything except validate" one a few lines below.

@@ -48,7 +35,6 @@ func ProviderEvalTree(n *NodeApplyableProvider, config *configs.Provider) EvalNo
},
})

// Apply stuff
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment (and the one above) did not seem to mean anything. I'd happily add more comments here if I knew what to write…

@codecov
Copy link

codecov bot commented Jun 26, 2020

Codecov Report

Merging #25420 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
terraform/graph_builder_import.go 93.75% <ø> (-0.19%) ⬇️
terraform/eval_provider.go 87.50% <100.00%> (+1.78%) ⬆️
terraform/evaltree_provider.go 100.00% <100.00%> (ø)
terraform/context_import.go 88.88% <0.00%> (-11.12%) ⬇️
dag/marshal.go 53.33% <0.00%> (-1.12%) ⬇️
backend/remote/backend_common.go 54.57% <0.00%> (-0.68%) ⬇️
terraform/node_resource_plan.go 93.44% <0.00%> (+1.63%) ⬆️

@alisdair alisdair force-pushed the alisdair/fix-import-provider-config-references branch from 62bfcc0 to c9bf9f3 Compare June 29, 2020 13:07
When configuring providers, it is normally valid to refer to any value
which is known at apply time. This can include resource instance
attributes, variables, locals, and so on.

The import command has a simpler graph evaluation, which means that
many of these values are unknown. We previously prevented this from
happening by restricting provider configuration references to input
variables (#22862), but this was more restrictive than is necessary.

This commit changes how we verify provider configuration for import.
We no longer inspect the configuration references during graph building,
because this is too early to determine if these values will become known
or not.

Instead, when the provider is configured during evaluation, we
check if the configuration value is wholly known. If not, we fail with a
diagnostic error.

Includes a test case which verifies that providers can now be configured
using locals as well as vars, and an updated test case which verifies
that providers cannot be configured with references to resources.
@alisdair alisdair force-pushed the alisdair/fix-import-provider-config-references branch from c9bf9f3 to ac99a3b Compare June 29, 2020 15:00
@alisdair alisdair marked this pull request as ready for review June 29, 2020 15:07
@alisdair alisdair requested a review from a team June 29, 2020 15:07
Copy link
Member

@jbardin jbardin left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of the dead code too!

@alisdair alisdair merged commit df82796 into master Jun 29, 2020
@alisdair alisdair deleted the alisdair/fix-import-provider-config-references branch June 29, 2020 19:28
@ghost
Copy link

ghost commented Jul 30, 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 Jul 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when using local.variables in Provider block.
2 participants