Skip to content

Commit

Permalink
r/cloudtrail: Retry if IAM role isn't propagated yet
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Aug 7, 2017
1 parent d06c25f commit 0d7e9d8
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions aws/resource_aws_cloudtrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudtrail"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -116,7 +118,21 @@ func resourceAwsCloudTrailCreate(d *schema.ResourceData, meta interface{}) error
input.SnsTopicName = aws.String(v.(string))
}

t, err := conn.CreateTrail(&input)
var t *cloudtrail.CreateTrailOutput
err := resource.Retry(15*time.Second, func() *resource.RetryError {
var err error
t, err = conn.CreateTrail(&input)
if err != nil {
if isAWSErr(err, cloudtrail.ErrCodeInvalidCloudWatchLogsRoleArnException, "Access denied.") {
return resource.RetryableError(err)
}
if isAWSErr(err, cloudtrail.ErrCodeInvalidCloudWatchLogsLogGroupArnException, "Access denied.") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
}
Expand Down Expand Up @@ -250,7 +266,21 @@ func resourceAwsCloudTrailUpdate(d *schema.ResourceData, meta interface{}) error
}

log.Printf("[DEBUG] Updating CloudTrail: %s", input)
t, err := conn.UpdateTrail(&input)
var t *cloudtrail.UpdateTrailOutput
err := resource.Retry(15*time.Second, func() *resource.RetryError {
var err error
t, err = conn.UpdateTrail(&input)
if err != nil {
if isAWSErr(err, cloudtrail.ErrCodeInvalidCloudWatchLogsRoleArnException, "Access denied.") {
return resource.RetryableError(err)
}
if isAWSErr(err, cloudtrail.ErrCodeInvalidCloudWatchLogsLogGroupArnException, "Access denied.") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
}
Expand Down

0 comments on commit 0d7e9d8

Please sign in to comment.