configs: More interpolation-only expr deprecations

Extend the deprecation for interpolation-only expressions to include
module calls, data sources, outputs, and locals.
This commit is contained in:
Alisdair McDiarmid 2020-07-02 10:32:57 -04:00
parent fa4917172d
commit e693c14e5a
4 changed files with 48 additions and 3 deletions

View File

@ -31,6 +31,13 @@ type ModuleCall struct {
} }
func decodeModuleBlock(block *hcl.Block, override bool) (*ModuleCall, hcl.Diagnostics) { func decodeModuleBlock(block *hcl.Block, override bool) (*ModuleCall, hcl.Diagnostics) {
var diags hcl.Diagnostics
// Produce deprecation messages for any pre-0.12-style
// single-interpolation-only expressions.
moreDiags := warnForDeprecatedInterpolationsInBody(block.Body)
diags = append(diags, moreDiags...)
mc := &ModuleCall{ mc := &ModuleCall{
Name: block.Labels[0], Name: block.Labels[0],
DeclRange: block.DefRange, DeclRange: block.DefRange,
@ -41,7 +48,8 @@ func decodeModuleBlock(block *hcl.Block, override bool) (*ModuleCall, hcl.Diagno
schema = schemaForOverrides(schema) schema = schemaForOverrides(schema)
} }
content, remain, diags := block.Body.PartialContent(schema) content, remain, moreDiags := block.Body.PartialContent(schema)
diags = append(diags, moreDiags...)
mc.Config = remain mc.Config = remain
if !hclsyntax.ValidIdentifier(mc.Name) { if !hclsyntax.ValidIdentifier(mc.Name) {

View File

@ -433,6 +433,8 @@ type Output struct {
} }
func decodeOutputBlock(block *hcl.Block, override bool) (*Output, hcl.Diagnostics) { func decodeOutputBlock(block *hcl.Block, override bool) (*Output, hcl.Diagnostics) {
var diags hcl.Diagnostics
o := &Output{ o := &Output{
Name: block.Labels[0], Name: block.Labels[0],
DeclRange: block.DefRange, DeclRange: block.DefRange,
@ -443,7 +445,13 @@ func decodeOutputBlock(block *hcl.Block, override bool) (*Output, hcl.Diagnostic
schema = schemaForOverrides(schema) schema = schemaForOverrides(schema)
} }
content, diags := block.Body.Content(schema) // Produce deprecation messages for any pre-0.12-style
// single-interpolation-only expressions.
moreDiags := warnForDeprecatedInterpolationsInBody(block.Body)
diags = append(diags, moreDiags...)
content, moreDiags := block.Body.Content(schema)
diags = append(diags, moreDiags...)
if !hclsyntax.ValidIdentifier(o.Name) { if !hclsyntax.ValidIdentifier(o.Name) {
diags = append(diags, &hcl.Diagnostic{ diags = append(diags, &hcl.Diagnostic{
@ -506,6 +514,11 @@ func decodeLocalsBlock(block *hcl.Block) ([]*Local, hcl.Diagnostics) {
}) })
} }
// Produce deprecation messages for any pre-0.12-style
// single-interpolation-only expressions.
moreDiags := warnForDeprecatedInterpolationsInExpr(attr.Expr)
diags = append(diags, moreDiags...)
locals = append(locals, &Local{ locals = append(locals, &Local{
Name: name, Name: name,
Expr: attr.Expr, Expr: attr.Expr,

View File

@ -290,6 +290,7 @@ func decodeResourceBlock(block *hcl.Block) (*Resource, hcl.Diagnostics) {
} }
func decodeDataBlock(block *hcl.Block) (*Resource, hcl.Diagnostics) { func decodeDataBlock(block *hcl.Block) (*Resource, hcl.Diagnostics) {
var diags hcl.Diagnostics
r := &Resource{ r := &Resource{
Mode: addrs.DataResourceMode, Mode: addrs.DataResourceMode,
Type: block.Labels[0], Type: block.Labels[0],
@ -298,7 +299,13 @@ func decodeDataBlock(block *hcl.Block) (*Resource, hcl.Diagnostics) {
TypeRange: block.LabelRanges[0], TypeRange: block.LabelRanges[0],
} }
content, remain, diags := block.Body.PartialContent(dataBlockSchema) // Produce deprecation messages for any pre-0.12-style
// single-interpolation-only expressions.
moreDiags := warnForDeprecatedInterpolationsInBody(block.Body)
diags = append(diags, moreDiags...)
content, remain, moreDiags := block.Body.PartialContent(dataBlockSchema)
diags = append(diags, moreDiags...)
r.Config = remain r.Config = remain
if !hclsyntax.ValidIdentifier(r.Type) { if !hclsyntax.ValidIdentifier(r.Type) {

View File

@ -34,3 +34,20 @@ resource "null_resource" "a" {
wrapped = ["${var.triggers["greeting"]}"] wrapped = ["${var.triggers["greeting"]}"]
} }
} }
module "foo" {
source = "./foo"
foo = "${var.foo}" # WARNING: Interpolation-only expressions are deprecated
}
data "null_data_source" "b" {
has_computed_default = "${var.foo}" # WARNING: Interpolation-only expressions are deprecated
}
output "output" {
value = "${var.foo}" # WARNING: Interpolation-only expressions are deprecated
}
locals {
foo = "${var.foo}" # WARNING: Interpolation-only expressions are deprecated
}