Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions configs/compat_shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,27 @@ func warnForDeprecatedInterpolationsInBody(body hcl.Body) hcl.Diagnostics {
}

func warnForDeprecatedInterpolationsInExpr(expr hcl.Expression) hcl.Diagnostics {
var diags hcl.Diagnostics

if _, ok := expr.(*hclsyntax.TemplateWrapExpr); !ok {
// We're only interested in TemplateWrapExpr, because that's how
// the HCL native syntax parser represents the case of a template
// that consists entirely of a single interpolation expression, which
// is therefore subject to the special case of passing through the
// inner value without conversion to string.
return diags
node, ok := expr.(hclsyntax.Node)
if !ok {
return nil
}

diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: "Interpolation-only expressions are deprecated",
Detail: "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.\n\nTemplate 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.",
Subject: expr.Range().Ptr(),
return hclsyntax.VisitAll(node, func(n hclsyntax.Node) hcl.Diagnostics {
e, ok := n.(*hclsyntax.TemplateWrapExpr)
if !ok {
// We're only interested in TemplateWrapExpr, because that's how
// the HCL native syntax parser represents the case of a template
// that consists entirely of a single interpolation expression, which
// is therefore subject to the special case of passing through the
// inner value without conversion to string.
return nil
}

return hcl.Diagnostics{&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: "Interpolation-only expressions are deprecated",
Detail: "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.\n\nTemplate 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.",
Subject: e.Range().Ptr(),
}}
})

return diags
}
8 changes: 5 additions & 3 deletions configs/testdata/warning-files/redundant_interp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ resource "null_resource" "a" {
# in the template.
template = " ${var.triggers["greeting"]} "

# No warning for this one, because it's embedded inside a more complex
# expression and our check is only for direct assignment to attributes.
wrapped = ["${var.triggers["greeting"]}"]
wrapped = ["${var.triggers["greeting"]}"] # WARNING: Interpolation-only expressions are deprecated
}
}

Expand All @@ -41,6 +39,10 @@ module "foo" {
}

data "null_data_source" "b" {
inputs = {
host = "${var.triggers["host"]}" # WARNING: Interpolation-only expressions are deprecated
}

has_computed_default = "${var.foo}" # WARNING: Interpolation-only expressions are deprecated
}

Expand Down