diff --git a/builtin/providers/aws/import_aws_iam_group_test.go b/builtin/providers/aws/import_aws_iam_group_test.go new file mode 100644 index 000000000..76da67d25 --- /dev/null +++ b/builtin/providers/aws/import_aws_iam_group_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSIAMGroup_importBasic(t *testing.T) { + resourceName := "aws_iam_group.group" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSGroupDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSGroupConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_iam_group.go b/builtin/providers/aws/resource_aws_iam_group.go index f2415f585..ecc5cae8e 100644 --- a/builtin/providers/aws/resource_aws_iam_group.go +++ b/builtin/providers/aws/resource_aws_iam_group.go @@ -16,6 +16,9 @@ func resourceAwsIamGroup() *schema.Resource { Read: resourceAwsIamGroupRead, Update: resourceAwsIamGroupUpdate, Delete: resourceAwsIamGroupDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "arn": &schema.Schema{ @@ -53,15 +56,16 @@ func resourceAwsIamGroupCreate(d *schema.ResourceData, meta interface{}) error { if err != nil { return fmt.Errorf("Error creating IAM Group %s: %s", name, err) } + d.SetId(*createResp.Group.GroupName) + return resourceAwsIamGroupReadResult(d, createResp.Group) } func resourceAwsIamGroupRead(d *schema.ResourceData, meta interface{}) error { iamconn := meta.(*AWSClient).iamconn - name := d.Get("name").(string) request := &iam.GetGroupInput{ - GroupName: aws.String(name), + GroupName: aws.String(d.Id()), } getResp, err := iamconn.GetGroup(request) @@ -76,7 +80,6 @@ func resourceAwsIamGroupRead(d *schema.ResourceData, meta interface{}) error { } func resourceAwsIamGroupReadResult(d *schema.ResourceData, group *iam.Group) error { - d.SetId(*group.GroupName) if err := d.Set("name", group.GroupName); err != nil { return err } diff --git a/builtin/providers/aws/resource_aws_iam_group_test.go b/builtin/providers/aws/resource_aws_iam_group_test.go index 977889bd6..ae895b0a0 100644 --- a/builtin/providers/aws/resource_aws_iam_group_test.go +++ b/builtin/providers/aws/resource_aws_iam_group_test.go @@ -29,7 +29,7 @@ func TestAccAWSIAMGroup_basic(t *testing.T) { resource.TestStep{ Config: testAccAWSGroupConfig2, Check: resource.ComposeTestCheckFunc( - testAccCheckAWSGroupExists("aws_iam_group.group", &conf), + testAccCheckAWSGroupExists("aws_iam_group.group2", &conf), testAccCheckAWSGroupAttributes(&conf, "test-group2", "/funnypath/"), ), }, @@ -113,7 +113,7 @@ resource "aws_iam_group" "group" { } ` const testAccAWSGroupConfig2 = ` -resource "aws_iam_group" "group" { +resource "aws_iam_group" "group2" { name = "test-group2" path = "/funnypath/" }