Merge pull request #3237 from GrayCoder/group-work
provider/aws: add support for group name and path changes with group update function
This commit is contained in:
commit
0bd8b32637
|
@ -14,8 +14,7 @@ func resourceAwsIamGroup() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Create: resourceAwsIamGroupCreate,
|
Create: resourceAwsIamGroupCreate,
|
||||||
Read: resourceAwsIamGroupRead,
|
Read: resourceAwsIamGroupRead,
|
||||||
// TODO
|
Update: resourceAwsIamGroupUpdate,
|
||||||
//Update: resourceAwsIamGroupUpdate,
|
|
||||||
Delete: resourceAwsIamGroupDelete,
|
Delete: resourceAwsIamGroupDelete,
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
|
@ -30,13 +29,11 @@ func resourceAwsIamGroup() *schema.Resource {
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
|
||||||
},
|
},
|
||||||
"path": &schema.Schema{
|
"path": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: "/",
|
Default: "/",
|
||||||
ForceNew: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -45,9 +42,10 @@ func resourceAwsIamGroup() *schema.Resource {
|
||||||
func resourceAwsIamGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsIamGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
iamconn := meta.(*AWSClient).iamconn
|
iamconn := meta.(*AWSClient).iamconn
|
||||||
name := d.Get("name").(string)
|
name := d.Get("name").(string)
|
||||||
|
path := d.Get("path").(string)
|
||||||
|
|
||||||
request := &iam.CreateGroupInput{
|
request := &iam.CreateGroupInput{
|
||||||
Path: aws.String(d.Get("path").(string)),
|
Path: aws.String(path),
|
||||||
GroupName: aws.String(name),
|
GroupName: aws.String(name),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,9 +58,10 @@ func resourceAwsIamGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
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(d.Id()),
|
GroupName: aws.String(name),
|
||||||
}
|
}
|
||||||
|
|
||||||
getResp, err := iamconn.GetGroup(request)
|
getResp, err := iamconn.GetGroup(request)
|
||||||
|
@ -93,6 +92,26 @@ func resourceAwsIamGroupReadResult(d *schema.ResourceData, group *iam.Group) err
|
||||||
return nil
|
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")
|
||||||
|
|
||||||
|
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 {
|
||||||
|
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 {
|
func resourceAwsIamGroupDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
iamconn := meta.(*AWSClient).iamconn
|
iamconn := meta.(*AWSClient).iamconn
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,14 @@ func TestAccAWSIAMGroup_basic(t *testing.T) {
|
||||||
Config: testAccAWSGroupConfig,
|
Config: testAccAWSGroupConfig,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSGroupExists("aws_iam_group.group", &conf),
|
testAccCheckAWSGroupExists("aws_iam_group.group", &conf),
|
||||||
testAccCheckAWSGroupAttributes(&conf),
|
testAccCheckAWSGroupAttributes(&conf, "test-group", "/"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSGroupConfig2,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSGroupExists("aws_iam_group.group", &conf),
|
||||||
|
testAccCheckAWSGroupAttributes(&conf, "test-group2", "/funnypath/"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -85,14 +92,14 @@ func testAccCheckAWSGroupExists(n string, res *iam.GetGroupOutput) resource.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckAWSGroupAttributes(group *iam.GetGroupOutput) resource.TestCheckFunc {
|
func testAccCheckAWSGroupAttributes(group *iam.GetGroupOutput, name string, path string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
if *group.Group.GroupName != "test-group" {
|
if *group.Group.GroupName != name {
|
||||||
return fmt.Errorf("Bad name: %s", *group.Group.GroupName)
|
return fmt.Errorf("Bad name: %s when %s was expected", *group.Group.GroupName, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *group.Group.Path != "/" {
|
if *group.Group.Path != path {
|
||||||
return fmt.Errorf("Bad path: %s", *group.Group.Path)
|
return fmt.Errorf("Bad path: %s when %s was expected", *group.Group.Path, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -105,3 +112,9 @@ resource "aws_iam_group" "group" {
|
||||||
path = "/"
|
path = "/"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
const testAccAWSGroupConfig2 = `
|
||||||
|
resource "aws_iam_group" "group" {
|
||||||
|
name = "test-group2"
|
||||||
|
path = "/funnypath/"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
Reference in New Issue