don't hanlde "type" when parsing connection blocks

There's no provisioner schema yet, and we need to handle the type
dynamically during evaluation.
This commit is contained in:
James Bardin 2018-05-29 14:58:28 -04:00 committed by Martin Atkins
parent 30d6a40329
commit e0e177374f
2 changed files with 10 additions and 33 deletions

View File

@ -3,7 +3,6 @@ package configs
import ( import (
"fmt" "fmt"
"github.com/hashicorp/hcl2/gohcl"
"github.com/hashicorp/hcl2/hcl" "github.com/hashicorp/hcl2/hcl"
) )
@ -86,9 +85,12 @@ func decodeProvisionerBlock(block *hcl.Block) (*Provisioner, hcl.Diagnostics) {
} }
seenConnection = block seenConnection = block
conn, connDiags := decodeConnectionBlock(block) //conn, connDiags := decodeConnectionBlock(block)
diags = append(diags, connDiags...) //diags = append(diags, connDiags...)
pv.Connection = conn pv.Connection = &Connection{
Config: block.Body,
DeclRange: block.DefRange,
}
default: default:
// Should never happen because there are no other block types // 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 // Connection represents a "connection" block when used within either a
// "resource" or "provisioner" block in a module or file. // "resource" or "provisioner" block in a module or file.
type Connection struct { type Connection struct {
Type string
Config hcl.Body Config hcl.Body
DeclRange hcl.Range 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. // ProvisionerWhen is an enum for valid values for when to run provisioners.

View File

@ -231,9 +231,10 @@ func decodeResourceBlock(block *hcl.Block) (*Resource, hcl.Diagnostics) {
} }
seenConnection = block seenConnection = block
conn, connDiags := decodeConnectionBlock(block) r.Managed.Connection = &Connection{
diags = append(diags, connDiags...) Config: block.Body,
r.Managed.Connection = conn DeclRange: block.DefRange,
}
case "provisioner": case "provisioner":
pv, pvDiags := decodeProvisionerBlock(block) pv, pvDiags := decodeProvisionerBlock(block)