Skip to content

Commit

Permalink
Use the InstanceState to query any connection details (#15271)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander van Harmelen authored Jun 14, 2017
1 parent 9706042 commit 21a646f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions builtin/provisioners/chef/resource_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func Provisioner() terraform.ResourceProvisioner {
// TODO: Support context cancelling (Provisioner Stop)
func applyFn(ctx context.Context) error {
o := ctx.Value(schema.ProvOutputKey).(terraform.UIOutput)
s := ctx.Value(schema.ProvRawStateKey).(*terraform.InstanceState)
d := ctx.Value(schema.ProvConfigDataKey).(*schema.ResourceData)

// Decode the raw config for this provisioner
Expand All @@ -265,7 +266,7 @@ func applyFn(ctx context.Context) error {
}

if p.OSType == "" {
switch t := d.State().Ephemeral.ConnInfo["type"]; t {
switch t := s.Ephemeral.ConnInfo["type"]; t {
case "ssh", "": // The default connection type is ssh, so if the type is empty assume ssh
p.OSType = "linux"
case "winrm":
Expand All @@ -285,7 +286,7 @@ func applyFn(ctx context.Context) error {
p.generateClientKey = p.generateClientKeyFunc(linuxKnifeCmd, linuxConfDir, linuxNoOutput)
p.configureVaults = p.configureVaultsFunc(linuxGemCmd, linuxKnifeCmd, linuxConfDir)
p.runChefClient = p.runChefClientFunc(linuxChefCmd, linuxConfDir)
p.useSudo = !p.PreventSudo && d.State().Ephemeral.ConnInfo["user"] != "root"
p.useSudo = !p.PreventSudo && s.Ephemeral.ConnInfo["user"] != "root"
case "windows":
p.cleanupUserKeyCmd = fmt.Sprintf("cd %s && del /F /Q %s", windowsConfDir, p.UserName+".pem")
p.createConfigFiles = p.windowsCreateConfigFiles
Expand All @@ -300,7 +301,7 @@ func applyFn(ctx context.Context) error {
}

// Get a new communicator
comm, err := communicator.New(d.State())
comm, err := communicator.New(s)
if err != nil {
return err
}
Expand Down

0 comments on commit 21a646f

Please sign in to comment.