Fix issue with Network interfaces and an instance-level security groups (#1188)
This commit is contained in:
parent
9654f2ff3a
commit
749db242f4
|
@ -292,6 +292,17 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
subnet, hasSubnet := d.GetOk("subnet_id")
|
subnet, hasSubnet := d.GetOk("subnet_id")
|
||||||
subnetID := subnet.(string)
|
subnetID := subnet.(string)
|
||||||
|
|
||||||
|
var groups []string
|
||||||
|
if v := d.Get("security_groups"); v != nil {
|
||||||
|
// Security group names.
|
||||||
|
// For a nondefault VPC, you must use security group IDs instead.
|
||||||
|
// See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html
|
||||||
|
for _, v := range v.(*schema.Set).List() {
|
||||||
|
str := v.(string)
|
||||||
|
groups = append(groups, str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if hasSubnet && associatePublicIPAddress {
|
if hasSubnet && associatePublicIPAddress {
|
||||||
// If we have a non-default VPC / Subnet specified, we can flag
|
// If we have a non-default VPC / Subnet specified, we can flag
|
||||||
// AssociatePublicIpAddress to get a Public IP assigned. By default these are not provided.
|
// AssociatePublicIpAddress to get a Public IP assigned. By default these are not provided.
|
||||||
|
@ -310,6 +321,10 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
ni.PrivateIPAddress = aws.String(v.(string))
|
ni.PrivateIPAddress = aws.String(v.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(groups) > 0 {
|
||||||
|
ni.Groups = groups
|
||||||
|
}
|
||||||
|
|
||||||
runOpts.NetworkInterfaces = []ec2.InstanceNetworkInterfaceSpecification{ni}
|
runOpts.NetworkInterfaces = []ec2.InstanceNetworkInterfaceSpecification{ni}
|
||||||
} else {
|
} else {
|
||||||
if subnetID != "" {
|
if subnetID != "" {
|
||||||
|
@ -319,21 +334,6 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
if v, ok := d.GetOk("private_ip"); ok {
|
if v, ok := d.GetOk("private_ip"); ok {
|
||||||
runOpts.PrivateIPAddress = aws.String(v.(string))
|
runOpts.PrivateIPAddress = aws.String(v.(string))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if v, ok := d.GetOk("key_name"); ok {
|
|
||||||
runOpts.KeyName = aws.String(v.(string))
|
|
||||||
}
|
|
||||||
|
|
||||||
if v := d.Get("security_groups"); v != nil {
|
|
||||||
// Security group names.
|
|
||||||
// For a nondefault VPC, you must use security group IDs instead.
|
|
||||||
// See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html
|
|
||||||
var groups []string
|
|
||||||
for _, v := range v.(*schema.Set).List() {
|
|
||||||
str := v.(string)
|
|
||||||
groups = append(groups, str)
|
|
||||||
}
|
|
||||||
if runOpts.SubnetID != nil &&
|
if runOpts.SubnetID != nil &&
|
||||||
*runOpts.SubnetID != "" {
|
*runOpts.SubnetID != "" {
|
||||||
runOpts.SecurityGroupIDs = groups
|
runOpts.SecurityGroupIDs = groups
|
||||||
|
@ -342,6 +342,10 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("key_name"); ok {
|
||||||
|
runOpts.KeyName = aws.String(v.(string))
|
||||||
|
}
|
||||||
|
|
||||||
blockDevices := make([]interface{}, 0)
|
blockDevices := make([]interface{}, 0)
|
||||||
|
|
||||||
if v := d.Get("block_device"); v != nil {
|
if v := d.Get("block_device"); v != nil {
|
||||||
|
|
Loading…
Reference in New Issue