From 8112f589c1bfbf8767b8ce744cc573b974556a89 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 4 Dec 2018 17:29:42 -0800 Subject: [PATCH] configs/configupgrade: Pass through connection and provisioner blocks This is a temporary implementation of these rules just so that these can be passed through verbatim (rather than generating an error) while we do testing of other features. A subsequent commit will finish these with their own custom rulesets. --- .../valid/noop/input/resources.tf | 8 ++++++++ .../test-fixtures/valid/noop/want/resources.tf | 8 ++++++++ configs/configupgrade/upgrade_native.go | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/configs/configupgrade/test-fixtures/valid/noop/input/resources.tf b/configs/configupgrade/test-fixtures/valid/noop/input/resources.tf index e8210aa23..f738f6971 100644 --- a/configs/configupgrade/test-fixtures/valid/noop/input/resources.tf +++ b/configs/configupgrade/test-fixtures/valid/noop/input/resources.tf @@ -1,3 +1,11 @@ resource "test_instance" "example" { + connection { + host = "127.0.0.1" + } + provisioner "local-exec" { + connection { + host = "127.0.0.2" + } + } } diff --git a/configs/configupgrade/test-fixtures/valid/noop/want/resources.tf b/configs/configupgrade/test-fixtures/valid/noop/want/resources.tf index e8210aa23..f738f6971 100644 --- a/configs/configupgrade/test-fixtures/valid/noop/want/resources.tf +++ b/configs/configupgrade/test-fixtures/valid/noop/want/resources.tf @@ -1,3 +1,11 @@ resource "test_instance" "example" { + connection { + host = "127.0.0.1" + } + provisioner "local-exec" { + connection { + host = "127.0.0.2" + } + } } diff --git a/configs/configupgrade/upgrade_native.go b/configs/configupgrade/upgrade_native.go index 009d44cf6..2e8d91fe0 100644 --- a/configs/configupgrade/upgrade_native.go +++ b/configs/configupgrade/upgrade_native.go @@ -329,6 +329,24 @@ func (u *Upgrader) upgradeNativeSyntaxResource(filename string, buf *bytes.Buffe rules["depends_on"] = dependsOnAttributeRule(filename, an) rules["provider"] = maybeBareTraversalAttributeRule(filename, an) rules["lifecycle"] = nestedBlockRule(filename, lifecycleBlockBodyRules(filename, an), an, adhocComments) + rules["connection"] = func(buf *bytes.Buffer, blockAddr string, item *hcl1ast.ObjectItem) tfdiags.Diagnostics { + // TODO: For the few resource types that were setting ConnInfo in + // state after create/update in prior versions, generate the additional + // explicit connection settings that are now required if and only if + // there's at least one provisioner block. + // For now, we just pass this through as-is. + hcl1printer.Fprint(buf, item) + buf.WriteByte('\n') + return nil + } + rules["provisioner"] = func(buf *bytes.Buffer, blockAddr string, item *hcl1ast.ObjectItem) tfdiags.Diagnostics { + // TODO: Look up the provisioner schema and map this properly to ensure + // any references get properly updated. + // For now, we just pass this through as-is. + hcl1printer.Fprint(buf, item) + buf.WriteByte('\n') + return nil + } printComments(buf, item.LeadComment) printBlockOpen(buf, blockType, labels, item.LineComment)