From dfa205f65bc0c25f18c7b38923ba797cb988f495 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Fri, 11 May 2018 14:02:41 -0400 Subject: [PATCH 1/2] resource/aws_kinesis_firehose_delivery_stream: Retry on Elasticsearch destination IAM role errors and update IAM errors --- ...ce_aws_kinesis_firehose_delivery_stream.go | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_kinesis_firehose_delivery_stream.go b/aws/resource_aws_kinesis_firehose_delivery_stream.go index fa09a219ce4..0a2fb320ecc 100644 --- a/aws/resource_aws_kinesis_firehose_delivery_stream.go +++ b/aws/resource_aws_kinesis_firehose_delivery_stream.go @@ -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: @@ -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", From c1c6ac48920afa86278f11184ac5e108d501de02 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Fri, 11 May 2018 15:50:19 -0400 Subject: [PATCH 2/2] tests/resource/aws_kinesis_firehose_delivery_stream: Fix Elasticsearch IAM policy handling --- ...s_kinesis_firehose_delivery_stream_test.go | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/aws/resource_aws_kinesis_firehose_delivery_stream_test.go b/aws/resource_aws_kinesis_firehose_delivery_stream_test.go index b389939e0d0..d499a3797d9 100644 --- a/aws/resource_aws_kinesis_firehose_delivery_stream_test.go +++ b/aws/resource_aws_kinesis_firehose_delivery_stream_test.go @@ -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{ @@ -1285,27 +1285,35 @@ resource "aws_elasticsearch_domain" "test_cluster" { cluster_config { instance_type = "m3.medium.elasticsearch" } +} - access_policies = <