From f4c556cde18f208e3002a9e06f0bd4990552664d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 2 Mar 2021 18:00:56 -0500 Subject: [PATCH] r/aws_kinesis_analytics_application: Wait for correct status when updating running application. Acceptance test output: $ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSKinesisAnalyticsApplication_StartApplication_Update' ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSKinesisAnalyticsApplication_StartApplication_Update -timeout 120m === RUN TestAccAWSKinesisAnalyticsApplication_StartApplication_Update === PAUSE TestAccAWSKinesisAnalyticsApplication_StartApplication_Update === CONT TestAccAWSKinesisAnalyticsApplication_StartApplication_Update --- PASS: TestAccAWSKinesisAnalyticsApplication_StartApplication_Update (701.79s) PASS ok github.com/terraform-providers/terraform-provider-aws/aws 701.898s --- ...ource_aws_kinesis_analytics_application.go | 36 +++ ..._aws_kinesis_analytics_application_test.go | 248 +++++++++++++++++- 2 files changed, 278 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_kinesis_analytics_application.go b/aws/resource_aws_kinesis_analytics_application.go index 103bfd4e949..ffc8b2f4820 100644 --- a/aws/resource_aws_kinesis_analytics_application.go +++ b/aws/resource_aws_kinesis_analytics_application.go @@ -788,6 +788,10 @@ func resourceAwsKinesisAnalyticsApplicationUpdate(d *schema.ResourceData, meta i return fmt.Errorf("error adding Kinesis Analytics Application (%s) CloudWatch logging option: %w", d.Id(), err) } + if _, err := waiter.ApplicationUpdated(conn, applicationName); err != nil { + return fmt.Errorf("error waiting for Kinesis Analytics Application (%s) to update: %w", d.Id(), err) + } + currentApplicationVersionId += 1 } else if len(n.([]interface{})) == 0 { // Delete existing CloudWatch logging options. @@ -809,6 +813,10 @@ func resourceAwsKinesisAnalyticsApplicationUpdate(d *schema.ResourceData, meta i return fmt.Errorf("error deleting Kinesis Analytics Application (%s) CloudWatch logging option: %w", d.Id(), err) } + if _, err := waiter.ApplicationUpdated(conn, applicationName); err != nil { + return fmt.Errorf("error waiting for Kinesis Analytics Application (%s) to update: %w", d.Id(), err) + } + currentApplicationVersionId += 1 } else { // Update existing CloudWatch logging options. @@ -854,6 +862,10 @@ func resourceAwsKinesisAnalyticsApplicationUpdate(d *schema.ResourceData, meta i return fmt.Errorf("error adding Kinesis Analytics Application (%s) input: %w", d.Id(), err) } + if _, err := waiter.ApplicationUpdated(conn, applicationName); err != nil { + return fmt.Errorf("error waiting for Kinesis Analytics Application (%s) to update: %w", d.Id(), err) + } + currentApplicationVersionId += 1 } else if len(n.([]interface{})) == 0 { // The existing input cannot be deleted. @@ -887,6 +899,10 @@ func resourceAwsKinesisAnalyticsApplicationUpdate(d *schema.ResourceData, meta i return fmt.Errorf("error adding Kinesis Analytics Application (%s) input processing configuration: %w", d.Id(), err) } + if _, err := waiter.ApplicationUpdated(conn, applicationName); err != nil { + return fmt.Errorf("error waiting for Kinesis Analytics Application (%s) to update: %w", d.Id(), err) + } + currentApplicationVersionId += 1 } else if len(n.([]interface{})) == 0 { // Delete existing input processing configuration. @@ -906,6 +922,10 @@ func resourceAwsKinesisAnalyticsApplicationUpdate(d *schema.ResourceData, meta i return fmt.Errorf("error deleting Kinesis Analytics Application (%s) input processing configuration: %w", d.Id(), err) } + if _, err := waiter.ApplicationUpdated(conn, applicationName); err != nil { + return fmt.Errorf("error waiting for Kinesis Analytics Application (%s) to update: %w", d.Id(), err) + } + currentApplicationVersionId += 1 } } @@ -962,6 +982,10 @@ func resourceAwsKinesisAnalyticsApplicationUpdate(d *schema.ResourceData, meta i return fmt.Errorf("error deleting Kinesis Analytics Application (%s) output: %w", d.Id(), err) } + if _, err := waiter.ApplicationUpdated(conn, applicationName); err != nil { + return fmt.Errorf("error waiting for Kinesis Analytics Application (%s) to update: %w", d.Id(), err) + } + currentApplicationVersionId += 1 } @@ -983,6 +1007,10 @@ func resourceAwsKinesisAnalyticsApplicationUpdate(d *schema.ResourceData, meta i return fmt.Errorf("error adding Kinesis Analytics Application (%s) output: %w", d.Id(), err) } + if _, err := waiter.ApplicationUpdated(conn, applicationName); err != nil { + return fmt.Errorf("error waiting for Kinesis Analytics Application (%s) to update: %w", d.Id(), err) + } + currentApplicationVersionId += 1 } } @@ -1008,6 +1036,10 @@ func resourceAwsKinesisAnalyticsApplicationUpdate(d *schema.ResourceData, meta i return fmt.Errorf("error adding Kinesis Analytics Application (%s) reference data source: %w", d.Id(), err) } + if _, err := waiter.ApplicationUpdated(conn, applicationName); err != nil { + return fmt.Errorf("error waiting for Kinesis Analytics Application (%s) to update: %w", d.Id(), err) + } + currentApplicationVersionId += 1 } else if len(n.([]interface{})) == 0 { // Delete existing reference data source. @@ -1029,6 +1061,10 @@ func resourceAwsKinesisAnalyticsApplicationUpdate(d *schema.ResourceData, meta i return fmt.Errorf("error deleting Kinesis Analytics Application (%s) reference data source: %w", d.Id(), err) } + if _, err := waiter.ApplicationUpdated(conn, applicationName); err != nil { + return fmt.Errorf("error waiting for Kinesis Analytics Application (%s) to update: %w", d.Id(), err) + } + currentApplicationVersionId += 1 } else { // Update existing reference data source. diff --git a/aws/resource_aws_kinesis_analytics_application_test.go b/aws/resource_aws_kinesis_analytics_application_test.go index a047431163c..ffa8781b592 100644 --- a/aws/resource_aws_kinesis_analytics_application_test.go +++ b/aws/resource_aws_kinesis_analytics_application_test.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "strconv" "testing" "time" @@ -109,6 +110,7 @@ func TestAccAWSKinesisAnalyticsApplication_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -216,6 +218,7 @@ func TestAccAWSKinesisAnalyticsApplication_Code_Update(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -235,6 +238,7 @@ func TestAccAWSKinesisAnalyticsApplication_Code_Update(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "2"), @@ -275,6 +279,7 @@ func TestAccAWSKinesisAnalyticsApplication_CloudWatchLoggingOptions_Add(t *testi resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -296,6 +301,7 @@ func TestAccAWSKinesisAnalyticsApplication_CloudWatchLoggingOptions_Add(t *testi resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "2"), @@ -338,6 +344,7 @@ func TestAccAWSKinesisAnalyticsApplication_CloudWatchLoggingOptions_Delete(t *te resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -357,6 +364,7 @@ func TestAccAWSKinesisAnalyticsApplication_CloudWatchLoggingOptions_Delete(t *te resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "2"), @@ -401,6 +409,7 @@ func TestAccAWSKinesisAnalyticsApplication_CloudWatchLoggingOptions_Update(t *te resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -422,6 +431,7 @@ func TestAccAWSKinesisAnalyticsApplication_CloudWatchLoggingOptions_Update(t *te resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "2"), @@ -462,6 +472,7 @@ func TestAccAWSKinesisAnalyticsApplication_Input_Add(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -505,6 +516,7 @@ func TestAccAWSKinesisAnalyticsApplication_Input_Add(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", ""), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "2"), @@ -571,6 +583,7 @@ func TestAccAWSKinesisAnalyticsApplication_Input_Update(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", ""), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -617,6 +630,7 @@ func TestAccAWSKinesisAnalyticsApplication_Input_Update(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", ""), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "2"), @@ -682,6 +696,7 @@ func TestAccAWSKinesisAnalyticsApplication_InputProcessingConfiguration_Add(t *t resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", ""), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -728,6 +743,7 @@ func TestAccAWSKinesisAnalyticsApplication_InputProcessingConfiguration_Add(t *t resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", ""), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "3"), // Add input processing configuration + update input. @@ -796,6 +812,7 @@ func TestAccAWSKinesisAnalyticsApplication_InputProcessingConfiguration_Delete(t resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", ""), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -839,6 +856,7 @@ func TestAccAWSKinesisAnalyticsApplication_InputProcessingConfiguration_Delete(t resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", ""), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "3"), // Delete input processing configuration + update input. @@ -909,6 +927,7 @@ func TestAccAWSKinesisAnalyticsApplication_InputProcessingConfiguration_Update(t resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", ""), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -955,6 +974,7 @@ func TestAccAWSKinesisAnalyticsApplication_InputProcessingConfiguration_Update(t resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", ""), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "2"), @@ -987,7 +1007,7 @@ func TestAccAWSKinesisAnalyticsApplication_Multiple_Update(t *testing.T) { CheckDestroy: testAccCheckKinesisAnalyticsApplicationDestroy, Steps: []resource.TestStep{ { - Config: testAccKinesisAnalyticsApplicationConfigMultiple(rName), + Config: testAccKinesisAnalyticsApplicationConfigMultiple(rName, "", ""), Check: resource.ComposeTestCheckFunc( testAccCheckKinesisAnalyticsApplicationExists(resourceName, &v), testAccCheckResourceAttrRegionalARN(resourceName, "arn", "kinesisanalytics", fmt.Sprintf("application/%s", rName)), @@ -1046,7 +1066,7 @@ func TestAccAWSKinesisAnalyticsApplication_Multiple_Update(t *testing.T) { ), }, { - Config: testAccKinesisAnalyticsApplicationConfigMultipleUpdated(rName), + Config: testAccKinesisAnalyticsApplicationConfigMultipleUpdated(rName, "", ""), Check: resource.ComposeTestCheckFunc( testAccCheckKinesisAnalyticsApplicationExists(resourceName, &v), testAccCheckResourceAttrRegionalARN(resourceName, "arn", "kinesisanalytics", fmt.Sprintf("application/%s", rName)), @@ -1179,6 +1199,7 @@ func TestAccAWSKinesisAnalyticsApplication_Output_Update(t *testing.T) { resource.TestCheckTypeSetElemAttrPair(resourceName, "outputs.*.kinesis_firehose.0.resource_arn", firehoseResourceName, "arn"), resource.TestCheckTypeSetElemAttrPair(resourceName, "outputs.*.kinesis_firehose.0.role_arn", iamRole1ResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -1218,6 +1239,7 @@ func TestAccAWSKinesisAnalyticsApplication_Output_Update(t *testing.T) { resource.TestCheckTypeSetElemAttrPair(resourceName, "outputs.*.lambda.0.resource_arn", lambdaResourceName, "arn"), resource.TestCheckTypeSetElemAttrPair(resourceName, "outputs.*.lambda.0.role_arn", iamRole1ResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "4"), // 1 * output deletion + 2 * output addition. @@ -1242,6 +1264,7 @@ func TestAccAWSKinesisAnalyticsApplication_Output_Update(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "6"), // 2 * output deletion. @@ -1277,6 +1300,7 @@ func TestAccAWSKinesisAnalyticsApplication_ReferenceDataSource_Add(t *testing.T) resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "1"), @@ -1314,6 +1338,7 @@ func TestAccAWSKinesisAnalyticsApplication_ReferenceDataSource_Add(t *testing.T) resource.TestCheckResourceAttrPair(resourceName, "reference_data_sources.0.s3.0.role_arn", iamRoleResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.table_name", "TABLE-1"), resource.TestCheckResourceAttrSet(resourceName, "reference_data_sources.0.id"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "2"), @@ -1372,6 +1397,7 @@ func TestAccAWSKinesisAnalyticsApplication_ReferenceDataSource_Delete(t *testing resource.TestCheckResourceAttrPair(resourceName, "reference_data_sources.0.s3.0.role_arn", iamRoleResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.table_name", "TABLE-1"), resource.TestCheckResourceAttrSet(resourceName, "reference_data_sources.0.id"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "2"), @@ -1391,6 +1417,7 @@ func TestAccAWSKinesisAnalyticsApplication_ReferenceDataSource_Delete(t *testing resource.TestCheckResourceAttr(resourceName, "inputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "outputs.#", "0"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "3"), @@ -1450,6 +1477,7 @@ func TestAccAWSKinesisAnalyticsApplication_ReferenceDataSource_Update(t *testing resource.TestCheckResourceAttrPair(resourceName, "reference_data_sources.0.s3.0.role_arn", iamRole1ResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.table_name", "TABLE-1"), resource.TestCheckResourceAttrSet(resourceName, "reference_data_sources.0.id"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "2"), @@ -1490,6 +1518,7 @@ func TestAccAWSKinesisAnalyticsApplication_ReferenceDataSource_Update(t *testing resource.TestCheckResourceAttrPair(resourceName, "reference_data_sources.0.s3.0.role_arn", iamRole2ResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.table_name", "TABLE-2"), resource.TestCheckResourceAttrSet(resourceName, "reference_data_sources.0.id"), + resource.TestCheckNoResourceAttr(resourceName, "start_application"), resource.TestCheckResourceAttr(resourceName, "status", "READY"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "version", "3"), @@ -1724,6 +1753,180 @@ func TestAccAWSKinesisAnalyticsApplication_StartApplication_OnUpdate(t *testing. }) } +func TestAccAWSKinesisAnalyticsApplication_StartApplication_Update(t *testing.T) { + var v kinesisanalytics.ApplicationDetail + resourceName := "aws_kinesis_analytics_application.test" + iamRole1ResourceName := "aws_iam_role.test.0" + iamRole2ResourceName := "aws_iam_role.test.1" + cloudWatchLogStreamResourceName := "aws_cloudwatch_log_stream.test" + lambdaResourceName := "aws_lambda_function.test.0" + firehoseResourceName := "aws_kinesis_firehose_delivery_stream.test" + streamsResourceName := "aws_kinesis_stream.test" + s3BucketResourceName := "aws_s3_bucket.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSKinesisAnalytics(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckKinesisAnalyticsApplicationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccKinesisAnalyticsApplicationConfigMultiple(rName, "true", "LAST_STOPPED_POINT"), + Check: resource.ComposeTestCheckFunc( + testAccCheckKinesisAnalyticsApplicationExists(resourceName, &v), + testAccCheckResourceAttrRegionalARN(resourceName, "arn", "kinesisanalytics", fmt.Sprintf("application/%s", rName)), + resource.TestCheckResourceAttr(resourceName, "cloudwatch_logging_options.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "cloudwatch_logging_options.0.log_stream_arn", cloudWatchLogStreamResourceName, "arn"), + resource.TestCheckResourceAttrPair(resourceName, "cloudwatch_logging_options.0.role_arn", iamRole2ResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "code", ""), + resource.TestCheckResourceAttrSet(resourceName, "create_timestamp"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttrSet(resourceName, "last_update_timestamp"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "inputs.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.stream_names.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "inputs.0.id"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_columns.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_columns.0.name", "COLUMN_1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_columns.0.sql_type", "INTEGER"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_encoding", ""), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.mapping_parameters.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.mapping_parameters.0.csv.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.mapping_parameters.0.csv.0.record_column_delimiter", ","), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.mapping_parameters.0.csv.0.record_row_delimiter", "|"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.mapping_parameters.0.json.#", "0"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.record_format_type", "CSV"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.name_prefix", "NAME_PREFIX_1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.parallelism.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.parallelism.0.count", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.processing_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.processing_configuration.0.lambda.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "inputs.0.processing_configuration.0.lambda.0.resource_arn", lambdaResourceName, "arn"), + resource.TestCheckResourceAttrPair(resourceName, "inputs.0.processing_configuration.0.lambda.0.role_arn", iamRole1ResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.kinesis_firehose.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "inputs.0.kinesis_firehose.0.resource_arn", firehoseResourceName, "arn"), + resource.TestCheckResourceAttrPair(resourceName, "inputs.0.kinesis_firehose.0.role_arn", iamRole1ResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.kinesis_stream.#", "0"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", "LAST_STOPPED_POINT"), + resource.TestCheckResourceAttr(resourceName, "outputs.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "outputs.*", map[string]string{ + "name": "OUTPUT_1", + "schema.#": "1", + "schema.0.record_format_type": "CSV", + "kinesis_firehose.#": "1", + "kinesis_stream.#": "0", + "lambda.#": "0", + }), + resource.TestCheckTypeSetElemAttrPair(resourceName, "outputs.*.kinesis_firehose.0.resource_arn", firehoseResourceName, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "outputs.*.kinesis_firehose.0.role_arn", iamRole2ResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "0"), + resource.TestCheckResourceAttr(resourceName, "start_application", "true"), + resource.TestCheckResourceAttr(resourceName, "status", "RUNNING"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Key1", "Value1"), + resource.TestCheckResourceAttr(resourceName, "version", "1"), + ), + }, + { + Config: testAccKinesisAnalyticsApplicationConfigMultipleUpdated(rName, "true", "LAST_STOPPED_POINT"), + Check: resource.ComposeTestCheckFunc( + testAccCheckKinesisAnalyticsApplicationExists(resourceName, &v), + testAccCheckResourceAttrRegionalARN(resourceName, "arn", "kinesisanalytics", fmt.Sprintf("application/%s", rName)), + resource.TestCheckResourceAttr(resourceName, "cloudwatch_logging_options.#", "0"), + resource.TestCheckResourceAttr(resourceName, "code", ""), + resource.TestCheckResourceAttrSet(resourceName, "create_timestamp"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttrSet(resourceName, "last_update_timestamp"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "inputs.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.stream_names.#", "42"), + resource.TestCheckResourceAttrSet(resourceName, "inputs.0.id"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_columns.#", "2"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_columns.0.mapping", "MAPPING-2"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_columns.0.name", "COLUMN_2"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_columns.0.sql_type", "VARCHAR(8)"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_columns.1.mapping", "MAPPING-3"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_columns.1.name", "COLUMN_3"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_columns.1.sql_type", "DOUBLE"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_encoding", "UTF-8"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.mapping_parameters.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.mapping_parameters.0.csv.#", "0"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.mapping_parameters.0.json.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.mapping_parameters.0.json.0.record_row_path", "$path.to.record"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.schema.0.record_format.0.record_format_type", "JSON"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.name_prefix", "NAME_PREFIX_2"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.parallelism.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.parallelism.0.count", "42"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.processing_configuration.#", "0"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.kinesis_firehose.#", "0"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.kinesis_stream.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "inputs.0.kinesis_stream.0.resource_arn", streamsResourceName, "arn"), + resource.TestCheckResourceAttrPair(resourceName, "inputs.0.kinesis_stream.0.role_arn", iamRole2ResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "inputs.0.starting_position_configuration.0.starting_position", "LAST_STOPPED_POINT"), + resource.TestCheckResourceAttr(resourceName, "outputs.#", "2"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "outputs.*", map[string]string{ + "name": "OUTPUT_2", + "schema.#": "1", + "schema.0.record_format_type": "JSON", + "kinesis_firehose.#": "0", + "kinesis_stream.#": "1", + "lambda.#": "0", + }), + resource.TestCheckTypeSetElemAttrPair(resourceName, "outputs.*.kinesis_stream.0.resource_arn", streamsResourceName, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "outputs.*.kinesis_stream.0.role_arn", iamRole2ResourceName, "arn"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "outputs.*", map[string]string{ + "name": "OUTPUT_3", + "schema.#": "1", + "schema.0.record_format_type": "CSV", + "kinesis_firehose.#": "0", + "kinesis_stream.#": "0", + "lambda.#": "1", + }), + resource.TestCheckTypeSetElemAttrPair(resourceName, "outputs.*.lambda.0.resource_arn", lambdaResourceName, "arn"), + resource.TestCheckTypeSetElemAttrPair(resourceName, "outputs.*.lambda.0.role_arn", iamRole1ResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.#", "1"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.#", "1"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_columns.#", "1"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_columns.0.name", "COLUMN_1"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_columns.0.sql_type", "INTEGER"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_encoding", ""), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_format.#", "1"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_format.0.mapping_parameters.#", "1"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_format.0.mapping_parameters.0.csv.#", "1"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_format.0.mapping_parameters.0.csv.0.record_column_delimiter", ","), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_format.0.mapping_parameters.0.csv.0.record_row_delimiter", "|"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_format.0.mapping_parameters.0.json.#", "0"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.schema.0.record_format.0.record_format_type", "CSV"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.s3.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "reference_data_sources.0.s3.0.bucket_arn", s3BucketResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.s3.0.file_key", "KEY-1"), + resource.TestCheckResourceAttrPair(resourceName, "reference_data_sources.0.s3.0.role_arn", iamRole2ResourceName, "arn"), + resource.TestCheckResourceAttr(resourceName, "reference_data_sources.0.table_name", "TABLE-1"), + resource.TestCheckResourceAttrSet(resourceName, "reference_data_sources.0.id"), + resource.TestCheckResourceAttr(resourceName, "start_application", "true"), + resource.TestCheckResourceAttr(resourceName, "status", "RUNNING"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.Key2", "Value2"), + resource.TestCheckResourceAttr(resourceName, "tags.Key3", "Value3"), + resource.TestCheckResourceAttr(resourceName, "version", "8"), // Delete CloudWatch logging options + add reference data source + delete input processing configuration+ update application + delete output + 2 * add output. + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"start_application"}, + }, + }, + }) +} + func testAccCheckKinesisAnalyticsApplicationDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).kinesisanalyticsconn @@ -1733,9 +1936,11 @@ func testAccCheckKinesisAnalyticsApplicationDestroy(s *terraform.State) error { } _, err := finder.ApplicationDetailByName(conn, rs.Primary.Attributes["name"]) + if tfresource.NotFound(err) { continue } + if err != nil { return err } @@ -1759,6 +1964,7 @@ func testAccCheckKinesisAnalyticsApplicationExists(n string, v *kinesisanalytics conn := testAccProvider.Meta().(*AWSClient).kinesisanalyticsconn application, err := finder.ApplicationDetailByName(conn, rs.Primary.Attributes["name"]) + if err != nil { return err } @@ -2064,7 +2270,16 @@ resource "aws_kinesis_analytics_application" "test" { `, rName, lambdaIndex)) } -func testAccKinesisAnalyticsApplicationConfigMultiple(rName string) string { +func testAccKinesisAnalyticsApplicationConfigMultiple(rName, startApplication, startingPosition string) string { + if startApplication == "" { + startApplication = "null" + } + if startingPosition == "" { + startingPosition = "null" + } else { + startingPosition = strconv.Quote(startingPosition) + } + return composeConfig( testAccKinesisAnalyticsApplicationConfigBaseIamRole(rName), testAccKinesisAnalyticsApplicationConfigBaseInputOutput(rName), @@ -2116,6 +2331,10 @@ resource "aws_kinesis_analytics_application" "test" { resource_arn = aws_kinesis_firehose_delivery_stream.test.arn role_arn = aws_iam_role.test[0].arn } + + starting_position_configuration { + starting_position = %[3]s + } } outputs { @@ -2134,11 +2353,22 @@ resource "aws_kinesis_analytics_application" "test" { tags = { Key1 = "Value1" } + + start_application = %[2]s } -`, rName)) +`, rName, startApplication, startingPosition)) } -func testAccKinesisAnalyticsApplicationConfigMultipleUpdated(rName string) string { +func testAccKinesisAnalyticsApplicationConfigMultipleUpdated(rName, startApplication, startingPosition string) string { + if startApplication == "" { + startApplication = "null" + } + if startingPosition == "" { + startingPosition = "null" + } else { + startingPosition = strconv.Quote(startingPosition) + } + return composeConfig( testAccKinesisAnalyticsApplicationConfigBaseIamRole(rName), testAccKinesisAnalyticsApplicationConfigBaseInputOutput(rName), @@ -2181,6 +2411,10 @@ resource "aws_kinesis_analytics_application" "test" { resource_arn = aws_kinesis_stream.test.arn role_arn = aws_iam_role.test[1].arn } + + starting_position_configuration { + starting_position = %[3]s + } } outputs { @@ -2239,8 +2473,10 @@ resource "aws_kinesis_analytics_application" "test" { Key2 = "Value2" Key3 = "Value3" } + + start_application = %[2]s } -`, rName)) +`, rName, startApplication, startingPosition)) } func testAccKinesisAnalyticsApplicationOutput(rName string) string {