Merge pull request #4879 from thrashr888/thrashr888/fix4693

Fix issue 4693 - Derive vpc_id from subnet_id
This commit is contained in:
Matthew Hooker 2017-05-15 13:49:33 -07:00 committed by GitHub
commit 57d15432db
8 changed files with 55 additions and 26 deletions

View File

@ -89,15 +89,21 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
} }
ec2conn := ec2.New(session) ec2conn := ec2.New(session)
// If the subnet is specified but not the AZ, try to determine the AZ automatically // If the subnet is specified but not the VpcId or AZ, try to determine them automatically
if b.config.SubnetId != "" && b.config.AvailabilityZone == "" { if b.config.SubnetId != "" && (b.config.AvailabilityZone == "" || b.config.VpcId == "") {
log.Printf("[INFO] Finding AZ for the given subnet '%s'", b.config.SubnetId) log.Printf("[INFO] Finding AZ and VpcId for the given subnet '%s'", b.config.SubnetId)
resp, err := ec2conn.DescribeSubnets(&ec2.DescribeSubnetsInput{SubnetIds: []*string{&b.config.SubnetId}}) resp, err := ec2conn.DescribeSubnets(&ec2.DescribeSubnetsInput{SubnetIds: []*string{&b.config.SubnetId}})
if err != nil { if err != nil {
return nil, err return nil, err
} }
if b.config.AvailabilityZone == "" {
b.config.AvailabilityZone = *resp.Subnets[0].AvailabilityZone b.config.AvailabilityZone = *resp.Subnets[0].AvailabilityZone
log.Printf("[INFO] AZ found: '%s'", b.config.AvailabilityZone) log.Printf("[INFO] AvailabilityZone found: '%s'", b.config.AvailabilityZone)
}
if b.config.VpcId == "" {
b.config.VpcId = *resp.Subnets[0].VpcId
log.Printf("[INFO] VpcId found: '%s'", b.config.VpcId)
}
} }
// Setup the state bag and initial state for the steps // Setup the state bag and initial state for the steps

View File

@ -106,15 +106,21 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ec2conn := ec2.New(awsSession) ec2conn := ec2.New(awsSession)
// If the subnet is specified but not the AZ, try to determine the AZ automatically // If the subnet is specified but not the VpcId or AZ, try to determine them automatically
if b.config.SubnetId != "" && b.config.AvailabilityZone == "" { if b.config.SubnetId != "" && (b.config.AvailabilityZone == "" || b.config.VpcId == "") {
log.Printf("[INFO] Finding AZ for the given subnet '%s'", b.config.SubnetId) log.Printf("[INFO] Finding AZ and VpcId for the given subnet '%s'", b.config.SubnetId)
resp, err := ec2conn.DescribeSubnets(&ec2.DescribeSubnetsInput{SubnetIds: []*string{&b.config.SubnetId}}) resp, err := ec2conn.DescribeSubnets(&ec2.DescribeSubnetsInput{SubnetIds: []*string{&b.config.SubnetId}})
if err != nil { if err != nil {
return nil, err return nil, err
} }
if b.config.AvailabilityZone == "" {
b.config.AvailabilityZone = *resp.Subnets[0].AvailabilityZone b.config.AvailabilityZone = *resp.Subnets[0].AvailabilityZone
log.Printf("[INFO] AZ found: '%s'", b.config.AvailabilityZone) log.Printf("[INFO] AvailabilityZone found: '%s'", b.config.AvailabilityZone)
}
if b.config.VpcId == "" {
b.config.VpcId = *resp.Subnets[0].VpcId
log.Printf("[INFO] VpcId found: '%s'", b.config.VpcId)
}
} }
// Setup the state bag and initial state for the steps // Setup the state bag and initial state for the steps

View File

@ -84,15 +84,21 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ec2conn := ec2.New(session) ec2conn := ec2.New(session)
// If the subnet is specified but not the AZ, try to determine the AZ automatically // If the subnet is specified but not the VpcId or AZ, try to determine them automatically
if b.config.SubnetId != "" && b.config.AvailabilityZone == "" { if b.config.SubnetId != "" && (b.config.AvailabilityZone == "" || b.config.VpcId == "") {
log.Printf("[INFO] Finding AZ for the given subnet '%s'", b.config.SubnetId) log.Printf("[INFO] Finding AZ and VpcId for the given subnet '%s'", b.config.SubnetId)
resp, err := ec2conn.DescribeSubnets(&ec2.DescribeSubnetsInput{SubnetIds: []*string{&b.config.SubnetId}}) resp, err := ec2conn.DescribeSubnets(&ec2.DescribeSubnetsInput{SubnetIds: []*string{&b.config.SubnetId}})
if err != nil { if err != nil {
return nil, err return nil, err
} }
if b.config.AvailabilityZone == "" {
b.config.AvailabilityZone = *resp.Subnets[0].AvailabilityZone b.config.AvailabilityZone = *resp.Subnets[0].AvailabilityZone
log.Printf("[INFO] AZ found: '%s'", b.config.AvailabilityZone) log.Printf("[INFO] AvailabilityZone found: '%s'", b.config.AvailabilityZone)
}
if b.config.VpcId == "" {
b.config.VpcId = *resp.Subnets[0].VpcId
log.Printf("[INFO] VpcId found: '%s'", b.config.VpcId)
}
} }
// Setup the state bag and initial state for the steps // Setup the state bag and initial state for the steps

View File

@ -175,15 +175,21 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
} }
ec2conn := ec2.New(session) ec2conn := ec2.New(session)
// If the subnet is specified but not the AZ, try to determine the AZ automatically // If the subnet is specified but not the VpcId or AZ, try to determine them automatically
if b.config.SubnetId != "" && b.config.AvailabilityZone == "" { if b.config.SubnetId != "" && (b.config.AvailabilityZone == "" || b.config.VpcId == "") {
log.Printf("[INFO] Finding AZ for the given subnet '%s'", b.config.SubnetId) log.Printf("[INFO] Finding AZ and VpcId for the given subnet '%s'", b.config.SubnetId)
resp, err := ec2conn.DescribeSubnets(&ec2.DescribeSubnetsInput{SubnetIds: []*string{&b.config.SubnetId}}) resp, err := ec2conn.DescribeSubnets(&ec2.DescribeSubnetsInput{SubnetIds: []*string{&b.config.SubnetId}})
if err != nil { if err != nil {
return nil, err return nil, err
} }
if b.config.AvailabilityZone == "" {
b.config.AvailabilityZone = *resp.Subnets[0].AvailabilityZone b.config.AvailabilityZone = *resp.Subnets[0].AvailabilityZone
log.Printf("[INFO] AZ found: '%s'", b.config.AvailabilityZone) log.Printf("[INFO] AvailabilityZone found: '%s'", b.config.AvailabilityZone)
}
if b.config.VpcId == "" {
b.config.VpcId = *resp.Subnets[0].VpcId
log.Printf("[INFO] VpcId found: '%s'", b.config.VpcId)
}
} }
// Setup the state bag and initial state for the steps // Setup the state bag and initial state for the steps

View File

@ -328,7 +328,8 @@ builder.
- `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID - `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID
in order to create a temporary security group within the VPC. Requires `subnet_id` in order to create a temporary security group within the VPC. Requires `subnet_id`
to be set. to be set. If this field is left blank, Packer will try to get the VPC ID from the
`subnet_id`.
- `windows_password_timeout` (string) - The timeout for waiting for a Windows - `windows_password_timeout` (string) - The timeout for waiting for a Windows
password for Windows instances. Defaults to 20 minutes. Example value: `10m` password for Windows instances. Defaults to 20 minutes. Example value: `10m`

View File

@ -320,7 +320,8 @@ builder.
- `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID - `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID
in order to create a temporary security group within the VPC. Requires `subnet_id` in order to create a temporary security group within the VPC. Requires `subnet_id`
to be set. to be set. If this field is left blank, Packer will try to get the VPC ID from the
`subnet_id`.
- `windows_password_timeout` (string) - The timeout for waiting for a Windows - `windows_password_timeout` (string) - The timeout for waiting for a Windows
password for Windows instances. Defaults to 20 minutes. Example value: `10m` password for Windows instances. Defaults to 20 minutes. Example value: `10m`

View File

@ -220,7 +220,8 @@ builder.
- `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID - `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID
in order to create a temporary security group within the VPC. Requires `subnet_id` in order to create a temporary security group within the VPC. Requires `subnet_id`
to be set. to be set. If this field is left blank, Packer will try to get the VPC ID from the
`subnet_id`.
- `windows_password_timeout` (string) - The timeout for waiting for a Windows - `windows_password_timeout` (string) - The timeout for waiting for a Windows
password for Windows instances. Defaults to 20 minutes. Example value: `10m` password for Windows instances. Defaults to 20 minutes. Example value: `10m`

View File

@ -323,7 +323,9 @@ builder.
data when launching the instance. data when launching the instance.
- `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID - `vpc_id` (string) - If launching into a VPC subnet, Packer needs the VPC ID
in order to create a temporary security group within the VPC. in order to create a temporary security group within the VPC. Requires `subnet_id`
to be set. If this field is left blank, Packer will try to get the VPC ID from the
`subnet_id`.
- `x509_upload_path` (string) - The path on the remote machine where the X509 - `x509_upload_path` (string) - The path on the remote machine where the X509
certificate will be uploaded. This path must already exist and be writable. certificate will be uploaded. This path must already exist and be writable.