From 0c787ec9df19a69f3968835c4f138c62b654a582 Mon Sep 17 00:00:00 2001 From: John Davies-Colley Date: Tue, 28 Nov 2017 11:46:01 +1300 Subject: [PATCH] =?UTF-8?q?Valadating=20early=20=E2=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builder/amazon/common/run_config.go | 13 +++++++++++++ builder/amazon/common/ssh.go | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index 48f8337f8..7e523740a 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -76,11 +76,24 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { c.RunTags = make(map[string]string) } + if c.SSHPrivateIp && c.SSHInterface { + errs = append(errs, errors.New("ssh_interface and ssh_private_ip should not both be specified")) + } + // Legacy configurable if c.SSHPrivateIp { c.SSHInterface = "private_ip" } + // Valadating ssh_interface + if c.SSHInterface != "public_ip" || + c.SSHInterface != "private_ip" || + c.SSHInterface != "public_dns" || + c.SSHInterface != "private_dns" || + c.SSHInterface != "" { + errs = append(errs, errors.New("Unknown interface type: %s", SSHInterface)) + } + // Validation errs := c.Comm.Prepare(ctx) if c.SSHKeyPairName != "" { diff --git a/builder/amazon/common/ssh.go b/builder/amazon/common/ssh.go index 34fb64ce1..be414a8a0 100644 --- a/builder/amazon/common/ssh.go +++ b/builder/amazon/common/ssh.go @@ -51,7 +51,7 @@ func SSHHost(e ec2Describer, sshInterface string) func(multistep.StateBag) (stri host = *i.PrivateDnsName } default: - return "", fmt.Errorf("unknown interface type: %s", sshInterface) + panic(fmt.Sprintf("Unknown interface type: %s", sshInterface)) } } else if i.VpcId != nil && *i.VpcId != "" { if i.PublicIpAddress != nil && *i.PublicIpAddress != "" {