provisioners/file: use the old communicator.New just to minimize risk

This commit is contained in:
Mitchell Hashimoto 2016-12-22 16:43:52 -08:00
parent 02a4adc07c
commit a2e044829b
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 7 additions and 18 deletions

View File

@ -40,11 +40,11 @@ func Provisioner() terraform.ResourceProvisioner {
} }
func applyFn(ctx context.Context) error { func applyFn(ctx context.Context) error {
connData := ctx.Value(schema.ProvConnDataKey).(*schema.ResourceData) connState := ctx.Value(schema.ProvRawStateKey).(*terraform.InstanceState)
data := ctx.Value(schema.ProvConfigDataKey).(*schema.ResourceData) data := ctx.Value(schema.ProvConfigDataKey).(*schema.ResourceData)
// Get a new communicator // Get a new communicator
comm, err := communicator.NewData(connData) comm, err := communicator.New(connState)
if err != nil { if err != nil {
return err return err
} }

View File

@ -8,7 +8,6 @@ import (
"github.com/hashicorp/terraform/communicator/remote" "github.com/hashicorp/terraform/communicator/remote"
"github.com/hashicorp/terraform/communicator/ssh" "github.com/hashicorp/terraform/communicator/ssh"
"github.com/hashicorp/terraform/communicator/winrm" "github.com/hashicorp/terraform/communicator/winrm"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -52,18 +51,3 @@ func New(s *terraform.InstanceState) (Communicator, error) {
return nil, fmt.Errorf("connection type '%s' not supported", connType) return nil, fmt.Errorf("connection type '%s' not supported", connType)
} }
} }
// NewData creates a new Communicator from a ResourceData structure that
// represents the connection information.
func NewData(d *schema.ResourceData) (Communicator, error) {
// Turn the ResourceData into a legacy-style ConnInfo struct that
// is used to instantiate the communicator.
raw := d.State()
state := &terraform.InstanceState{
Ephemeral: terraform.EphemeralState{
ConnInfo: raw.Attributes,
},
}
return New(state)
}

View File

@ -61,6 +61,10 @@ const (
// This returns a terraform.UIOutput. Guaranteed to never be nil. // This returns a terraform.UIOutput. Guaranteed to never be nil.
ProvOutputKey ProvOutputKey
// This returns the raw InstanceState passed to Apply. Guaranteed to
// be set, but may be nil.
ProvRawStateKey
) )
// InternalValidate should be called to validate the structure // InternalValidate should be called to validate the structure
@ -171,5 +175,6 @@ func (p *Provisioner) Apply(
ctx = context.WithValue(ctx, ProvConnDataKey, connData) ctx = context.WithValue(ctx, ProvConnDataKey, connData)
ctx = context.WithValue(ctx, ProvConfigDataKey, configData) ctx = context.WithValue(ctx, ProvConfigDataKey, configData)
ctx = context.WithValue(ctx, ProvOutputKey, o) ctx = context.WithValue(ctx, ProvOutputKey, o)
ctx = context.WithValue(ctx, ProvRawStateKey, s)
return p.ApplyFunc(ctx) return p.ApplyFunc(ctx)
} }