Merge pull request #7291 from hashicorp/import-aws-iamgroup
provider/aws: Support Import for `aws_iam_group`
This commit is contained in:
commit
5ac9f21d2f
|
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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/"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue