From 707ec675b2d64cf16cade5e16c89b5d32fcf61f1 Mon Sep 17 00:00:00 2001 From: John Davies-Colley Date: Wed, 22 Nov 2017 15:49:38 +1300 Subject: [PATCH 1/8] =?UTF-8?q?ssh=20interface=20for=20amazon=20builders?= =?UTF-8?q?=20=F0=9F=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builder/amazon/common/run_config.go | 6 +++ builder/amazon/common/ssh.go | 31 ++++++++++--- builder/amazon/common/ssh_test.go | 60 +++++++++++++++----------- builder/amazon/ebs/builder.go | 2 +- builder/amazon/ebssurrogate/builder.go | 2 +- builder/amazon/ebsvolume/builder.go | 2 +- builder/amazon/instance/builder.go | 2 +- 7 files changed, 71 insertions(+), 34 deletions(-) diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index 73970e59e..8b605392b 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -54,6 +54,7 @@ type RunConfig struct { Comm communicator.Config `mapstructure:",squash"` SSHKeyPairName string `mapstructure:"ssh_keypair_name"` SSHPrivateIp bool `mapstructure:"ssh_private_ip"` + SSHInterface string `mapstructure:"ssh_interface` } func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { @@ -75,6 +76,11 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { c.RunTags = make(map[string]string) } + // Legacy configurable + if c.SSHPrivateIp { + c.SSHInterface = "private_ip" + } + // Validation errs := c.Comm.Prepare(ctx) if c.SSHKeyPairName != "" { diff --git a/builder/amazon/common/ssh.go b/builder/amazon/common/ssh.go index c451bbf96..34fb64ce1 100644 --- a/builder/amazon/common/ssh.go +++ b/builder/amazon/common/ssh.go @@ -25,21 +25,40 @@ 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, private bool) func(multistep.StateBag) (string, error) { +func SSHHost(e ec2Describer, sshInterface string) func(multistep.StateBag) (string, error) { return func(state multistep.StateBag) (string, error) { 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 i.VpcId != nil && *i.VpcId != "" { - if i.PublicIpAddress != nil && *i.PublicIpAddress != "" && !private { + if sshInterface != "" { + switch sshInterface { + case "public_ip": + if i.PublicIpAddress != nil { + host = *i.PublicIpAddress + } + case "private_ip": + if i.PrivateIpAddress != nil { + host = *i.PrivateIpAddress + } + case "public_dns": + if i.PublicDnsName != nil { + host = *i.PublicDnsName + } + case "private_dns": + if i.PrivateDnsName != nil { + host = *i.PrivateDnsName + } + default: + return "", fmt.Errorf("unknown interface type: %s", sshInterface) + } + } else if i.VpcId != nil && *i.VpcId != "" { + if i.PublicIpAddress != nil && *i.PublicIpAddress != "" { host = *i.PublicIpAddress } else if i.PrivateIpAddress != nil && *i.PrivateIpAddress != "" { host = *i.PrivateIpAddress } - } else if private && i.PrivateIpAddress != nil && *i.PrivateIpAddress != "" { - host = *i.PrivateIpAddress } else if i.PublicDnsName != nil && *i.PublicDnsName != "" { host = *i.PublicDnsName } @@ -63,7 +82,7 @@ func SSHHost(e ec2Describer, private bool) func(multistep.StateBag) (string, err time.Sleep(sshHostSleepDuration) } - return "", errors.New("couldn't determine IP address for instance") + return "", errors.New("couldn't determine address for instance") } } diff --git a/builder/amazon/common/ssh_test.go b/builder/amazon/common/ssh_test.go index 9f1d4a53e..e39088e67 100644 --- a/builder/amazon/common/ssh_test.go +++ b/builder/amazon/common/ssh_test.go @@ -9,9 +9,10 @@ import ( ) const ( - privateIP = "10.0.0.1" - publicIP = "192.168.1.1" - publicDNS = "public.dns.test" + privateIP = "10.0.0.1" + publicIP = "192.168.1.1" + privateDNS = "private.dns.test" + publicDNS = "public.dns.test" ) func TestSSHHost(t *testing.T) { @@ -20,44 +21,54 @@ func TestSSHHost(t *testing.T) { sshHostSleepDuration = 0 var cases = []struct { - allowTries int - vpcId string - private bool + allowTries int + vpcId string + sshInterface string ok bool wantHost string }{ - {1, "", false, true, publicDNS}, - {1, "", true, true, privateIP}, - {1, "vpc-id", false, true, publicIP}, - {1, "vpc-id", true, true, privateIP}, - {2, "", false, true, publicDNS}, - {2, "", true, true, privateIP}, - {2, "vpc-id", false, true, publicIP}, - {2, "vpc-id", true, true, privateIP}, - {3, "", false, false, ""}, - {3, "", true, false, ""}, - {3, "vpc-id", false, false, ""}, - {3, "vpc-id", true, false, ""}, + {1, "", "", true, publicDNS}, + {1, "", "private_ip", true, privateIP}, + {1, "vpc-id", "", true, publicIP}, + {1, "vpc-id", "private_ip", true, privateIP}, + {1, "vpc-id", "private_dns", true, privateDNS}, + {1, "vpc-id", "public_dns", true, publicDNS}, + {1, "vpc-id", "public_ip", true, publicIP}, + {2, "", "", true, publicDNS}, + {2, "", "private_ip", true, privateIP}, + {2, "vpc-id", "", true, publicIP}, + {2, "vpc-id", "private_ip", true, privateIP}, + {2, "vpc-id", "private_dns", true, privateDNS}, + {2, "vpc-id", "public_dns", true, publicDNS}, + {2, "vpc-id", "public_ip", true, publicIP}, + {3, "", "", false, ""}, + {3, "", "private_ip", false, ""}, + {3, "vpc-id", "", false, ""}, + {3, "vpc-id", "private_ip", false, ""}, + {3, "vpc-id", "private_dns", false, ""}, + {3, "vpc-id", "public_dns", false, ""}, + {3, "vpc-id", "public_ip", false, ""}, } for _, c := range cases { - testSSHHost(t, c.allowTries, c.vpcId, c.private, c.ok, c.wantHost) + testSSHHost(t, c.allowTries, c.vpcId, c.sshInterface, c.ok, c.wantHost) } } -func testSSHHost(t *testing.T, allowTries int, vpcId string, private, ok bool, wantHost string) { - t.Logf("allowTries=%d vpcId=%s private=%t ok=%t wantHost=%q", allowTries, vpcId, private, ok, wantHost) +func testSSHHost(t *testing.T, allowTries int, vpcId string, sshInterface string, ok bool, wantHost string) { + t.Logf("allowTries=%d vpcId=%s sshInterface=%s ok=%t wantHost=%q", allowTries, vpcId, sshInterface, ok, wantHost) e := &fakeEC2Describer{ allowTries: allowTries, vpcId: vpcId, privateIP: privateIP, publicIP: publicIP, + privateDNS: privateDNS, publicDNS: publicDNS, } - f := SSHHost(e, private) + f := SSHHost(e, sshInterface) st := &multistep.BasicStateBag{} st.Put("instance", &ec2.Instance{ InstanceId: aws.String("instance-id"), @@ -85,8 +96,8 @@ type fakeEC2Describer struct { allowTries int tries int - vpcId string - privateIP, publicIP, publicDNS string + vpcId string + privateIP, publicIP, privateDNS, publicDNS string } func (d *fakeEC2Describer) DescribeInstances(in *ec2.DescribeInstancesInput) (*ec2.DescribeInstancesOutput, error) { @@ -104,6 +115,7 @@ func (d *fakeEC2Describer) DescribeInstances(in *ec2.DescribeInstancesInput) (*e instance.PublicIpAddress = aws.String(d.publicIP) instance.PrivateIpAddress = aws.String(d.privateIP) instance.PublicDnsName = aws.String(d.publicDNS) + instance.PrivateDnsName = aws.String(d.privateDNS) } out := &ec2.DescribeInstancesOutput{ diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 1cc346472..56757b826 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -193,7 +193,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Config: &b.config.RunConfig.Comm, Host: awscommon.SSHHost( ec2conn, - b.config.SSHPrivateIp), + b.config.SSHInterface), SSHConfig: awscommon.SSHConfig( b.config.RunConfig.Comm.SSHAgentAuth, b.config.RunConfig.Comm.SSHUsername, diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index 16e8367da..fec997816 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -204,7 +204,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Config: &b.config.RunConfig.Comm, Host: awscommon.SSHHost( ec2conn, - b.config.SSHPrivateIp), + b.config.SSHInterface), SSHConfig: awscommon.SSHConfig( b.config.RunConfig.Comm.SSHAgentAuth, b.config.RunConfig.Comm.SSHUsername, diff --git a/builder/amazon/ebsvolume/builder.go b/builder/amazon/ebsvolume/builder.go index ea3f74b61..6bd8927ee 100644 --- a/builder/amazon/ebsvolume/builder.go +++ b/builder/amazon/ebsvolume/builder.go @@ -181,7 +181,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Config: &b.config.RunConfig.Comm, Host: awscommon.SSHHost( ec2conn, - b.config.SSHPrivateIp), + b.config.SSHInterface), SSHConfig: awscommon.SSHConfig( b.config.RunConfig.Comm.SSHAgentAuth, b.config.RunConfig.Comm.SSHUsername, diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index 7cee44c09..220ee7b10 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -268,7 +268,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Config: &b.config.RunConfig.Comm, Host: awscommon.SSHHost( ec2conn, - b.config.SSHPrivateIp), + b.config.SSHInterface), SSHConfig: awscommon.SSHConfig( b.config.RunConfig.Comm.SSHAgentAuth, b.config.RunConfig.Comm.SSHUsername, From 7b03613649b4753a0aa281bcb169a1e296bc856b Mon Sep 17 00:00:00 2001 From: Henry Muru Paenga Date: Wed, 22 Nov 2017 15:52:22 +1300 Subject: [PATCH 2/8] Update docs with ssh_interface --- website/source/docs/builders/amazon-ebs.html.md | 13 ++++++++++--- .../docs/builders/amazon-ebssurrogate.html.md | 11 +++++++++-- .../source/docs/builders/amazon-ebsvolume.html.md | 9 ++++++++- .../source/docs/builders/amazon-instance.html.md | 11 +++++++++-- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/website/source/docs/builders/amazon-ebs.html.md b/website/source/docs/builders/amazon-ebs.html.md index c11525dd0..4385a754a 100644 --- a/website/source/docs/builders/amazon-ebs.html.md +++ b/website/source/docs/builders/amazon-ebs.html.md @@ -237,7 +237,7 @@ builder. - `temporary_security_group_source_cidr` (string) - An IPv4 CIDR block to be authorized access to the instance, when packer is creating a temporary security group. - The default is `0.0.0.0/0` (ie, allow any IPv4 source). This is only used + The default is `0.0.0.0/0` (ie, allow any IPv4 source). This is only used when `security_group_id` or `security_group_ids` is not specified. - `shutdown_behavior` (string) - Automatically terminate instances on shutdown @@ -328,8 +328,15 @@ builder. in AWS with the source instance, set the `ssh_keypair_name` field to the name of the key pair. -- `ssh_private_ip` (boolean) - If true, then SSH will always use the private - IP if available. Also works for WinRM. +- `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private + IP if available. Also works for WinRM. Overrides `ssh_interface`. + +- `ssh_interface` (string) - One of `PublicIpAddress`, `PrivateIpAddress`, + `PublicDnsName` or `PrivateDnsName`. If set, either the public IP address, + private IP address, public DNS name or private DNS name will used as the host for SSH. + The default behaviour if inside a VPC is to use the public IP address if available, + otherwise the private IP address will be used. If not in a VPC the public DNS name + will be used. - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is diff --git a/website/source/docs/builders/amazon-ebssurrogate.html.md b/website/source/docs/builders/amazon-ebssurrogate.html.md index c044fc350..30b19ad6b 100644 --- a/website/source/docs/builders/amazon-ebssurrogate.html.md +++ b/website/source/docs/builders/amazon-ebssurrogate.html.md @@ -321,8 +321,15 @@ builder. in AWS with the source instance, set the `ssh_keypair_name` field to the name of the key pair. -- `ssh_private_ip` (boolean) - If true, then SSH will always use the private - IP if available. +- `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private + IP if available. Also works for WinRM. Overrides `ssh_interface`. + +- `ssh_interface` (string) - One of `PublicIpAddress`, `PrivateIpAddress`, + `PublicDnsName` or `PrivateDnsName`. If set, either the public IP address, + private IP address, public DNS name or private DNS name will used as the host for SSH. + The default behaviour if inside a VPC is to use the public IP address if available, + otherwise the private IP address will be used. If not in a VPC the public DNS name + will be used. - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is diff --git a/website/source/docs/builders/amazon-ebsvolume.html.md b/website/source/docs/builders/amazon-ebsvolume.html.md index 125064626..cc6cf39de 100644 --- a/website/source/docs/builders/amazon-ebsvolume.html.md +++ b/website/source/docs/builders/amazon-ebsvolume.html.md @@ -226,7 +226,14 @@ builder. must be specified with this. - `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private - IP if available. Also works for WinRM. + IP if available. Also works for WinRM. Overrides `ssh_interface`. + +- `ssh_interface` (string) - One of `PublicIpAddress`, `PrivateIpAddress`, + `PublicDnsName` or `PrivateDnsName`. If set, either the public IP address, + private IP address, public DNS name or private DNS name will used as the host for SSH. + The default behaviour if inside a VPC is to use the public IP address if available, + otherwise the private IP address will be used. If not in a VPC the public DNS name + will be used. - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is diff --git a/website/source/docs/builders/amazon-instance.html.md b/website/source/docs/builders/amazon-instance.html.md index 95a1bc007..93975fb88 100644 --- a/website/source/docs/builders/amazon-instance.html.md +++ b/website/source/docs/builders/amazon-instance.html.md @@ -329,8 +329,15 @@ builder. in AWS with the source instance, set the `ssh_keypair_name` field to the name of the key pair. -- `ssh_private_ip` (boolean) - If true, then SSH will always use the private - IP if available. Also works for WinRM. +- `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private + IP if available. Also works for WinRM. Overrides `ssh_interface`. + +- `ssh_interface` (string) - One of `PublicIpAddress`, `PrivateIpAddress`, + `PublicDnsName` or `PrivateDnsName`. If set, either the public IP address, + private IP address, public DNS name or private DNS name will used as the host for SSH. + The default behaviour if inside a VPC is to use the public IP address if available, + otherwise the private IP address will be used. If not in a VPC the public DNS name + will be used. - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is From 75320440ec2e904faa885c1769bdd3343d04d436 Mon Sep 17 00:00:00 2001 From: John Davies-Colley Date: Wed, 22 Nov 2017 15:59:15 +1300 Subject: [PATCH 3/8] =?UTF-8?q?adding=20missing=20quote=20=F0=9F=99=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builder/amazon/common/run_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index 8b605392b..48f8337f8 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -54,7 +54,7 @@ type RunConfig struct { Comm communicator.Config `mapstructure:",squash"` SSHKeyPairName string `mapstructure:"ssh_keypair_name"` SSHPrivateIp bool `mapstructure:"ssh_private_ip"` - SSHInterface string `mapstructure:"ssh_interface` + SSHInterface string `mapstructure:"ssh_interface"` } func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { From d4f37ab5f69166eea0494c31fa731475a738b2b3 Mon Sep 17 00:00:00 2001 From: John Davies-Colley Date: Wed, 22 Nov 2017 17:15:46 +1300 Subject: [PATCH 4/8] =?UTF-8?q?changing=20config=20varibles=20name=20in=20?= =?UTF-8?q?docs=20to=20match=20names=20in=20code=20=E2=9A=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- website/source/docs/builders/amazon-ebs.html.md | 4 ++-- website/source/docs/builders/amazon-ebssurrogate.html.md | 4 ++-- website/source/docs/builders/amazon-ebsvolume.html.md | 4 ++-- website/source/docs/builders/amazon-instance.html.md | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/website/source/docs/builders/amazon-ebs.html.md b/website/source/docs/builders/amazon-ebs.html.md index 4385a754a..4d8c56a1e 100644 --- a/website/source/docs/builders/amazon-ebs.html.md +++ b/website/source/docs/builders/amazon-ebs.html.md @@ -331,8 +331,8 @@ builder. - `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private IP if available. Also works for WinRM. Overrides `ssh_interface`. -- `ssh_interface` (string) - One of `PublicIpAddress`, `PrivateIpAddress`, - `PublicDnsName` or `PrivateDnsName`. If set, either the public IP address, +- `ssh_interface` (string) - One of `public_ip`, `private_ip`, + `public_dns` or `private_dns`. If set, either the public IP address, private IP address, public DNS name or private DNS name will used as the host for SSH. The default behaviour if inside a VPC is to use the public IP address if available, otherwise the private IP address will be used. If not in a VPC the public DNS name diff --git a/website/source/docs/builders/amazon-ebssurrogate.html.md b/website/source/docs/builders/amazon-ebssurrogate.html.md index 30b19ad6b..acd976538 100644 --- a/website/source/docs/builders/amazon-ebssurrogate.html.md +++ b/website/source/docs/builders/amazon-ebssurrogate.html.md @@ -324,8 +324,8 @@ builder. - `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private IP if available. Also works for WinRM. Overrides `ssh_interface`. -- `ssh_interface` (string) - One of `PublicIpAddress`, `PrivateIpAddress`, - `PublicDnsName` or `PrivateDnsName`. If set, either the public IP address, +- `ssh_interface` (string) - One of `public_ip`, `private_ip`, + `public_dns` or `private_dns`. If set, either the public IP address, private IP address, public DNS name or private DNS name will used as the host for SSH. The default behaviour if inside a VPC is to use the public IP address if available, otherwise the private IP address will be used. If not in a VPC the public DNS name diff --git a/website/source/docs/builders/amazon-ebsvolume.html.md b/website/source/docs/builders/amazon-ebsvolume.html.md index cc6cf39de..b022c9e81 100644 --- a/website/source/docs/builders/amazon-ebsvolume.html.md +++ b/website/source/docs/builders/amazon-ebsvolume.html.md @@ -228,8 +228,8 @@ builder. - `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private IP if available. Also works for WinRM. Overrides `ssh_interface`. -- `ssh_interface` (string) - One of `PublicIpAddress`, `PrivateIpAddress`, - `PublicDnsName` or `PrivateDnsName`. If set, either the public IP address, +- `ssh_interface` (string) - One of `public_ip`, `private_ip`, + `public_dns` or `private_dns`. If set, either the public IP address, private IP address, public DNS name or private DNS name will used as the host for SSH. The default behaviour if inside a VPC is to use the public IP address if available, otherwise the private IP address will be used. If not in a VPC the public DNS name diff --git a/website/source/docs/builders/amazon-instance.html.md b/website/source/docs/builders/amazon-instance.html.md index 93975fb88..8636b6a49 100644 --- a/website/source/docs/builders/amazon-instance.html.md +++ b/website/source/docs/builders/amazon-instance.html.md @@ -332,8 +332,8 @@ builder. - `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private IP if available. Also works for WinRM. Overrides `ssh_interface`. -- `ssh_interface` (string) - One of `PublicIpAddress`, `PrivateIpAddress`, - `PublicDnsName` or `PrivateDnsName`. If set, either the public IP address, +- `ssh_interface` (string) - One of `public_ip`, `private_ip`, + `public_dns` or `private_dns`. If set, either the public IP address, private IP address, public DNS name or private DNS name will used as the host for SSH. The default behaviour if inside a VPC is to use the public IP address if available, otherwise the private IP address will be used. If not in a VPC the public DNS name From 0c787ec9df19a69f3968835c4f138c62b654a582 Mon Sep 17 00:00:00 2001 From: John Davies-Colley Date: Tue, 28 Nov 2017 11:46:01 +1300 Subject: [PATCH 5/8] =?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 != "" { From 10aaa49bebf7edbb4c50005aa5b19d5d4f3d434d Mon Sep 17 00:00:00 2001 From: John Davies-Colley Date: Tue, 28 Nov 2017 14:26:55 +1300 Subject: [PATCH 6/8] =?UTF-8?q?fixing=20tests=20and=20funky=20logic=20?= =?UTF-8?q?=F0=9F=92=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builder/amazon/common/run_config.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index 7e523740a..4f20ed3b4 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -76,7 +76,9 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { c.RunTags = make(map[string]string) } - if c.SSHPrivateIp && c.SSHInterface { + // Validation + errs := c.Comm.Prepare(ctx) + if c.SSHPrivateIp && c.SSHInterface != "" { errs = append(errs, errors.New("ssh_interface and ssh_private_ip should not both be specified")) } @@ -86,16 +88,14 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { } // Valadating ssh_interface - if c.SSHInterface != "public_ip" || - c.SSHInterface != "private_ip" || - c.SSHInterface != "public_dns" || - c.SSHInterface != "private_dns" || + 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)) + errs = append(errs, errors.New(fmt.Sprintf("Unknown interface type: %s", c.SSHInterface))) } - // Validation - errs := c.Comm.Prepare(ctx) if c.SSHKeyPairName != "" { if c.Comm.Type == "winrm" && c.Comm.WinRMPassword == "" && c.Comm.SSHPrivateKey == "" { errs = append(errs, errors.New("A private_key_file must be provided to retrieve the winrm password when using ssh_keypair_name.")) From 92d1bdbdabb62cb4e029fc60c7292a64d404d8cf Mon Sep 17 00:00:00 2001 From: John Davies-Colley Date: Wed, 6 Dec 2017 16:50:54 +1300 Subject: [PATCH 7/8] =?UTF-8?q?docs=20change=20for=20deprecation=20and=20p?= =?UTF-8?q?roxy=20usage=20=E2=9C=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- website/source/docs/builders/amazon-ebs.html.md | 7 +++++-- website/source/docs/builders/amazon-ebssurrogate.html.md | 7 +++++-- website/source/docs/builders/amazon-ebsvolume.html.md | 7 +++++-- website/source/docs/builders/amazon-instance.html.md | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/website/source/docs/builders/amazon-ebs.html.md b/website/source/docs/builders/amazon-ebs.html.md index 4d8c56a1e..54782d9d4 100644 --- a/website/source/docs/builders/amazon-ebs.html.md +++ b/website/source/docs/builders/amazon-ebs.html.md @@ -328,8 +328,8 @@ builder. in AWS with the source instance, set the `ssh_keypair_name` field to the name of the key pair. -- `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private - IP if available. Also works for WinRM. Overrides `ssh_interface`. +- `ssh_private_ip` (boolean) - *Deprecated* use `ssh_interface` instead. If `true`, + then SSH will always use the private IP if available. Also works for WinRM. - `ssh_interface` (string) - One of `public_ip`, `private_ip`, `public_dns` or `private_dns`. If set, either the public IP address, @@ -338,6 +338,9 @@ builder. otherwise the private IP address will be used. If not in a VPC the public DNS name will be used. + If packer is configured for an outbound proxy. To configure WinRM traffic to bypass the proxy + `ssh_interface` can be set to `private_dns`. + - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is required if you are using an non-default VPC. diff --git a/website/source/docs/builders/amazon-ebssurrogate.html.md b/website/source/docs/builders/amazon-ebssurrogate.html.md index acd976538..998733e4a 100644 --- a/website/source/docs/builders/amazon-ebssurrogate.html.md +++ b/website/source/docs/builders/amazon-ebssurrogate.html.md @@ -321,8 +321,8 @@ builder. in AWS with the source instance, set the `ssh_keypair_name` field to the name of the key pair. -- `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private - IP if available. Also works for WinRM. Overrides `ssh_interface`. +- `ssh_private_ip` (boolean) - *Deprecated* use `ssh_interface` instead. If `true`, + then SSH will always use the private IP if available. Also works for WinRM. - `ssh_interface` (string) - One of `public_ip`, `private_ip`, `public_dns` or `private_dns`. If set, either the public IP address, @@ -331,6 +331,9 @@ builder. otherwise the private IP address will be used. If not in a VPC the public DNS name will be used. + If packer is configured for an outbound proxy. To configure WinRM traffic to bypass the proxy + `ssh_interface` can be set to `private_dns`. + - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is required if you are using an non-default VPC. diff --git a/website/source/docs/builders/amazon-ebsvolume.html.md b/website/source/docs/builders/amazon-ebsvolume.html.md index b022c9e81..a28398746 100644 --- a/website/source/docs/builders/amazon-ebsvolume.html.md +++ b/website/source/docs/builders/amazon-ebsvolume.html.md @@ -225,8 +225,8 @@ builder. [`ssh_private_key_file`](/docs/templates/communicator.html#ssh_private_key_file) must be specified with this. -- `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private - IP if available. Also works for WinRM. Overrides `ssh_interface`. +- `ssh_private_ip` (boolean) - *Deprecated* use `ssh_interface` instead. If `true`, + then SSH will always use the private IP if available. Also works for WinRM. - `ssh_interface` (string) - One of `public_ip`, `private_ip`, `public_dns` or `private_dns`. If set, either the public IP address, @@ -235,6 +235,9 @@ builder. otherwise the private IP address will be used. If not in a VPC the public DNS name will be used. + If packer is configured for an outbound proxy. To configure WinRM traffic to bypass the proxy + `ssh_interface` can be set to `private_dns`. + - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is required if you are using an non-default VPC. diff --git a/website/source/docs/builders/amazon-instance.html.md b/website/source/docs/builders/amazon-instance.html.md index 8636b6a49..9afd894c2 100644 --- a/website/source/docs/builders/amazon-instance.html.md +++ b/website/source/docs/builders/amazon-instance.html.md @@ -329,8 +329,8 @@ builder. in AWS with the source instance, set the `ssh_keypair_name` field to the name of the key pair. -- `ssh_private_ip` (boolean) - If `true`, then SSH will always use the private - IP if available. Also works for WinRM. Overrides `ssh_interface`. +- `ssh_private_ip` (boolean) - *Deprecated* use `ssh_interface` instead. If `true`, + then SSH will always use the private IP if available. Also works for WinRM. - `ssh_interface` (string) - One of `public_ip`, `private_ip`, `public_dns` or `private_dns`. If set, either the public IP address, @@ -339,6 +339,9 @@ builder. otherwise the private IP address will be used. If not in a VPC the public DNS name will be used. + If packer is configured for an outbound proxy. To configure WinRM traffic to bypass the proxy + `ssh_interface` can be set to `private_dns`. + - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is required if you are using an non-default VPC. From 76ac755ed98ed28154e38de0b13247e91bdef451 Mon Sep 17 00:00:00 2001 From: John Davies-Colley Date: Wed, 6 Dec 2017 17:13:02 +1300 Subject: [PATCH 8/8] =?UTF-8?q?fixing=20wording=20for=20proxy=20usage=20?= =?UTF-8?q?=F0=9F=91=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- website/source/docs/builders/amazon-ebs.html.md | 5 +++-- website/source/docs/builders/amazon-ebssurrogate.html.md | 5 +++-- website/source/docs/builders/amazon-ebsvolume.html.md | 5 +++-- website/source/docs/builders/amazon-instance.html.md | 7 ++++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/website/source/docs/builders/amazon-ebs.html.md b/website/source/docs/builders/amazon-ebs.html.md index 54782d9d4..c050cd070 100644 --- a/website/source/docs/builders/amazon-ebs.html.md +++ b/website/source/docs/builders/amazon-ebs.html.md @@ -338,8 +338,9 @@ builder. otherwise the private IP address will be used. If not in a VPC the public DNS name will be used. - If packer is configured for an outbound proxy. To configure WinRM traffic to bypass the proxy - `ssh_interface` can be set to `private_dns`. + Where Packer is configured for an outbound proxy but WinRM traffic should be direct + `ssh_interface` must be set to `private_dns` and `.compute.internal` included + in the `NO_PROXY` environment variable. - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is diff --git a/website/source/docs/builders/amazon-ebssurrogate.html.md b/website/source/docs/builders/amazon-ebssurrogate.html.md index 998733e4a..640710230 100644 --- a/website/source/docs/builders/amazon-ebssurrogate.html.md +++ b/website/source/docs/builders/amazon-ebssurrogate.html.md @@ -331,8 +331,9 @@ builder. otherwise the private IP address will be used. If not in a VPC the public DNS name will be used. - If packer is configured for an outbound proxy. To configure WinRM traffic to bypass the proxy - `ssh_interface` can be set to `private_dns`. + Where Packer is configured for an outbound proxy but WinRM traffic should be direct + `ssh_interface` must be set to `private_dns` and `.compute.internal` included + in the `NO_PROXY` environment variable. - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is diff --git a/website/source/docs/builders/amazon-ebsvolume.html.md b/website/source/docs/builders/amazon-ebsvolume.html.md index a28398746..2b92c6b44 100644 --- a/website/source/docs/builders/amazon-ebsvolume.html.md +++ b/website/source/docs/builders/amazon-ebsvolume.html.md @@ -235,8 +235,9 @@ builder. otherwise the private IP address will be used. If not in a VPC the public DNS name will be used. - If packer is configured for an outbound proxy. To configure WinRM traffic to bypass the proxy - `ssh_interface` can be set to `private_dns`. + Where Packer is configured for an outbound proxy but WinRM traffic should be direct + `ssh_interface` must be set to `private_dns` and `.compute.internal` included + in the `NO_PROXY` environment variable. - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is diff --git a/website/source/docs/builders/amazon-instance.html.md b/website/source/docs/builders/amazon-instance.html.md index 9afd894c2..198345ba7 100644 --- a/website/source/docs/builders/amazon-instance.html.md +++ b/website/source/docs/builders/amazon-instance.html.md @@ -329,7 +329,7 @@ builder. in AWS with the source instance, set the `ssh_keypair_name` field to the name of the key pair. -- `ssh_private_ip` (boolean) - *Deprecated* use `ssh_interface` instead. If `true`, +- `ssh_private_ip` (boolean) - *Deprecated* use `ssh_interface` instead. If `true`, then SSH will always use the private IP if available. Also works for WinRM. - `ssh_interface` (string) - One of `public_ip`, `private_ip`, @@ -339,8 +339,9 @@ builder. otherwise the private IP address will be used. If not in a VPC the public DNS name will be used. - If packer is configured for an outbound proxy. To configure WinRM traffic to bypass the proxy - `ssh_interface` can be set to `private_dns`. + Where Packer is configured for an outbound proxy but WinRM traffic should be direct + `ssh_interface` must be set to `private_dns` and `.compute.internal` included + in the `NO_PROXY` environment variable. - `subnet_id` (string) - If using VPC, the ID of the subnet, such as `subnet-12345def`, where Packer will launch the EC2 instance. This field is