From e0e177374ff35502b6510224adec0a52354b1fde Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 29 May 2018 14:58:28 -0400 Subject: [PATCH] don't hanlde "type" when parsing connection blocks There's no provisioner schema yet, and we need to handle the type dynamically during evaluation. --- configs/provisioner.go | 36 ++++++------------------------------ configs/resource.go | 7 ++++--- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/configs/provisioner.go b/configs/provisioner.go index 843f4c0f9..909044902 100644 --- a/configs/provisioner.go +++ b/configs/provisioner.go @@ -3,7 +3,6 @@ package configs import ( "fmt" - "github.com/hashicorp/hcl2/gohcl" "github.com/hashicorp/hcl2/hcl" ) @@ -86,9 +85,12 @@ func decodeProvisionerBlock(block *hcl.Block) (*Provisioner, hcl.Diagnostics) { } seenConnection = block - conn, connDiags := decodeConnectionBlock(block) - diags = append(diags, connDiags...) - pv.Connection = conn + //conn, connDiags := decodeConnectionBlock(block) + //diags = append(diags, connDiags...) + pv.Connection = &Connection{ + Config: block.Body, + DeclRange: block.DefRange, + } default: // Should never happen because there are no other block types @@ -102,35 +104,9 @@ func decodeProvisionerBlock(block *hcl.Block) (*Provisioner, hcl.Diagnostics) { // Connection represents a "connection" block when used within either a // "resource" or "provisioner" block in a module or file. type Connection struct { - Type string Config hcl.Body DeclRange hcl.Range - TypeRange *hcl.Range // nil if type is not set -} - -func decodeConnectionBlock(block *hcl.Block) (*Connection, hcl.Diagnostics) { - content, config, diags := block.Body.PartialContent(&hcl.BodySchema{ - Attributes: []hcl.AttributeSchema{ - { - Name: "type", - }, - }, - }) - - conn := &Connection{ - Type: "ssh", - Config: config, - DeclRange: block.DefRange, - } - - if attr, exists := content.Attributes["type"]; exists { - valDiags := gohcl.DecodeExpression(attr.Expr, nil, &conn.Type) - diags = append(diags, valDiags...) - conn.TypeRange = attr.Expr.Range().Ptr() - } - - return conn, diags } // ProvisionerWhen is an enum for valid values for when to run provisioners. diff --git a/configs/resource.go b/configs/resource.go index e10e37128..1a39fe7cc 100644 --- a/configs/resource.go +++ b/configs/resource.go @@ -231,9 +231,10 @@ func decodeResourceBlock(block *hcl.Block) (*Resource, hcl.Diagnostics) { } seenConnection = block - conn, connDiags := decodeConnectionBlock(block) - diags = append(diags, connDiags...) - r.Managed.Connection = conn + r.Managed.Connection = &Connection{ + Config: block.Body, + DeclRange: block.DefRange, + } case "provisioner": pv, pvDiags := decodeProvisionerBlock(block)