provider/aws: fixing instance for EC2-VPC /cc:@pearkes
This commit is contained in:
parent
0828e0528d
commit
c8d5ea4d9d
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/flatmap"
|
"github.com/hashicorp/terraform/flatmap"
|
||||||
|
@ -263,10 +264,28 @@ func resource_aws_instance_update_state(
|
||||||
s.Attributes["subnet_id"] = instance.SubnetId
|
s.Attributes["subnet_id"] = instance.SubnetId
|
||||||
s.Dependencies = nil
|
s.Dependencies = nil
|
||||||
|
|
||||||
|
// Extract the existing security groups
|
||||||
|
useID := false
|
||||||
|
if raw := flatmap.Expand(s.Attributes, "security_groups"); raw != nil {
|
||||||
|
if sgs, ok := raw.([]interface{}); ok {
|
||||||
|
for _, sg := range sgs {
|
||||||
|
str, ok := sg.(string)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(str, "sg-") {
|
||||||
|
useID = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Build up the security groups
|
// Build up the security groups
|
||||||
sgs := make([]string, len(instance.SecurityGroups))
|
sgs := make([]string, len(instance.SecurityGroups))
|
||||||
for i, sg := range instance.SecurityGroups {
|
for i, sg := range instance.SecurityGroups {
|
||||||
if instance.SubnetId != "" {
|
if instance.SubnetId != "" && useID {
|
||||||
sgs[i] = sg.Id
|
sgs[i] = sg.Id
|
||||||
} else {
|
} else {
|
||||||
sgs[i] = sg.Name
|
sgs[i] = sg.Name
|
||||||
|
|
Loading…
Reference in New Issue