Terraform12 upgrade does not update local variable names and mix variables

I am using terraform 0.12upgrade command to update tf files from from terraform v0.11.14
I noticed that it is not changing variable names defined as local
For example "${local.service_name}-test"
In above example command should change it to "local.service_name-test"

Also it did not change variables used with string…
For example service_name = "app-test-${var.env_name}"
In above example command should change to "app-test-var.env_name"

Is this expected or bug?

Hi @neeleshg,

Changing "${local.service_name}-test" to "local.service_name-test" would break your configuration because it’d be replacing an interpolation with a literal string, causing the result to literally be local.service_name-test, not including the value of local.service_name. The ${ ... } syntax is what Terraform uses to determine that you want to substitute the value of a variable into the resulting string.

1 Like

Thanks @apparentlymart

In Terraform 12 I noticed that ${..} is removed from variables as well as aws resources for eg. var.service_name and aws_instance.example.id

So had this question.

IIRC, only the free-standing variables are now first-class and can be called directly, like var.my_foo or local.my_foo but the moment you have the string bar attached to it, you have to use the interpolation, like "${var.my_foo}-bar". Even if you concatenate two free-sanding variables, you still have to go the "${}" way, like: "${var.my_foo}${local.my_bar}" It’s not true that v0.12 removes all of the "${...}" regardlessly.

1 Like

Thanks @dsantanu and @apparentlymart