Skip to content

Commit

Permalink
Merge pull request #4518 from terraform-providers/b-aws_kinesis_fireh…
Browse files Browse the repository at this point in the history
…ose_delivery_stream-more-retries

resource/aws_kinesis_firehose_delivery_stream: Retry on Elasticsearch destination IAM role errors and update IAM errors
  • Loading branch information
bflad authored May 14, 2018
2 parents e3b9efc + c1c6ac4 commit 0bf9db3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
25 changes: 23 additions & 2 deletions aws/resource_aws_kinesis_firehose_delivery_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ func resourceAwsKinesisFirehoseDeliveryStreamCreate(d *schema.ResourceData, meta
log.Printf("[DEBUG] Error creating Firehose Delivery Stream: %s", err)

// Retry for IAM eventual consistency
if isAWSErr(err, firehose.ErrCodeInvalidArgumentException, "is not authorized to perform") {
if isAWSErr(err, firehose.ErrCodeInvalidArgumentException, "is not authorized to") {
return resource.RetryableError(err)
}
// IAM roles can take ~10 seconds to propagate in AWS:
Expand Down Expand Up @@ -1545,7 +1545,28 @@ func resourceAwsKinesisFirehoseDeliveryStreamUpdate(d *schema.ResourceData, meta
}
}

_, err := conn.UpdateDestination(updateInput)
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := conn.UpdateDestination(updateInput)
if err != nil {
log.Printf("[DEBUG] Error creating Firehose Delivery Stream: %s", err)

// Retry for IAM eventual consistency
if isAWSErr(err, firehose.ErrCodeInvalidArgumentException, "is not authorized to") {
return resource.RetryableError(err)
}
// IAM roles can take ~10 seconds to propagate in AWS:
// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#launch-instance-with-role-console
if isAWSErr(err, firehose.ErrCodeInvalidArgumentException, "Firehose is unable to assume role") {
log.Printf("[DEBUG] Firehose could not assume role referenced, retrying...")
return resource.RetryableError(err)
}
// Not retryable
return resource.NonRetryableError(err)
}

return nil
})

if err != nil {
return fmt.Errorf(
"Error Updating Kinesis Firehose Delivery Stream: \"%s\"\n%s",
Expand Down
33 changes: 21 additions & 12 deletions aws/resource_aws_kinesis_firehose_delivery_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,10 @@ func TestAccAWSKinesisFirehoseDeliveryStream_ElasticsearchConfigUpdates(t *testi
policyName := fmt.Sprintf("tf_acc_policy_%s", rString)
roleName := fmt.Sprintf("tf_acc_role_%s", rString)
preConfig := fmt.Sprintf(testAccKinesisFirehoseDeliveryStreamConfig_ElasticsearchBasic,
ri, ri, ri, ri, ri, ri)
ri, ri, ri, ri, ri)
postConfig := testAccFirehoseAWSLambdaConfigBasic(funcName, policyName, roleName) +
fmt.Sprintf(testAccKinesisFirehoseDeliveryStreamConfig_ElasticsearchUpdate,
ri, ri, ri, ri, ri, ri)
ri, ri, ri, ri, ri)

updatedElasticSearchConfig := &firehose.ElasticsearchDestinationDescription{
BufferingHints: &firehose.ElasticsearchBufferingHints{
Expand Down Expand Up @@ -1285,27 +1285,35 @@ resource "aws_elasticsearch_domain" "test_cluster" {
cluster_config {
instance_type = "m3.medium.elasticsearch"
}
}
access_policies = <<CONFIG
resource "aws_iam_role_policy" "firehose-elasticsearch" {
name = "elasticsearch"
role = "${aws_iam_role.firehose.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
},
"Action": "es:*",
"Resource": "arn:aws:es:us-east-1:${data.aws_caller_identity.current.account_id}:domain/es-test-%d/*"
"Action": [
"es:*"
],
"Resource": [
"${aws_elasticsearch_domain.test_cluster.arn}",
"${aws_elasticsearch_domain.test_cluster.arn}/*"
]
}
]
}
CONFIG
}`
EOF
}
`

var testAccKinesisFirehoseDeliveryStreamConfig_ElasticsearchBasic = testAccKinesisFirehoseDeliveryStreamBaseElasticsearchConfig + `
resource "aws_kinesis_firehose_delivery_stream" "test_stream_es" {
depends_on = ["aws_iam_role_policy.firehose", "aws_elasticsearch_domain.test_cluster"]
depends_on = ["aws_iam_role_policy.firehose-elasticsearch"]
name = "terraform-kinesis-firehose-es-%d"
destination = "elasticsearch"
s3_configuration {
Expand All @@ -1322,7 +1330,8 @@ resource "aws_kinesis_firehose_delivery_stream" "test_stream_es" {

var testAccKinesisFirehoseDeliveryStreamConfig_ElasticsearchUpdate = testAccKinesisFirehoseDeliveryStreamBaseElasticsearchConfig + `
resource "aws_kinesis_firehose_delivery_stream" "test_stream_es" {
depends_on = ["aws_iam_role_policy.firehose", "aws_elasticsearch_domain.test_cluster"]
depends_on = ["aws_iam_role_policy.firehose-elasticsearch"]
name = "terraform-kinesis-firehose-es-%d"
destination = "elasticsearch"
s3_configuration {
Expand Down

0 comments on commit 0bf9db3

Please sign in to comment.