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 {
|
||||
var diags hcl.Diagnostics
|
||||
node, ok := expr.(hclsyntax.Node)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, ok := expr.(*hclsyntax.TemplateWrapExpr); !ok {
|
||||
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 diags
|
||||
return nil
|
||||
}
|
||||
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
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: expr.Range().Ptr(),
|
||||
Subject: e.Range().Ptr(),
|
||||
}}
|
||||
})
|
||||
|
||||
return diags
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue