diff --git a/configs/configupgrade/test-fixtures/valid/ignore-changes-flatmap-colls/input/ignore-changes-flatmap-colls.tf b/configs/configupgrade/test-fixtures/valid/ignore-changes-flatmap-colls/input/ignore-changes-flatmap-colls.tf new file mode 100644 index 0000000000..1eeadef557 --- /dev/null +++ b/configs/configupgrade/test-fixtures/valid/ignore-changes-flatmap-colls/input/ignore-changes-flatmap-colls.tf @@ -0,0 +1,8 @@ +resource "test_instance" "foo" { + lifecycle { + ignore_changes = [ + "a.%", + "b.#", + ] + } +} diff --git a/configs/configupgrade/test-fixtures/valid/ignore-changes-flatmap-colls/want/ignore-changes-flatmap-colls.tf b/configs/configupgrade/test-fixtures/valid/ignore-changes-flatmap-colls/want/ignore-changes-flatmap-colls.tf new file mode 100644 index 0000000000..b79d3639d8 --- /dev/null +++ b/configs/configupgrade/test-fixtures/valid/ignore-changes-flatmap-colls/want/ignore-changes-flatmap-colls.tf @@ -0,0 +1,8 @@ +resource "test_instance" "foo" { + lifecycle { + ignore_changes = [ + a, + b, + ] + } +} diff --git a/configs/configupgrade/test-fixtures/valid/ignore-changes-flatmap-colls/want/versions.tf b/configs/configupgrade/test-fixtures/valid/ignore-changes-flatmap-colls/want/versions.tf new file mode 100644 index 0000000000..d9b6f790b9 --- /dev/null +++ b/configs/configupgrade/test-fixtures/valid/ignore-changes-flatmap-colls/want/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.12" +} diff --git a/configs/configupgrade/upgrade_expr.go b/configs/configupgrade/upgrade_expr.go index aa4d2bcbc2..b1e40450c6 100644 --- a/configs/configupgrade/upgrade_expr.go +++ b/configs/configupgrade/upgrade_expr.go @@ -560,6 +560,14 @@ func upgradeHeredocBody(buf *bytes.Buffer, val *hilast.Output, filename string, func upgradeTraversalExpr(val interface{}, filename string, an *analysis) ([]byte, tfdiags.Diagnostics) { if lit, ok := val.(*hcl1ast.LiteralType); ok && lit.Token.Type == hcl1token.STRING { trStr := lit.Token.Value().(string) + if strings.HasSuffix(trStr, ".%") || strings.HasSuffix(trStr, ".#") { + // Terraform 0.11 would often not validate traversals given in + // strings and so users would get away with this sort of + // flatmap-implementation-detail reference, particularly inside + // ignore_changes. We'll just trim these off to tolerate it, + // rather than failing below in ParseTraversalAbs. + trStr = trStr[:len(trStr)-2] + } trSrc := []byte(trStr) _, trDiags := hcl2syntax.ParseTraversalAbs(trSrc, "", hcl2.Pos{}) if !trDiags.HasErrors() {