If you want to add interpolation into your syntax with terraform 0.12 you still need to use the ${} interpolation syntax to append a variable output to a string.
Consider the following example. Notice that the local base can uses simple assignment of a string. However; when I want to include the output of a variable in a string I need to use the ${} syntax around my variable to tell Terraform to return the output not the string literal. This way I can just embed variables inside strings. Concatenation like your example “global/s3/“var.instancename”/terraform.tfstate” is not supported.
variable "instance" {
default = "something"
}
locals {
base = "global/s3/instance/terraform.tfstate"
interpolated = "global/s3/${var.instance}/terraform.tfstate"
}
output "local_base" {
value = local.base
}
output "local_interpolated" {
value = local.interpolated
}
unfortunately the terraform backend { does not allow variables
Error: Variables not allowed
on instance.tf line 14, in terraform:
14: key = local.interpolated
code below:
locals {
base = “global/s3/instance/terraform.tfstate”
interpolated = “global/s3/${var.instancename}/terraform.tfstate”
}
terraform {
backend “s3” {
# Replace this with your bucket name!
# need to strip white spaces
bucket = “xxxx”
key = local.interpolated
region = “eu-west-2”
}
}