configs/configupgrade: Initial passthrough mapping for module blocks

Some further rules are required here to deal with the meta-arguments we
accept inside these blocks, but this is good enough to pass through most
module blocks using the standard attribute-expression-based mapping.
This commit is contained in:
Martin Atkins 2018-12-04 13:49:57 -08:00
parent 4b5d31d35d
commit ea3b8b364c
3 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,3 @@
module "foo" {
source = "./foo"
}

View File

@ -0,0 +1,3 @@
module "foo" {
source = "./foo"
}

View File

@ -191,6 +191,33 @@ func (u *Upgrader) upgradeNativeSyntaxFile(filename string, src []byte, an *anal
diags = diags.Append(bodyDiags)
buf.WriteString("}\n\n")
case "module":
if len(labels) != 1 {
diags = diags.Append(&hcl2.Diagnostic{
Severity: hcl2.DiagError,
Summary: fmt.Sprintf("Invalid %s block", blockType),
Detail: fmt.Sprintf("A %s block must have one label: the module call name.", blockType),
Subject: &declRange,
})
continue
}
// Since upgrading is a single-module endeavor, we don't have access
// to the configuration of the child module here, but we know that
// in practice all arguments that aren't reserved meta-arguments
// in a module block are normal expression attributes so we'll
// start with the straightforward mapping of those and override
// the special lifecycle arguments below.
rules := justAttributesBodyRules(filename, body, an)
rules["source"] = noInterpAttributeRule(filename, cty.String, an)
printComments(&buf, item.LeadComment)
printBlockOpen(&buf, blockType, labels, item.LineComment)
log.Printf("[TRACE] configupgrade: Upgrading module.%s at %s", labels[0], declRange)
bodyDiags := upgradeBlockBody(filename, fmt.Sprintf("module.%s", labels[0]), &buf, body.List.Items, body.Rbrace, rules, adhocComments)
diags = diags.Append(bodyDiags)
buf.WriteString("}\n\n")
case "locals":
log.Printf("[TRACE] configupgrade: Upgrading locals block at %s", declRange)
printComments(&buf, item.LeadComment)