diff --git a/builtin/providers/aws/resource_aws_iam_group.go b/builtin/providers/aws/resource_aws_iam_group.go index 45defaaaf..c34137663 100644 --- a/builtin/providers/aws/resource_aws_iam_group.go +++ b/builtin/providers/aws/resource_aws_iam_group.go @@ -14,8 +14,7 @@ func resourceAwsIamGroup() *schema.Resource { return &schema.Resource{ Create: resourceAwsIamGroupCreate, Read: resourceAwsIamGroupRead, - // TODO - //Update: resourceAwsIamGroupUpdate, + Update: resourceAwsIamGroupUpdate, Delete: resourceAwsIamGroupDelete, Schema: map[string]*schema.Schema{ @@ -30,13 +29,11 @@ func resourceAwsIamGroup() *schema.Resource { "name": &schema.Schema{ Type: schema.TypeString, Required: true, - ForceNew: true, }, "path": &schema.Schema{ Type: schema.TypeString, Optional: true, Default: "/", - ForceNew: true, }, }, } @@ -45,9 +42,10 @@ func resourceAwsIamGroup() *schema.Resource { func resourceAwsIamGroupCreate(d *schema.ResourceData, meta interface{}) error { iamconn := meta.(*AWSClient).iamconn name := d.Get("name").(string) + path := d.Get("path").(string) request := &iam.CreateGroupInput{ - Path: aws.String(d.Get("path").(string)), + Path: aws.String(path), GroupName: aws.String(name), } @@ -60,9 +58,10 @@ func resourceAwsIamGroupCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsIamGroupRead(d *schema.ResourceData, meta interface{}) error { iamconn := meta.(*AWSClient).iamconn + name := d.Get("name").(string) request := &iam.GetGroupInput{ - GroupName: aws.String(d.Id()), + GroupName: aws.String(name), } getResp, err := iamconn.GetGroup(request) @@ -93,6 +92,30 @@ func resourceAwsIamGroupReadResult(d *schema.ResourceData, group *iam.Group) err return nil } +func resourceAwsIamGroupUpdate(d *schema.ResourceData, meta interface{}) error { + if d.HasChange("name") || d.HasChange("path") { + iamconn := meta.(*AWSClient).iamconn + on, nn := d.GetChange("name") + op, np := d.GetChange("path") + fmt.Println(on, nn, op, np) + request := &iam.UpdateGroupInput{ + GroupName: aws.String(on.(string)), + NewGroupName: aws.String(nn.(string)), + NewPath: aws.String(np.(string)), + } + _, err := iamconn.UpdateGroup(request) + if err != nil { + if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" { + d.SetId("") + return nil + } + return fmt.Errorf("Error updating IAM Group %s: %s", d.Id(), err) + } + return resourceAwsIamGroupRead(d, meta) + } + return nil +} + func resourceAwsIamGroupDelete(d *schema.ResourceData, meta interface{}) error { iamconn := meta.(*AWSClient).iamconn diff --git a/builtin/providers/aws/resource_aws_iam_group_test.go b/builtin/providers/aws/resource_aws_iam_group_test.go index 67a72733a..c36a938b6 100644 --- a/builtin/providers/aws/resource_aws_iam_group_test.go +++ b/builtin/providers/aws/resource_aws_iam_group_test.go @@ -26,6 +26,13 @@ func TestAccAWSIAMGroup_basic(t *testing.T) { testAccCheckAWSGroupAttributes(&conf), ), }, + resource.TestStep{ + Config: testAccAWSGroupConfig2, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSGroupExists("aws_iam_group.group", &conf), + testAccCheckAWSGroupAttributes(&conf), + ), + }, }, }) } @@ -105,3 +112,9 @@ resource "aws_iam_group" "group" { path = "/" } ` +const testAccAWSGroupConfig2 = ` +resource "aws_iam_group" "group" { + name = "test-group2" + path = "/funnypath/" +} +`