diff --git a/aws/resource_aws_config_aggregate_authorization_test.go b/aws/resource_aws_config_aggregate_authorization_test.go index 4d84475ab40..f2990534e1e 100644 --- a/aws/resource_aws_config_aggregate_authorization_test.go +++ b/aws/resource_aws_config_aggregate_authorization_test.go @@ -61,6 +61,8 @@ func TestAccAWSConfigAggregateAuthorization_basic(t *testing.T) { rString := acctest.RandStringFromCharSet(12, "0123456789") resourceName := "aws_config_aggregate_authorization.example" + region := "eu-west-1" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -70,8 +72,8 @@ func TestAccAWSConfigAggregateAuthorization_basic(t *testing.T) { Config: testAccAWSConfigAggregateAuthorizationConfig_basic(rString), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "account_id", rString), - resource.TestCheckResourceAttr(resourceName, "region", "eu-west-1"), - resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(`^arn:aws:config:[\w-]+:\d{12}:aggregation-authorization/\d{12}/[\w-]+$`)), + resource.TestCheckResourceAttr(resourceName, "region", region), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "config", regexp.MustCompile(fmt.Sprintf(`aggregation-authorization/%s/%s$`, rString, region))), ), }, { diff --git a/aws/resource_aws_config_config_rule_test.go b/aws/resource_aws_config_config_rule_test.go index fba3f26499f..e4db074a520 100644 --- a/aws/resource_aws_config_config_rule_test.go +++ b/aws/resource_aws_config_config_rule_test.go @@ -41,8 +41,6 @@ func testAccConfigConfigRule_ownerAws(t *testing.T) { var cr configservice.ConfigRule rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_config_config_rule.test" - expectedArn := regexp.MustCompile("arn:aws:config:[a-z0-9-]+:[0-9]{12}:config-rule/config-rule-([a-z0-9]+)") - expectedRuleId := regexp.MustCompile("config-rule-[a-z0-9]+") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -54,9 +52,9 @@ func testAccConfigConfigRule_ownerAws(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckConfigConfigRuleExists(resourceName, &cr), testAccCheckConfigConfigRuleName(resourceName, rName, &cr), - resource.TestMatchResourceAttr(resourceName, "arn", expectedArn), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "config", regexp.MustCompile("config-rule/config-rule-[a-z0-9]+$")), resource.TestCheckResourceAttr(resourceName, "name", rName), - resource.TestMatchResourceAttr(resourceName, "rule_id", expectedRuleId), + resource.TestMatchResourceAttr(resourceName, "rule_id", regexp.MustCompile("config-rule-[a-z0-9]+$")), resource.TestCheckResourceAttr(resourceName, "description", "Terraform Acceptance tests"), resource.TestCheckResourceAttr(resourceName, "source.#", "1"), resource.TestCheckResourceAttr(resourceName, "source.0.owner", "AWS"), @@ -75,12 +73,10 @@ func testAccConfigConfigRule_ownerAws(t *testing.T) { func testAccConfigConfigRule_customlambda(t *testing.T) { var cr configservice.ConfigRule rInt := acctest.RandInt() + resourceName := "aws_config_config_rule.test" expectedName := fmt.Sprintf("tf-acc-test-%d", rInt) path := "test-fixtures/lambdatest.zip" - expectedArn := regexp.MustCompile("arn:aws:config:[a-z0-9-]+:[0-9]{12}:config-rule/config-rule-([a-z0-9]+)") - expectedFunctionArn := regexp.MustCompile(fmt.Sprintf("arn:aws:lambda:[a-z0-9-]+:[0-9]{12}:function:tf_acc_lambda_awsconfig_%d", rInt)) - expectedRuleId := regexp.MustCompile("config-rule-[a-z0-9]+") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -90,23 +86,23 @@ func testAccConfigConfigRule_customlambda(t *testing.T) { { Config: testAccConfigConfigRuleConfig_customLambda(rInt, path), Check: resource.ComposeTestCheckFunc( - testAccCheckConfigConfigRuleExists("aws_config_config_rule.foo", &cr), - testAccCheckConfigConfigRuleName("aws_config_config_rule.foo", expectedName, &cr), - resource.TestMatchResourceAttr("aws_config_config_rule.foo", "arn", expectedArn), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "name", expectedName), - resource.TestMatchResourceAttr("aws_config_config_rule.foo", "rule_id", expectedRuleId), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "description", "Terraform Acceptance tests"), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "maximum_execution_frequency", "Six_Hours"), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "source.#", "1"), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "source.0.owner", "CUSTOM_LAMBDA"), - resource.TestMatchResourceAttr("aws_config_config_rule.foo", "source.0.source_identifier", expectedFunctionArn), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "source.0.source_detail.#", "1"), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "source.0.source_detail.3026922761.event_source", "aws.config"), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "source.0.source_detail.3026922761.message_type", "ConfigurationSnapshotDeliveryCompleted"), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "source.0.source_detail.3026922761.maximum_execution_frequency", ""), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "scope.#", "1"), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "scope.0.tag_key", "IsTemporary"), - resource.TestCheckResourceAttr("aws_config_config_rule.foo", "scope.0.tag_value", "yes"), + testAccCheckConfigConfigRuleExists(resourceName, &cr), + testAccCheckConfigConfigRuleName(resourceName, expectedName, &cr), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "config", regexp.MustCompile("config-rule/config-rule-[a-z0-9]+$")), + resource.TestCheckResourceAttr(resourceName, "name", expectedName), + resource.TestMatchResourceAttr(resourceName, "rule_id", regexp.MustCompile("config-rule-[a-z0-9]+$")), + resource.TestCheckResourceAttr(resourceName, "description", "Terraform Acceptance tests"), + resource.TestCheckResourceAttr(resourceName, "maximum_execution_frequency", "Six_Hours"), + resource.TestCheckResourceAttr(resourceName, "source.#", "1"), + resource.TestCheckResourceAttr(resourceName, "source.0.owner", "CUSTOM_LAMBDA"), + resource.TestCheckResourceAttrPair(resourceName, "source.0.source_identifier", "aws_lambda_function.f", "arn"), + resource.TestCheckResourceAttr(resourceName, "source.0.source_detail.#", "1"), + resource.TestCheckResourceAttr(resourceName, "source.0.source_detail.3026922761.event_source", "aws.config"), + resource.TestCheckResourceAttr(resourceName, "source.0.source_detail.3026922761.message_type", "ConfigurationSnapshotDeliveryCompleted"), + resource.TestCheckResourceAttr(resourceName, "source.0.source_detail.3026922761.maximum_execution_frequency", ""), + resource.TestCheckResourceAttr(resourceName, "scope.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scope.0.tag_key", "IsTemporary"), + resource.TestCheckResourceAttr(resourceName, "scope.0.tag_value", "yes"), ), }, }, @@ -136,7 +132,7 @@ func testAccConfigConfigRule_importAws(t *testing.T) { } func testAccConfigConfigRule_importLambda(t *testing.T) { - resourceName := "aws_config_config_rule.foo" + resourceName := "aws_config_config_rule.test" rInt := acctest.RandInt() path := "test-fixtures/lambdatest.zip" @@ -430,7 +426,7 @@ PARAMS func testAccConfigConfigRuleConfig_customLambda(randInt int, path string) string { return fmt.Sprintf(` -resource "aws_config_config_rule" "foo" { +resource "aws_config_config_rule" "test" { name = "tf-acc-test-%d" description = "Terraform Acceptance tests" maximum_execution_frequency = "Six_Hours" diff --git a/aws/resource_aws_config_configuration_aggregator_test.go b/aws/resource_aws_config_configuration_aggregator_test.go index a6e65d76750..19e71c3ce55 100644 --- a/aws/resource_aws_config_configuration_aggregator_test.go +++ b/aws/resource_aws_config_configuration_aggregator_test.go @@ -106,7 +106,7 @@ func TestAccAWSConfigConfigurationAggregator_organization(t *testing.T) { testAccCheckAWSConfigConfigurationAggregatorName(resourceName, rName, &ca), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "organization_aggregation_source.#", "1"), - resource.TestMatchResourceAttr(resourceName, "organization_aggregation_source.0.role_arn", regexp.MustCompile(`^arn:aws:iam::\d+:role/`)), + resource.TestCheckResourceAttrPair(resourceName, "organization_aggregation_source.0.role_arn", "aws_iam_role.r", "arn"), resource.TestCheckResourceAttr(resourceName, "organization_aggregation_source.0.all_regions", "true"), ), }, diff --git a/aws/resource_aws_config_configuration_recorder.go b/aws/resource_aws_config_configuration_recorder.go index e5787e156e1..aa05a0e3ca7 100644 --- a/aws/resource_aws_config_configuration_recorder.go +++ b/aws/resource_aws_config_configuration_recorder.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/configservice" ) @@ -99,7 +98,7 @@ func resourceAwsConfigConfigurationRecorderRead(d *schema.ResourceData, meta int } out, err := conn.DescribeConfigurationRecorders(&input) if err != nil { - if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NoSuchConfigurationRecorderException" { + if isAWSErr(err, configservice.ErrCodeNoSuchConfigurationRecorderException, "") { log.Printf("[WARN] Configuration Recorder %q is gone (NoSuchConfigurationRecorderException)", d.Id()) d.SetId("") return nil @@ -142,8 +141,9 @@ func resourceAwsConfigConfigurationRecorderDelete(d *schema.ResourceData, meta i } _, err := conn.DeleteConfigurationRecorder(&input) if err != nil { - return fmt.Errorf("Deleting Configuration Recorder failed: %s", err) + if !isAWSErr(err, configservice.ErrCodeNoSuchConfigurationRecorderException, "") { + return fmt.Errorf("Deleting Configuration Recorder failed: %s", err) + } } - return nil } diff --git a/aws/resource_aws_config_configuration_recorder_status.go b/aws/resource_aws_config_configuration_recorder_status.go index ed0cfbd51c2..34afae3bb84 100644 --- a/aws/resource_aws_config_configuration_recorder_status.go +++ b/aws/resource_aws_config_configuration_recorder_status.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/configservice" ) @@ -79,12 +78,10 @@ func resourceAwsConfigConfigurationRecorderStatusRead(d *schema.ResourceData, me } statusOut, err := conn.DescribeConfigurationRecorderStatus(&statusInput) if err != nil { - if awsErr, ok := err.(awserr.Error); ok { - if awsErr.Code() == "NoSuchConfigurationRecorderException" { - log.Printf("[WARN] Configuration Recorder (status) %q is gone (NoSuchConfigurationRecorderException)", name) - d.SetId("") - return nil - } + if isAWSErr(err, configservice.ErrCodeNoSuchConfigurationRecorderException, "") { + log.Printf("[WARN] Configuration Recorder (status) %q is gone (NoSuchConfigurationRecorderException)", name) + d.SetId("") + return nil } return fmt.Errorf("Failed describing Configuration Recorder %q status: %s", name, err) diff --git a/aws/resource_aws_config_configuration_recorder_test.go b/aws/resource_aws_config_configuration_recorder_test.go index 7b7baf1c2e3..43933c26667 100644 --- a/aws/resource_aws_config_configuration_recorder_test.go +++ b/aws/resource_aws_config_configuration_recorder_test.go @@ -82,8 +82,6 @@ func testAccConfigConfigurationRecorder_basic(t *testing.T) { testAccCheckConfigConfigurationRecorderRoleArn("aws_config_configuration_recorder.foo", regexp.MustCompile(`arn:aws:iam::[0-9]{12}:role/`+expectedRoleName), &cr), resource.TestCheckResourceAttr("aws_config_configuration_recorder.foo", "name", expectedName), - resource.TestMatchResourceAttr("aws_config_configuration_recorder.foo", "role_arn", - regexp.MustCompile(`arn:aws:iam::[0-9]{12}:role/`+expectedRoleName)), ), }, }, @@ -109,8 +107,6 @@ func testAccConfigConfigurationRecorder_allParams(t *testing.T) { testAccCheckConfigConfigurationRecorderRoleArn("aws_config_configuration_recorder.foo", regexp.MustCompile(`arn:aws:iam::[0-9]{12}:role/`+expectedRoleName), &cr), resource.TestCheckResourceAttr("aws_config_configuration_recorder.foo", "name", expectedName), - resource.TestMatchResourceAttr("aws_config_configuration_recorder.foo", "role_arn", - regexp.MustCompile(`arn:aws:iam::[0-9]{12}:role/`+expectedRoleName)), resource.TestCheckResourceAttr("aws_config_configuration_recorder.foo", "recording_group.#", "1"), resource.TestCheckResourceAttr("aws_config_configuration_recorder.foo", "recording_group.0.all_supported", "false"), resource.TestCheckResourceAttr("aws_config_configuration_recorder.foo", "recording_group.0.include_global_resource_types", "false"), diff --git a/aws/resource_aws_config_delivery_channel_test.go b/aws/resource_aws_config_delivery_channel_test.go index 2097f487b42..e48d9b4d559 100644 --- a/aws/resource_aws_config_delivery_channel_test.go +++ b/aws/resource_aws_config_delivery_channel_test.go @@ -3,7 +3,6 @@ package aws import ( "fmt" "log" - "regexp" "testing" "time" @@ -97,11 +96,11 @@ func testAccConfigDeliveryChannel_basic(t *testing.T) { } func testAccConfigDeliveryChannel_allParams(t *testing.T) { + resourceName := "aws_config_delivery_channel.foo" var dc configservice.DeliveryChannel rInt := acctest.RandInt() expectedName := fmt.Sprintf("tf-acc-test-awsconfig-%d", rInt) expectedBucketName := fmt.Sprintf("tf-acc-test-awsconfig-%d", rInt) - expectedSnsTopicArn := regexp.MustCompile(fmt.Sprintf("arn:aws:sns:[a-z0-9-]+:[0-9]{12}:tf-acc-test-%d", rInt)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -111,13 +110,13 @@ func testAccConfigDeliveryChannel_allParams(t *testing.T) { { Config: testAccConfigDeliveryChannelConfig_allParams(rInt), Check: resource.ComposeTestCheckFunc( - testAccCheckConfigDeliveryChannelExists("aws_config_delivery_channel.foo", &dc), - testAccCheckConfigDeliveryChannelName("aws_config_delivery_channel.foo", expectedName, &dc), - resource.TestCheckResourceAttr("aws_config_delivery_channel.foo", "name", expectedName), - resource.TestCheckResourceAttr("aws_config_delivery_channel.foo", "s3_bucket_name", expectedBucketName), - resource.TestCheckResourceAttr("aws_config_delivery_channel.foo", "s3_key_prefix", "one/two/three"), - resource.TestMatchResourceAttr("aws_config_delivery_channel.foo", "sns_topic_arn", expectedSnsTopicArn), - resource.TestCheckResourceAttr("aws_config_delivery_channel.foo", "snapshot_delivery_properties.0.delivery_frequency", "Six_Hours"), + testAccCheckConfigDeliveryChannelExists(resourceName, &dc), + testAccCheckConfigDeliveryChannelName(resourceName, expectedName, &dc), + resource.TestCheckResourceAttr(resourceName, "name", expectedName), + resource.TestCheckResourceAttr(resourceName, "s3_bucket_name", expectedBucketName), + resource.TestCheckResourceAttr(resourceName, "s3_key_prefix", "one/two/three"), + resource.TestCheckResourceAttrPair(resourceName, "sns_topic_arn", "aws_sns_topic.t", "arn"), + resource.TestCheckResourceAttr(resourceName, "snapshot_delivery_properties.0.delivery_frequency", "Six_Hours"), ), }, },