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

backend/remote: Report invalid variables only remotely #23122

Merged
merged 2 commits into from
Oct 18, 2019

Conversation

apparentlymart
Copy link
Contributor

The remote backend uses backend.ParseVariableValues locally only to decide if the user seems to be trying to use -var or -var-file options locally, since those are not supported for the remote backend.

Other than detecting those, we don't actually have any need to use the results of backend.ParseVariableValues locally, and so it's better for us to ignore any errors it produces itself and prefer to just send a potentially-invalid request to the remote system and let the remote system
be responsible for validating it.

This then avoids issues caused by the fact that when remote operations are in use the local system does not have all of the required context: it can't see which environment variables will be set in the remote execution context nor which variables the remote system will set using its own generated -var-file based on the workspace stored variables. This fixes #23115.

This does have a minor drawback in that it won't produce the error about variables not being supported if the only -var argument provided by the user produces a parse error, because we can't currently distinguish that particular error type from other error types. We may wish to revisit this in a later release to improve the precision of this hint, but for the moment the priority is to avoid the incorrect validation messages.

The remote backend uses backend.ParseVariableValues locally only to decide
if the user seems to be trying to use -var or -var-file options locally,
since those are not supported for the remote backend.

Other than detecting those, we don't actually have any need to use the
results of backend.ParseVariableValues, and so it's better for us to
ignore any errors it produces itself and prefer to just send a
potentially-invalid request to the remote system and let the remote system
be responsible for validating it.

This then avoids issues caused by the fact that when remote operations are
in use the local system does not have all of the required context: it
can't see which environment variables will be set in the remote execution
context nor which variables the remote system will set using its own
generated -var-file based on the workspace stored variables.
@apparentlymart apparentlymart added bug backend/remote v0.12 Issues (primarily bugs) reported against v0.12 releases labels Oct 18, 2019
@apparentlymart apparentlymart self-assigned this Oct 18, 2019
Some commands don't use variables at all or use them in a way that doesn't
require them to all be fully valid and consistent. For those, we don't
want to fetch variable values from the remote system and try to validate
them because that's wasteful and likely to cause unnecessary error
messages.

Furthermore, the variables endpoint in Terraform Cloud and Enterprise only
works for personal access tokens, so it's important that we don't assume
we can _always_ use it. If we do, then we'll see problems when commands
are run inside Terraform Cloud and Enterprise remote execution contexts,
where the variables map always comes back as empty.
@apparentlymart
Copy link
Contributor Author

I have tested this manually since we don't seem to have unit test coverage for these particular codepaths. I intend to follow up with some additional test coverage in a subsequent commit, but hope to move forward with this manually-tested change for the moment in the interests of expediting a fixed release.

@apparentlymart apparentlymart marked this pull request as ready for review October 18, 2019 18:17
@apparentlymart apparentlymart requested a review from a team October 18, 2019 18:17
@apparentlymart apparentlymart merged commit b10f058 into master Oct 18, 2019
@apparentlymart apparentlymart deleted the b-cmd-show-variables branch October 18, 2019 18:33
beekus added a commit to beekus/terraform that referenced this pull request Nov 13, 2019
Following up on hashicorp#23122, the remote system (Terraform Cloud or
Enterprise) serves environment and Terraform variables using a single
type of object. We only should load Terraform variables into the
Terraform context.

Fixes hashicorp#23283.
pselle pushed a commit that referenced this pull request Nov 13, 2019
…3358)

* backend/remote: Filter environment variables when loading context

Following up on #23122, the remote system (Terraform Cloud or
Enterprise) serves environment and Terraform variables using a single
type of object. We only should load Terraform variables into the
Terraform context.

Fixes #23283.
@ghost
Copy link

ghost commented Nov 18, 2019

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 Nov 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backend/remote bug v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remote terraforom plan reports missing input vars
2 participants