builder/amazon: various fixes (minor) to get things going
This commit is contained in:
parent
dc8c94890a
commit
8f6ecfd9e3
|
@ -48,7 +48,9 @@ func (s *StepGetPassword) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
ui.Say("Waiting for auto-generated password for instance...")
|
ui.Say("Waiting for auto-generated password for instance...")
|
||||||
ui.Message(
|
ui.Message(
|
||||||
"It is normal for this process to take up to 15 minutes,\n" +
|
"It is normal for this process to take up to 15 minutes,\n" +
|
||||||
"but it usually takes around 5. Please wait.")
|
"but it usually takes around 5. Please wait. After the\n" +
|
||||||
|
"password is read, it will printed out below. Since it should\n" +
|
||||||
|
"be a temporary password, this should be a minimal security risk.")
|
||||||
password, err = s.waitForPassword(state, cancel)
|
password, err = s.waitForPassword(state, cancel)
|
||||||
waitDone <- true
|
waitDone <- true
|
||||||
}()
|
}()
|
||||||
|
@ -66,7 +68,7 @@ WaitLoop:
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Message("Password retrieved!")
|
ui.Message(fmt.Sprintf(" \nPassword retrieved: %s", password))
|
||||||
s.Comm.WinRMPassword = password
|
s.Comm.WinRMPassword = password
|
||||||
break WaitLoop
|
break WaitLoop
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
|
@ -121,6 +123,8 @@ func (s *StepGetPassword) waitForPassword(state multistep.StateBag, cancel <-cha
|
||||||
|
|
||||||
return decryptedPassword, nil
|
return decryptedPassword, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] Password is blank, will retry...")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -53,7 +54,14 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test if it is encoded already, and if not, encode it
|
||||||
|
if _, err := base64.StdEncoding.DecodeString(string(contents)); err != nil {
|
||||||
|
log.Printf("[DEBUG] base64 encoding user data...")
|
||||||
|
contents = []byte(base64.StdEncoding.EncodeToString(contents))
|
||||||
|
}
|
||||||
|
|
||||||
userData = string(contents)
|
userData = string(contents)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Say("Launching a source AWS instance...")
|
ui.Say("Launching a source AWS instance...")
|
||||||
|
|
|
@ -9,12 +9,13 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"github.com/mitchellh/packer/common/uuid"
|
"github.com/mitchellh/packer/common/uuid"
|
||||||
|
"github.com/mitchellh/packer/helper/communicator"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StepSecurityGroup struct {
|
type StepSecurityGroup struct {
|
||||||
|
CommConfig *communicator.Config
|
||||||
SecurityGroupIds []string
|
SecurityGroupIds []string
|
||||||
SSHPort int
|
|
||||||
VpcId string
|
VpcId string
|
||||||
|
|
||||||
createdGroupId string
|
createdGroupId string
|
||||||
|
@ -30,8 +31,9 @@ func (s *StepSecurityGroup) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.SSHPort == 0 {
|
port := s.CommConfig.Port()
|
||||||
panic("SSHPort must be set to a non-zero value.")
|
if port == 0 {
|
||||||
|
panic("port must be set to a non-zero value.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the group
|
// Create the group
|
||||||
|
@ -57,15 +59,17 @@ func (s *StepSecurityGroup) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
req := &ec2.AuthorizeSecurityGroupIngressInput{
|
req := &ec2.AuthorizeSecurityGroupIngressInput{
|
||||||
GroupID: groupResp.GroupID,
|
GroupID: groupResp.GroupID,
|
||||||
IPProtocol: aws.String("tcp"),
|
IPProtocol: aws.String("tcp"),
|
||||||
FromPort: aws.Long(int64(s.SSHPort)),
|
FromPort: aws.Long(int64(port)),
|
||||||
ToPort: aws.Long(int64(s.SSHPort)),
|
ToPort: aws.Long(int64(port)),
|
||||||
CIDRIP: aws.String("0.0.0.0/0"),
|
CIDRIP: aws.String("0.0.0.0/0"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// We loop and retry this a few times because sometimes the security
|
// We loop and retry this a few times because sometimes the security
|
||||||
// group isn't available immediately because AWS resources are eventaully
|
// group isn't available immediately because AWS resources are eventaully
|
||||||
// consistent.
|
// consistent.
|
||||||
ui.Say("Authorizing SSH access on the temporary security group...")
|
ui.Say(fmt.Sprintf(
|
||||||
|
"Authorizing access to port %d the temporary security group...",
|
||||||
|
port))
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
_, err = ec2conn.AuthorizeSecurityGroupIngress(req)
|
_, err = ec2conn.AuthorizeSecurityGroupIngress(req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -94,7 +94,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
},
|
},
|
||||||
&awscommon.StepSecurityGroup{
|
&awscommon.StepSecurityGroup{
|
||||||
SecurityGroupIds: b.config.SecurityGroupIds,
|
SecurityGroupIds: b.config.SecurityGroupIds,
|
||||||
SSHPort: b.config.RunConfig.Comm.SSHPort,
|
CommConfig: &b.config.RunConfig.Comm,
|
||||||
VpcId: b.config.VpcId,
|
VpcId: b.config.VpcId,
|
||||||
},
|
},
|
||||||
&awscommon.StepRunSourceInstance{
|
&awscommon.StepRunSourceInstance{
|
||||||
|
|
|
@ -179,8 +179,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKey,
|
PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKey,
|
||||||
},
|
},
|
||||||
&awscommon.StepSecurityGroup{
|
&awscommon.StepSecurityGroup{
|
||||||
|
CommConfig: &b.config.RunConfig.Comm,
|
||||||
SecurityGroupIds: b.config.SecurityGroupIds,
|
SecurityGroupIds: b.config.SecurityGroupIds,
|
||||||
SSHPort: b.config.RunConfig.Comm.SSHPort,
|
|
||||||
VpcId: b.config.VpcId,
|
VpcId: b.config.VpcId,
|
||||||
},
|
},
|
||||||
&awscommon.StepRunSourceInstance{
|
&awscommon.StepRunSourceInstance{
|
||||||
|
|
|
@ -31,6 +31,18 @@ type Config struct {
|
||||||
WinRMTimeout time.Duration `mapstructure:"winrm_timeout"`
|
WinRMTimeout time.Duration `mapstructure:"winrm_timeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Port returns the port that will be used for access based on config.
|
||||||
|
func (c *Config) Port() int {
|
||||||
|
switch c.Type {
|
||||||
|
case "ssh":
|
||||||
|
return c.SSHPort
|
||||||
|
case "winrm":
|
||||||
|
return c.WinRMPort
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) Prepare(ctx *interpolate.Context) []error {
|
func (c *Config) Prepare(ctx *interpolate.Context) []error {
|
||||||
if c.Type == "" {
|
if c.Type == "" {
|
||||||
c.Type = "ssh"
|
c.Type = "ssh"
|
||||||
|
|
Loading…
Reference in New Issue