Add auto discovery of AZ based on the subnet
This commit is contained in:
parent
1b07d7eb5e
commit
a08725f7c5
|
@ -165,6 +165,17 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
|
|
||||||
ec2conn := ec2.New(auth, region)
|
ec2conn := ec2.New(auth, region)
|
||||||
|
|
||||||
|
// If the subnet is specified but not the AZ, try to determine the AZ automatically
|
||||||
|
if b.config.SubnetId != "" && b.config.AvailabilityZone == "" {
|
||||||
|
log.Printf("[INFO] Finding AZ for the given subnet '%s'", b.config.SubnetId)
|
||||||
|
resp, err := ec2conn.DescribeSubnets([]string{b.config.SubnetId}, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
b.config.AvailabilityZone = resp.Subnets[0].AvailabilityZone
|
||||||
|
log.Printf("[INFO] AZ found: '%s'", b.config.AvailabilityZone)
|
||||||
|
}
|
||||||
|
|
||||||
wrappedCommand := func(command string) (string, error) {
|
wrappedCommand := func(command string) (string, error) {
|
||||||
return b.config.tpl.Process(
|
return b.config.tpl.Process(
|
||||||
b.config.CommandWrapper, &wrappedCommandTemplate{
|
b.config.CommandWrapper, &wrappedCommandTemplate{
|
||||||
|
|
|
@ -75,6 +75,17 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
|
|
||||||
ec2conn := ec2.New(auth, region)
|
ec2conn := ec2.New(auth, region)
|
||||||
|
|
||||||
|
// If the subnet is specified but not the AZ, try to determine the AZ automatically
|
||||||
|
if b.config.SubnetId != "" && b.config.AvailabilityZone == "" {
|
||||||
|
log.Printf("[INFO] Finding AZ for the given subnet '%s'", b.config.SubnetId)
|
||||||
|
resp, err := ec2conn.DescribeSubnets([]string{b.config.SubnetId}, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
b.config.AvailabilityZone = resp.Subnets[0].AvailabilityZone
|
||||||
|
log.Printf("[INFO] AZ found: '%s'", b.config.AvailabilityZone)
|
||||||
|
}
|
||||||
|
|
||||||
// Setup the state bag and initial state for the steps
|
// Setup the state bag and initial state for the steps
|
||||||
state := new(multistep.BasicStateBag)
|
state := new(multistep.BasicStateBag)
|
||||||
state.Put("config", b.config)
|
state.Put("config", b.config)
|
||||||
|
|
|
@ -180,6 +180,17 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
|
|
||||||
ec2conn := ec2.New(auth, region)
|
ec2conn := ec2.New(auth, region)
|
||||||
|
|
||||||
|
// If the subnet is specified but not the AZ, try to determine the AZ automatically
|
||||||
|
if b.config.SubnetId != "" && b.config.AvailabilityZone == "" {
|
||||||
|
log.Printf("[INFO] Finding AZ for the given subnet '%s'", b.config.SubnetId)
|
||||||
|
resp, err := ec2conn.DescribeSubnets([]string{b.config.SubnetId}, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
b.config.AvailabilityZone = resp.Subnets[0].AvailabilityZone
|
||||||
|
log.Printf("[INFO] AZ found: '%s'", b.config.AvailabilityZone)
|
||||||
|
}
|
||||||
|
|
||||||
// Setup the state bag and initial state for the steps
|
// Setup the state bag and initial state for the steps
|
||||||
state := new(multistep.BasicStateBag)
|
state := new(multistep.BasicStateBag)
|
||||||
state.Put("config", &b.config)
|
state.Put("config", &b.config)
|
||||||
|
|
Loading…
Reference in New Issue