From 154911688a74bc8afe58f22e49f37a97b6933c12 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 20 Feb 2019 11:53:56 -0800 Subject: [PATCH] configs/configupgrade: upgrade expressions inside heredocs HEREDOC tokens are a little more fussy than normal string sequences because we need to preserve the whitespace within them along with the start and end markers while we upgrade any interpolated expressions inside. We need to do some work locally here because the HCL heredoc processing "does too much" and throws away information we need to do a faithful upgrade. We also need to contend with the fact that Terraform <=0.11 had an older version of HCL that accidentally permitted a degenerate form of heredoc where the marker was at the end of the final line, like this: degenerate = < heredoc-flush}/want/versions.tf (100%) create mode 100644 configs/configupgrade/test-fixtures/valid/heredoc-no-interp/input/heredoc.tf create mode 100644 configs/configupgrade/test-fixtures/valid/heredoc-no-interp/want/heredoc.tf create mode 100644 configs/configupgrade/test-fixtures/valid/heredoc-no-interp/want/versions.tf rename configs/configupgrade/test-fixtures/valid/{heredoc => heredoc-sameline}/input/heredoc.tf (100%) rename configs/configupgrade/test-fixtures/valid/{heredoc => heredoc-sameline}/want/heredoc.tf (82%) create mode 100644 configs/configupgrade/test-fixtures/valid/heredoc-sameline/want/versions.tf create mode 100644 configs/configupgrade/test-fixtures/valid/heredoc-standard/input/heredoc.tf create mode 100644 configs/configupgrade/test-fixtures/valid/heredoc-standard/want/heredoc.tf create mode 100644 configs/configupgrade/test-fixtures/valid/heredoc-standard/want/versions.tf diff --git a/configs/configupgrade/test-fixtures/valid/heredoc-flush/input/heredoc.tf b/configs/configupgrade/test-fixtures/valid/heredoc-flush/input/heredoc.tf new file mode 100644 index 000000000..918bbb66b --- /dev/null +++ b/configs/configupgrade/test-fixtures/valid/heredoc-flush/input/heredoc.tf @@ -0,0 +1,12 @@ +locals { + baz = { "greeting" = "hello" } + cert_options = <<-EOF + A + B ${lookup(local.baz, "greeting")} + C + EOF +} + +output "local" { + value = "${local.cert_options}" +} diff --git a/configs/configupgrade/test-fixtures/valid/heredoc-flush/want/heredoc.tf b/configs/configupgrade/test-fixtures/valid/heredoc-flush/want/heredoc.tf new file mode 100644 index 000000000..4ffcc6e44 --- /dev/null +++ b/configs/configupgrade/test-fixtures/valid/heredoc-flush/want/heredoc.tf @@ -0,0 +1,15 @@ +locals { + baz = { + "greeting" = "hello" + } + cert_options = <<-EOF + A + B ${local.baz["greeting"]} + C +EOF + +} + +output "local" { +value = local.cert_options +} diff --git a/configs/configupgrade/test-fixtures/valid/heredoc/want/versions.tf b/configs/configupgrade/test-fixtures/valid/heredoc-flush/want/versions.tf similarity index 100% rename from configs/configupgrade/test-fixtures/valid/heredoc/want/versions.tf rename to configs/configupgrade/test-fixtures/valid/heredoc-flush/want/versions.tf diff --git a/configs/configupgrade/test-fixtures/valid/heredoc-no-interp/input/heredoc.tf b/configs/configupgrade/test-fixtures/valid/heredoc-no-interp/input/heredoc.tf new file mode 100644 index 000000000..b80973754 --- /dev/null +++ b/configs/configupgrade/test-fixtures/valid/heredoc-no-interp/input/heredoc.tf @@ -0,0 +1,6 @@ +variable "foo" { + default = <