diff --git a/builder/cloudstack/builder.go b/builder/cloudstack/builder.go index 325b2ea86..fe376125f 100644 --- a/builder/cloudstack/builder.go +++ b/builder/cloudstack/builder.go @@ -77,7 +77,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &stepSetupNetworking{}, &communicator.StepConnect{ Config: &b.config.Comm, - Host: commHost(b.config.Comm.SSHHost), + Host: communicator.CommHost(b.config.Comm.SSHHost, "ipaddress"), SSHConfig: b.config.Comm.SSHConfigFunc(), SSHPort: commPort, WinRMPort: commPort, diff --git a/builder/cloudstack/ssh.go b/builder/cloudstack/ssh.go index a3b81ca64..518747ceb 100644 --- a/builder/cloudstack/ssh.go +++ b/builder/cloudstack/ssh.go @@ -7,21 +7,6 @@ import ( "github.com/hashicorp/packer/helper/multistep" ) -func commHost(host string) func(multistep.StateBag) (string, error) { - return func(state multistep.StateBag) (string, error) { - if host != "" { - log.Printf("Using ssh_host value: %s", host) - return host, nil - } - ip, hasIP := state.Get("ipaddress").(string) - if !hasIP { - return "", fmt.Errorf("Failed to retrieve IP address") - } - - return ip, nil - } -} - func commPort(state multistep.StateBag) (int, error) { commPort, hasPort := state.Get("commPort").(int) if !hasPort { diff --git a/builder/digitalocean/builder.go b/builder/digitalocean/builder.go index 7b10c90cd..6519d30f5 100644 --- a/builder/digitalocean/builder.go +++ b/builder/digitalocean/builder.go @@ -86,7 +86,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack new(stepDropletInfo), &communicator.StepConnect{ Config: &b.config.Comm, - Host: commHost(b.config.Comm.SSHHost), + Host: communicator.CommHost(b.config.Comm.SSHHost, "droplet_ip"), SSHConfig: b.config.Comm.SSHConfigFunc(), }, new(common.StepProvision), diff --git a/builder/digitalocean/ssh.go b/builder/digitalocean/ssh.go deleted file mode 100644 index e0567cd27..000000000 --- a/builder/digitalocean/ssh.go +++ /dev/null @@ -1,18 +0,0 @@ -package digitalocean - -import ( - "log" - - "github.com/hashicorp/packer/helper/multistep" -) - -func commHost(host string) func(multistep.StateBag) (string, error) { - return func(state multistep.StateBag) (string, error) { - if host != "" { - log.Printf("Using ssh_host value: %s", host) - return host, nil - } - ipAddress := state.Get("droplet_ip").(string) - return ipAddress, nil - } -} diff --git a/builder/googlecompute/builder.go b/builder/googlecompute/builder.go index 34aa97832..1cd8692b0 100644 --- a/builder/googlecompute/builder.go +++ b/builder/googlecompute/builder.go @@ -67,7 +67,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack }, &communicator.StepConnect{ Config: &b.config.Comm, - Host: commHost(b.config.Comm.SSHHost), + Host: communicator.CommHost(b.config.Comm.SSHHost, "instance_ip"), SSHConfig: b.config.Comm.SSHConfigFunc(), WinRMConfig: winrmConfig, }, diff --git a/builder/googlecompute/ssh.go b/builder/googlecompute/ssh.go deleted file mode 100644 index 4638d8242..000000000 --- a/builder/googlecompute/ssh.go +++ /dev/null @@ -1,18 +0,0 @@ -package googlecompute - -import ( - "log" - - "github.com/hashicorp/packer/helper/multistep" -) - -func commHost(host string) func(multistep.StateBag) (string, error) { - return func(state multistep.StateBag) (string, error) { - if host != "" { - log.Printf("Using ssh_host value: %s", host) - return host, nil - } - ipAddress := state.Get("instance_ip").(string) - return ipAddress, nil - } -} diff --git a/builder/oneandone/builder.go b/builder/oneandone/builder.go index d09bbac64..5ea7674bc 100644 --- a/builder/oneandone/builder.go +++ b/builder/oneandone/builder.go @@ -44,7 +44,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack new(stepCreateServer), &communicator.StepConnect{ Config: &b.config.Comm, - Host: commHost(b.config.Comm.SSHHost), + Host: communicator.CommHost(b.config.Comm.SSHHost, "server_ip"), SSHConfig: b.config.Comm.SSHConfigFunc(), }, &common.StepProvision{}, diff --git a/builder/oneandone/ssh.go b/builder/oneandone/ssh.go deleted file mode 100644 index 9a3271f07..000000000 --- a/builder/oneandone/ssh.go +++ /dev/null @@ -1,19 +0,0 @@ -package oneandone - -import ( - "log" - - "github.com/hashicorp/packer/helper/multistep" -) - -func commHost(host string) func(multistep.StateBag) (string, error) { - return func(state multistep.StateBag) (string, error) { - if host != "" { - log.Printf("Using ssh_host value: %s", host) - return host, nil - } - - ipAddress := state.Get("server_ip").(string) - return ipAddress, nil - } -} diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index f6440ee03..d8e169146 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -129,7 +129,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack KeyName: fmt.Sprintf("packer-generated-key_%s", runID), StepConnectSSH: &communicator.StepConnectSSH{ Config: &b.config.BuilderComm, - Host: ocommon.CommHost(b.config.Comm.SSHHost), + Host: communicator.CommHost(b.config.Comm.SSHHost, "instance_ip"), SSHConfig: b.config.BuilderComm.SSHConfigFunc(), }, }, diff --git a/builder/oracle/common/ssh.go b/builder/oracle/common/ssh.go deleted file mode 100644 index 461c977b1..000000000 --- a/builder/oracle/common/ssh.go +++ /dev/null @@ -1,19 +0,0 @@ -package common - -import ( - "log" - - "github.com/hashicorp/packer/helper/multistep" -) - -func CommHost(host string) func(multistep.StateBag) (string, error) { - return func(state multistep.StateBag) (string, error) { - if host != "" { - log.Printf("Using ssh_host value: %s", host) - return host, nil - } - - ipAddress := state.Get("instance_ip").(string) - return ipAddress, nil - } -} diff --git a/builder/oracle/oci/builder.go b/builder/oracle/oci/builder.go index f4a60d3e1..7822b144f 100644 --- a/builder/oracle/oci/builder.go +++ b/builder/oracle/oci/builder.go @@ -65,7 +65,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack }, &communicator.StepConnect{ Config: &b.config.Comm, - Host: ocommon.CommHost(b.config.Comm.SSHHost), + Host: communicator.CommHost(b.config.Comm.SSHHost, "instance_ip"), SSHConfig: b.config.Comm.SSHConfigFunc(), }, &common.StepProvision{}, diff --git a/builder/profitbricks/builder.go b/builder/profitbricks/builder.go index 0cd2e0003..3ab9d18fe 100644 --- a/builder/profitbricks/builder.go +++ b/builder/profitbricks/builder.go @@ -41,7 +41,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack new(stepCreateServer), &communicator.StepConnect{ Config: &b.config.Comm, - Host: commHost(b.config.Comm.SSHHost), + Host: communicator.CommHost(b.config.Comm.SSHHost, "server_ip"), SSHConfig: b.config.Comm.SSHConfigFunc(), }, &common.StepProvision{}, diff --git a/builder/profitbricks/ssh.go b/builder/profitbricks/ssh.go deleted file mode 100644 index 5ae5f22d8..000000000 --- a/builder/profitbricks/ssh.go +++ /dev/null @@ -1,19 +0,0 @@ -package profitbricks - -import ( - "log" - - "github.com/hashicorp/packer/helper/multistep" -) - -func commHost(host string) func(multistep.StateBag) (string, error) { - return func(state multistep.StateBag) (string, error) { - if host != "" { - log.Printf("Using ssh_host value: %s", host) - return host, nil - } - - ipAddress := state.Get("server_ip").(string) - return ipAddress, nil - } -} diff --git a/builder/scaleway/builder.go b/builder/scaleway/builder.go index 3b194ed14..83812c4a3 100644 --- a/builder/scaleway/builder.go +++ b/builder/scaleway/builder.go @@ -56,7 +56,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack new(stepServerInfo), &communicator.StepConnect{ Config: &b.config.Comm, - Host: commHost(b.config.Comm.SSHHost), + Host: communicator.CommHost(b.config.Comm.SSHHost, "server_ip"), SSHConfig: b.config.Comm.SSHConfigFunc(), }, new(common.StepProvision), diff --git a/builder/scaleway/ssh.go b/builder/scaleway/ssh.go deleted file mode 100644 index 0c2c3f9b7..000000000 --- a/builder/scaleway/ssh.go +++ /dev/null @@ -1,19 +0,0 @@ -package scaleway - -import ( - "log" - - "github.com/hashicorp/packer/helper/multistep" -) - -func commHost(host string) func(multistep.StateBag) (string, error) { - return func(state multistep.StateBag) (string, error) { - if host != "" { - log.Printf("Using ssh_host value: %s", host) - return host, nil - } - - ipAddress := state.Get("server_ip").(string) - return ipAddress, nil - } -} diff --git a/builder/yandex/builder.go b/builder/yandex/builder.go index 8fff5b4ba..5020fec2b 100644 --- a/builder/yandex/builder.go +++ b/builder/yandex/builder.go @@ -61,7 +61,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &stepInstanceInfo{}, &communicator.StepConnect{ Config: &b.config.Communicator, - Host: commHost(b.config.Communicator.SSHHost), + Host: communicator.CommHost(b.config.Communicator.SSHHost, "instance_ip"), SSHConfig: b.config.Communicator.SSHConfigFunc(), }, &common.StepProvision{}, diff --git a/builder/yandex/ssh.go b/builder/yandex/ssh.go deleted file mode 100644 index 4a18a0d79..000000000 --- a/builder/yandex/ssh.go +++ /dev/null @@ -1,19 +0,0 @@ -package yandex - -import ( - "log" - - "github.com/hashicorp/packer/helper/multistep" -) - -func commHost(host string) func(multistep.StateBag) (string, error) { - return func(state multistep.StateBag) (string, error) { - if host != "" { - log.Printf("Using ssh_host value: %s", host) - return host, nil - } - - ipAddress := state.Get("instance_ip").(string) - return ipAddress, nil - } -}