provider/aws: fixing instance for EC2-VPC /cc:@pearkes

This commit is contained in:
Armon Dadgar 2014-07-28 12:47:40 -04:00
parent 0828e0528d
commit c8d5ea4d9d
1 changed files with 20 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"log"
"strconv"
"strings"
"time"
"github.com/hashicorp/terraform/flatmap"
@ -263,10 +264,28 @@ func resource_aws_instance_update_state(
s.Attributes["subnet_id"] = instance.SubnetId
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
sgs := make([]string, len(instance.SecurityGroups))
for i, sg := range instance.SecurityGroups {
if instance.SubnetId != "" {
if instance.SubnetId != "" && useID {
sgs[i] = sg.Id
} else {
sgs[i] = sg.Name