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

Remote backend incorrectly handles remote stored variables of non-string types #23228

Closed
apparentlymart opened this issue Oct 29, 2019 · 1 comment · Fixed by #23229
Closed
Assignees
Labels
backend/remote bug v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@apparentlymart
Copy link
Contributor

Terraform Version

Terraform 0.12.12

Terraform Configuration

Any configuration using the remote backend with at least one non-string variable that is set remotely in the Terraform Cloud/Enterprise workspace settings is subject to this limitation.

terraform {
  backend "remote" {
    # (any valid remote backend configuration referring to
    # a workspace with a stored value for "example")
  }
}

variable "example" {
  type = list(string)
}

Terraform Cloud Variables configuration setting "example" to a list of strings with the "HCL" radio button checked

Expected Behavior

When running a Terraform command that operates only locally, such as terraform import, the remote backend should retrieved the stored variable value and parse it as HCL (due to the HCL checkbox being set) in order to set the value for the variable.

Actual Behavior

The remote backend always interprets all variable values as strings, causing the above to be interpreted as "[\"a\", \"b\"]" instead of as ["a", "b"]. Because there's a type constraint on that variable, the variable value fails validation with an error:

Error: Invalid value for input variable

The environment variable TF_VAR_example does not contain a valid value for
variable "example": list of string required.

It is additionally misreported as being set by environment variable because that is the source type used by the remote backend when populating these variables fetched from the remote workspace.

Steps to Reproduce

With a configuration and remote workspace configuration like the above, run a command like terraform import which attempts to construct a local context for their operation after fetching the variables from the remote workspace.

Additional Context

The relevant code that is assuming all variable values are strings is here:

return &terraform.InputValue{
Value: cty.StringVal(v.value),
SourceType: v.source,
}, tfdiags.Diagnostics{}

@ghost
Copy link

ghost commented Mar 29, 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 Mar 29, 2020
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 a pull request may close this issue.

1 participant