Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix "Interpolation-only expressions are deprecated" warning in Terraform

Tags:

terraform

I upgraded to Terraform v0.12.16 and now I am getting a lot of messages that look like this:

Warning: Interpolation-only expressions are deprecated    on ../modules/test-notifier/test_notifier.tf line 27, in resource "aws_sns_topic_policy" "default":   27:   arn    = "${aws_sns_topic.default.arn}"  Terraform 0.11 and earlier required all non-constant expressions to be provided via interpolation syntax, but this pattern is now deprecated. To silence this warning, remove the "${ sequence from the start and the }" sequence from the end of this expression, leaving just the inner expression.  Template interpolation syntax is still used to construct strings from expressions when the template includes multiple interpolation sequences or a mixture of literal strings and interpolations. This deprecation applies only to templates that consist entirely of a single interpolation sequence. 

There are hundreds of these messages. Is there an automated way to fix them?

like image 566
Kevin Burke Avatar asked Nov 25 '19 19:11

Kevin Burke


People also ask

Is interpolation deprecated Terraform?

default. arn}" Terraform 0.11 and earlier required all non-constant expressions to be provided via interpolation syntax, but this pattern is now deprecated. To silence this warning, remove the "${ sequence from the start and the }" sequence from the end of this expression, leaving just the inner expression.

Does Terraform allow variable interpolation?

Embedded within strings in Terraform, whether you're using the Terraform syntax or JSON syntax, you can interpolate other values. These interpolations are wrapped in ${} , such as ${var. foo} . The interpolation syntax is powerful and allows you to reference variables, attributes of resources, call functions, etc.

What is interpolation Terraform?

What is Terraform interpolation? In Terraform, string interpolation (or variable interpolation, variable substitution, or variable expansion) is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.


2 Answers

  Warning: Interpolation-only expressions are deprecated    on main.tf line 3, in provider "aws":    3:   region  = "${var.region}" 

I also got the above warning, which is due to the changed syntax for declaring variables in terraform. See the example below -:

Old syntax- region = "${var.region}" # you will get Interpolation-only warning

New Synatx- region = var.region # no warning

Check the syntax and correct it using any code editor.

like image 70
yetis200 Avatar answered Sep 19 '22 10:09

yetis200


Did you upgrade the code first?

Terraform 0.11 isn't compatible with 0.12, so you have to upgrade it first.

terraform init terraform 0.12upgrade 

If your Terraform code is calling other terraform modules, please make sure you have upgraded these terraform modules to 0.12 as well.

like image 21
BMW Avatar answered Sep 18 '22 10:09

BMW