Use the InstanceState to query any connection details (#15271)
Fixes #15205 #15270
This commit is contained in:
parent
9706042ddd
commit
21a646f6fe
|
@ -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
|
||||
|
@ -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":
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue