provisioner/puppet: fix bug when connection type was not set in config (#23057)

Before this, the Terraform Puppet provisioner would error out in a
confusing way if the type attribute in a connection block was not given.

Apparently an omitted type leads to type having a value "" which must be
then assumed to mean "ssh".

Fixes #23004
This commit is contained in:
Alex Harvey 2019-10-18 02:46:55 +11:00 committed by Kristin Laemmert
parent ee854261c5
commit cbeedfca35
1 changed files with 18 additions and 4 deletions

View File

@ -128,7 +128,7 @@ func applyFn(ctx context.Context) error {
if p.OSType == "" { if p.OSType == "" {
switch connType := state.Ephemeral.ConnInfo["type"]; connType { switch connType := state.Ephemeral.ConnInfo["type"]; connType {
case "ssh", "": case "ssh", "": // The default connection type is ssh, so if the type is empty assume ssh
p.OSType = "linux" p.OSType = "linux"
case "winrm": case "winrm":
p.OSType = "windows" p.OSType = "windows"
@ -259,16 +259,30 @@ func (p *provisioner) generateAutosignToken(certname string) (string, error) {
} }
func (p *provisioner) installPuppetAgentOpenSource() error { func (p *provisioner) installPuppetAgentOpenSource() error {
task := "puppet_agent::install"
connType := p.instanceState.Ephemeral.ConnInfo["type"]
if connType == "" {
connType = "ssh"
}
agentConnInfo := map[string]string{
"type": connType,
"host": p.instanceState.Ephemeral.ConnInfo["host"],
"user": p.instanceState.Ephemeral.ConnInfo["user"],
"password": p.instanceState.Ephemeral.ConnInfo["password"], // Required on Windows only
}
result, err := bolt.Task( result, err := bolt.Task(
p.instanceState.Ephemeral.ConnInfo, agentConnInfo,
p.BoltTimeout, p.BoltTimeout,
p.UseSudo, p.UseSudo,
"puppet_agent::install", task,
nil, nil,
) )
if err != nil || result.Items[0].Status != "success" { if err != nil || result.Items[0].Status != "success" {
return fmt.Errorf("puppet_agent::install failed: %s\n%+v", err, result) return fmt.Errorf("%s failed: %s\n%+v", task, err, result)
} }
return nil return nil