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,
|
Read: resourceAwsIamGroupRead,
|
||||||
Update: resourceAwsIamGroupUpdate,
|
Update: resourceAwsIamGroupUpdate,
|
||||||
Delete: resourceAwsIamGroupDelete,
|
Delete: resourceAwsIamGroupDelete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"arn": &schema.Schema{
|
"arn": &schema.Schema{
|
||||||
|
@ -53,15 +56,16 @@ func resourceAwsIamGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating IAM Group %s: %s", name, err)
|
return fmt.Errorf("Error creating IAM Group %s: %s", name, err)
|
||||||
}
|
}
|
||||||
|
d.SetId(*createResp.Group.GroupName)
|
||||||
|
|
||||||
return resourceAwsIamGroupReadResult(d, createResp.Group)
|
return resourceAwsIamGroupReadResult(d, createResp.Group)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsIamGroupRead(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsIamGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
iamconn := meta.(*AWSClient).iamconn
|
iamconn := meta.(*AWSClient).iamconn
|
||||||
name := d.Get("name").(string)
|
|
||||||
|
|
||||||
request := &iam.GetGroupInput{
|
request := &iam.GetGroupInput{
|
||||||
GroupName: aws.String(name),
|
GroupName: aws.String(d.Id()),
|
||||||
}
|
}
|
||||||
|
|
||||||
getResp, err := iamconn.GetGroup(request)
|
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 {
|
func resourceAwsIamGroupReadResult(d *schema.ResourceData, group *iam.Group) error {
|
||||||
d.SetId(*group.GroupName)
|
|
||||||
if err := d.Set("name", group.GroupName); err != nil {
|
if err := d.Set("name", group.GroupName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ func TestAccAWSIAMGroup_basic(t *testing.T) {
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSGroupConfig2,
|
Config: testAccAWSGroupConfig2,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSGroupExists("aws_iam_group.group", &conf),
|
testAccCheckAWSGroupExists("aws_iam_group.group2", &conf),
|
||||||
testAccCheckAWSGroupAttributes(&conf, "test-group2", "/funnypath/"),
|
testAccCheckAWSGroupAttributes(&conf, "test-group2", "/funnypath/"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -113,7 +113,7 @@ resource "aws_iam_group" "group" {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
const testAccAWSGroupConfig2 = `
|
const testAccAWSGroupConfig2 = `
|
||||||
resource "aws_iam_group" "group" {
|
resource "aws_iam_group" "group2" {
|
||||||
name = "test-group2"
|
name = "test-group2"
|
||||||
path = "/funnypath/"
|
path = "/funnypath/"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue