Skip to content

Commit

Permalink
Merge pull request #4107 from stack72/f-aws-iam_role_assume_policy_do…
Browse files Browse the repository at this point in the history
…c_update

provider/aws: IAM Role now Allows Update Assume Policy Document
  • Loading branch information
jen20 committed Nov 30, 2015
2 parents 72b8c82 + fece57f commit 683989f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions builtin/providers/aws/resource_aws_iam_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ func resourceAwsIamRole() *schema.Resource {
return &schema.Resource{
Create: resourceAwsIamRoleCreate,
Read: resourceAwsIamRoleRead,
// TODO
//Update: resourceAwsIamRoleUpdate,
Update: resourceAwsIamRoleUpdate,
Delete: resourceAwsIamRoleDelete,

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -55,7 +54,6 @@ func resourceAwsIamRole() *schema.Resource {
"assume_role_policy": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
}
Expand Down Expand Up @@ -95,6 +93,26 @@ func resourceAwsIamRoleRead(d *schema.ResourceData, meta interface{}) error {
}
return resourceAwsIamRoleReadResult(d, getResp.Role)
}
func resourceAwsIamRoleUpdate(d *schema.ResourceData, meta interface{}) error {
iamconn := meta.(*AWSClient).iamconn

if d.HasChange("assume_role_policy") {
assumeRolePolicyInput := &iam.UpdateAssumeRolePolicyInput{
RoleName: aws.String(d.Id()),
PolicyDocument: aws.String(d.Get("assume_role_policy").(string)),
}
_, err := iamconn.UpdateAssumeRolePolicy(assumeRolePolicyInput)
if err != nil {
if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" {
d.SetId("")
return nil
}
return fmt.Errorf("Error Updating IAM Role (%s) Assume Role Policy: %s", d.Id(), err)
}
}

return nil
}

func resourceAwsIamRoleReadResult(d *schema.ResourceData, role *iam.Role) error {
d.SetId(*role.RoleName)
Expand Down

0 comments on commit 683989f

Please sign in to comment.