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

Variables with type = any are not encoded properly for Terraform 0.12 #1211

Open
antonbabenko opened this issue Jun 5, 2020 · 5 comments
Open
Labels
bug Something isn't working needs design We need to flesh out the design before we can resolve the issue

Comments

@antonbabenko
Copy link
Contributor

# terragrunt.hcl
terraform {
  source = "..."
}

inputs = {
  name ="something"                 # <-- this does not work
  # name = jsonencode("something")  # <-- this works
}
# module/main.tf
variable "name" {
  type    = any      # Works as expected when type is not `any`
  default = null
}

The error message:

Error: Invalid expression

  on <value for var.name> line 1:
  (source code not available)

Expected the start of an expression, but found an invalid expression token.

It looks like terragrunt should do JSON encode for all variables, but I am not sure if it is a BC break, or not.

Using terragrunt version v0.23.23 and Terraform 0.12.26.

The workaround, for now, is to know which variables have "type = any" and wrap value with jsonencode().

@yorinasub17 yorinasub17 added bug Something isn't working needs investigation and removed needs investigation labels Jun 8, 2020
@yorinasub17
Copy link
Contributor

Investigating into this, it looks like terraform does not like the string value being passed in without quotes when type=any. However, this is problematic because we can't pass in with quotes when type=string, as the quotes make it to the final input value (we deliberately do not do a json encoding for strings for this reason).

I'm not sure there is anything we can do here other than to parse the terraform source for variables and dynamically adjust the conversion logic based on the type, but I am not sure we want to go that far. I am inclined to close this as something we won't address in terragrunt, and unfortunately have to rely on the jsonencode workaround.

Could use a second opinion though: @brikis98 what do you think?

@brikis98
Copy link
Member

@yorinasub17 Agreed. Should we also open a bug in the Terraform repo? The fact that you wrap strings with quotes sometimes in Terraform seems like an issue that would be best fixed on their end.

@Xtigyro
Copy link
Contributor

Xtigyro commented Oct 1, 2021

What's the status on this, guys?

@infraredgirl infraredgirl added needs design We need to flesh out the design before we can resolve the issue and removed needs-design labels Oct 20, 2021
@basarsoker
Copy link

Cost me 2 days. 😔 thanks a lot for the workaround.

@dserodio
Copy link

Thanks for the workaround and sorry for this "useless" comment, but since GitHub allows searching for commented issues but not subscribed issues I have to comment to easily find this issue later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs design We need to flesh out the design before we can resolve the issue
Projects
None yet
Development

No branches or pull requests

7 participants