From 0cbd3ff0f3c8b8b56479e70b8031e519c8055677 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 26 Sep 2019 12:30:04 -0700 Subject: [PATCH] make sure amazon builders respect ssh_host option --- builder/amazon/common/ssh.go | 9 +++++++-- builder/amazon/ebs/builder.go | 4 +++- builder/amazon/ebssurrogate/builder.go | 4 +++- builder/amazon/ebsvolume/builder.go | 4 +++- builder/amazon/instance/builder.go | 4 +++- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/builder/amazon/common/ssh.go b/builder/amazon/common/ssh.go index 713f88629..f085a1dca 100644 --- a/builder/amazon/common/ssh.go +++ b/builder/amazon/common/ssh.go @@ -3,6 +3,7 @@ package common import ( "errors" "fmt" + "log" "time" "github.com/aws/aws-sdk-go/service/ec2" @@ -20,12 +21,16 @@ var ( // SSHHost returns a function that can be given to the SSH communicator // for determining the SSH address based on the instance DNS name. -func SSHHost(e ec2Describer, sshInterface string) func(multistep.StateBag) (string, error) { +func SSHHost(e ec2Describer, sshInterface string, 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 + } + const tries = 2 // <= with current structure to check result of describing `tries` times for j := 0; j <= tries; j++ { - var host string i := state.Get("instance").(*ec2.Instance) if sshInterface != "" { switch sshInterface { diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index dd87f5d4e..2cbcbcbf4 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -231,7 +231,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack Config: &b.config.RunConfig.Comm, Host: awscommon.SSHHost( ec2conn, - b.config.SSHInterface), + b.config.SSHInterface, + b.config.Comm.SSHHost, + ), SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, &common.StepProvision{}, diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index ce4b9433f..f1e2c8122 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -272,7 +272,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack Config: &b.config.RunConfig.Comm, Host: awscommon.SSHHost( ec2conn, - b.config.SSHInterface), + b.config.SSHInterface, + b.config.Comm.SSHHost, + ), SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, &common.StepProvision{}, diff --git a/builder/amazon/ebsvolume/builder.go b/builder/amazon/ebsvolume/builder.go index 342f1b9aa..a26a7ff85 100644 --- a/builder/amazon/ebsvolume/builder.go +++ b/builder/amazon/ebsvolume/builder.go @@ -239,7 +239,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack Config: &b.config.RunConfig.Comm, Host: awscommon.SSHHost( ec2conn, - b.config.SSHInterface), + b.config.SSHInterface, + b.config.Comm.SSHHost, + ), SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, &common.StepProvision{}, diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index d40a69600..bcdb00d91 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -324,7 +324,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack Config: &b.config.RunConfig.Comm, Host: awscommon.SSHHost( ec2conn, - b.config.SSHInterface), + b.config.SSHInterface, + b.config.Comm.SSHHost, + ), SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, &common.StepProvision{},