Merge pull request #4315 from paybyphone/paybyphone_s3bucketpolicywaiter

aws_s3_bucket: Retry MalformedPolicy errors due to newly created principals
This commit is contained in:
Clint 2015-12-16 11:21:52 -06:00
commit 60817ae91a
1 changed files with 18 additions and 1 deletions

View File

@ -5,7 +5,9 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"time"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -466,9 +468,24 @@ func resourceAwsS3BucketPolicyUpdate(s3conn *s3.S3, d *schema.ResourceData) erro
if policy != "" { if policy != "" {
log.Printf("[DEBUG] S3 bucket: %s, put policy: %s", bucket, policy) log.Printf("[DEBUG] S3 bucket: %s, put policy: %s", bucket, policy)
_, err := s3conn.PutBucketPolicy(&s3.PutBucketPolicyInput{ params := &s3.PutBucketPolicyInput{
Bucket: aws.String(bucket), Bucket: aws.String(bucket),
Policy: aws.String(policy), Policy: aws.String(policy),
}
err := resource.Retry(1*time.Minute, func() error {
if _, err := s3conn.PutBucketPolicy(params); err != nil {
if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "MalformedPolicy" {
// Retryable
return awserr
}
}
// Not retryable
return resource.RetryError{Err: err}
}
// No error
return nil
}) })
if err != nil { if err != nil {