terraform

Fix "Interpolation-only expressions are deprecated" warning


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?


Solution

  • This tool will automatically strip the beginning and ending quotes and braces for you, which fixes the warnings: https://github.com/apparentlymart/terraform-clean-syntax

    go get github.com/apparentlymart/terraform-clean-syntax
    terraform-clean-syntax .