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

Trying to create a list variable in a workspace fails #40

Closed
sethbacon opened this issue Dec 11, 2018 · 11 comments
Closed

Trying to create a list variable in a workspace fails #40

sethbacon opened this issue Dec 11, 2018 · 11 comments

Comments

@sethbacon
Copy link

Trying to create a tfe_variable resource with a value of list gives: Error tfe_variable.availability_zones: value must be a single value, not a list

Latest .11.10

resource "tfe_variable" "availability_zones" {
hcl = true
key = "availability_zones"
value = ["us-east-1a","us-east-1b","us-east-1c"]
category = "terraform"
workspace_id = "${tfe_workspace.nc_use1_inf_dev_net.id}"
}
I've tried re-writing the value with various quote methodologies. Am I doing something wrong or is this not handled by provider?

@sethbacon
Copy link
Author

Looking at the source code, it is just passing through a string value to the terraform client, so either the backend isn't respecting the hcl flag or there is a different way to pass the list value as a string.

@svanharmelen
Copy link
Contributor

Very good question @sethbacon! The value is indeed passed through 1:1, so I will need to take a closer look to see what exactly happens here. Will try to make some time for that tomorrow.

@sethbacon
Copy link
Author

Thanks, let me know if I can provide any additional information.

@sethbacon
Copy link
Author

sethbacon commented Dec 12, 2018

Customer support offered this as a solution:
value = "[\"us-east-1a\",\"us-east-1b\", \"us-east-1c\"]"
Escaping the interior quotes and encapsulating the entire thing as a string.
This works but I would really like to see it take the regular list and map syntax if possible. Thanks!

@svanharmelen
Copy link
Contributor

That was exactly what I was also going to test just now 😉

It will not be possible to have this one value take in different types (e.g. string, list, map) at this moment. Terraform v0.12 will have some new capabilities on this front, but that will not be available to providers directly after v0.12 is released but will be enabled in a later release.

Only when that is done, we can update the schema so it can take in these different types correctly. So until that time we are limited to the solution (that thankfully works) which support suggested.

@Kimnor
Copy link

Kimnor commented Jan 3, 2019

Having a similar issue using a MAP. Difference here is that I can get the map string to work with open source terraform on Windows and it is not parsing correctly in Linux.

resource "tfe_variable" "test6" {
key = "map_tags"
value = "{version = "v1", Business_Unit = "test", Platform = "test"}"
category = "terraform"
hcl = "true"
sensitive = "false"
workspace_id = "test/test"
}

The escape character works in Windows and creates the TFE variables but errors in Linux. Have tried multiple variations of escape characters and quotes but cant get it to recognize the string as hcl.

@svanharmelen
Copy link
Contributor

@Kimnor if I use this config on my mac it seems to work as expected:

resource "tfe_variable" "test6" {
  key = "map_tags"
  value = "{version = \"v1\", Business_Unit = \"test\", Platform = \"test\"}"
  category = "terraform"
  hcl = "true"
  sensitive = "false"
  workspace_id = "test/test"
}

I don't get any errors and see this variable in TFE:

image

Can you test if this works for you as well?

@Kimnor
Copy link

Kimnor commented Jan 4, 2019

@svanharmelen Thank you. That is exactly the code I pasted into the browser. I appears to have removed my \s in the text above. when I hit the submit button.
However your comment made me look into what I was doing. I discovered that I had another .tf file in the same directory that was causing the problem. Once I removed the other .tf file in the directory the code worked just like it did in windows, with the slashes as we both had it. Thanks for the help.

@svanharmelen
Copy link
Contributor

Ah, glad to hear that it's fixed now 👍

I'll go ahead and close this issue as there isn't much we can do to improve this for the coming months. And when we are able to change the schema that will be a new topic on its own.

Feel free to reopen this issue or open a new issue if there are any follow up questions.

@MichaelAngVTS
Copy link

Donno if this will be useful for y'all. But here is a workaround using heredoc and template directive

# in .tfvars
map = {
  A = "A"
  B = "B"
  C = "C"
}

# in .tf
variable "map" {
  description = "a mapped variable"
  type        = "map"
}

resource "tfe_variable" "variable" {
  key          = "map"
  value        = <<EOT
                  {
                    %{ for key, value in var.map ~}
                    ${key} = "${value}"
                    %{ endfor ~}
                  }
                  EOT
  hcl          = true
  sensitive    = false
  category     = "terraform"
  workspace_id = "${tfe_workspace.workspace.id}"
}

@mvn-bachhuynh-dn
Copy link

Hi @MichaelAngVTS ,
You are awesome! Help me very much!
This is just workaround solution, Hope Terraform Provider will support it soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants