Error in using string list variable in Terraform Cloud

I have a simple project that creates DigitalOcean droplets. As part of the droplet creation, I need to inject a list of SSH key fingerprints to the authorized keys list.
When I add these as Terraform Variables in the UI

The resulting run fails with the following error.

Terraform v0.12.23
Configuring remote state backend...
Initializing Terraform configuration...
2020/03/09 15:09:44 [DEBUG] Using modified User-Agent: Terraform/0.12.23 TFC/896fd11ba6

Error: Invalid value for input variable

  on /terraform/terraform/terraform.tfvars line 4:
   4: ssh_fingerprints = "[\"fingerprint_1\", \"fingerprint_2\"]"

The given value is not valid for variable "ssh_fingerprints": list of string

But, if I change the variable definition to be parsed as HCL, then it works.

Why would using ["fingerprint_1", "fingerprint_2"] as is not work?

Hi @HanSooloo,

When the “HCL” checkbox is not checked, Terraform Cloud interprets the contents of the “Value” box as a static string value, not as an HCL expression. We can see in the error message there that indeed Terraform cloud has wrapped the exact string you entered in quotes and escaped the quotes inside, causing Terraform Core to interpret it as a string that happens to contain brackets and quote marks.

Marking it as HCL causes Terraform Cloud to pass the value to Terraform Core as a general expression, which means you can then produce values of types other than string.

1 Like