Skip to content

Commit

Permalink
provider/aws: Support additional changes to security groups of instan…
Browse files Browse the repository at this point in the history
…ce without forcing new
  • Loading branch information
innossh committed Feb 21, 2016
1 parent 938ab99 commit 564dd36
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion builtin/providers/aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func resourceAwsInstance() *schema.Resource {
Type: schema.TypeSet,
Optional: true,
Computed: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
Expand Down Expand Up @@ -581,6 +580,28 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
}
}

if d.HasChange("security_groups") {
var groupIds []*string
if v := d.Get("security_groups").(*schema.Set); v.Len() > 0 {
resp, err := conn.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{
GroupNames: expandStringList(v.List()),
})
if err != nil {
return err
}
for _, v := range resp.SecurityGroups {
groupIds = append(groupIds, aws.String(*v.GroupId))
}
}
_, err := conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
InstanceId: aws.String(d.Id()),
Groups: groupIds,
})
if err != nil {
return err
}
}

if d.HasChange("vpc_security_group_ids") {
var groups []*string
if v := d.Get("vpc_security_group_ids").(*schema.Set); v.Len() > 0 {
Expand Down

1 comment on commit 564dd36

@cbarbour
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have been good if this had an issue attached to it. As far as I can tell, this change didn't appear in the changelog.

Please sign in to comment.