Merge pull request #26334 from hashicorp/alisdair/deprecate-nested-redundant-interpolation-expressions
configs: Deprecate nested redundant interpolations
This commit is contained in:
commit
0a5f2d9047
|
@ -142,23 +142,27 @@ func warnForDeprecatedInterpolationsInBody(body hcl.Body) hcl.Diagnostics {
|
||||||
}
|
}
|
||||||
|
|
||||||
func warnForDeprecatedInterpolationsInExpr(expr hcl.Expression) hcl.Diagnostics {
|
func warnForDeprecatedInterpolationsInExpr(expr hcl.Expression) hcl.Diagnostics {
|
||||||
var diags hcl.Diagnostics
|
node, ok := expr.(hclsyntax.Node)
|
||||||
|
if !ok {
|
||||||
if _, ok := expr.(*hclsyntax.TemplateWrapExpr); !ok {
|
return nil
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
diags = append(diags, &hcl.Diagnostic{
|
return hclsyntax.VisitAll(node, func(n hclsyntax.Node) hcl.Diagnostics {
|
||||||
Severity: hcl.DiagWarning,
|
e, ok := n.(*hclsyntax.TemplateWrapExpr)
|
||||||
Summary: "Interpolation-only expressions are deprecated",
|
if !ok {
|
||||||
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.",
|
// We're only interested in TemplateWrapExpr, because that's how
|
||||||
Subject: expr.Range().Ptr(),
|
// 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 diags
|
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(),
|
||||||
|
}}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,7 @@ resource "null_resource" "a" {
|
||||||
# in the template.
|
# in the template.
|
||||||
template = " ${var.triggers["greeting"]} "
|
template = " ${var.triggers["greeting"]} "
|
||||||
|
|
||||||
# No warning for this one, because it's embedded inside a more complex
|
wrapped = ["${var.triggers["greeting"]}"] # WARNING: Interpolation-only expressions are deprecated
|
||||||
# expression and our check is only for direct assignment to attributes.
|
|
||||||
wrapped = ["${var.triggers["greeting"]}"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +39,10 @@ module "foo" {
|
||||||
}
|
}
|
||||||
|
|
||||||
data "null_data_source" "b" {
|
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
|
has_computed_default = "${var.foo}" # WARNING: Interpolation-only expressions are deprecated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue