From 0e9c4617f12cab937c5e9928a81070e6132524bd Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 4 Jan 2021 18:30:52 -0500 Subject: [PATCH 1/4] tests/resource/codebuild_project: Fix hardcoded regions --- aws/resource_aws_codebuild_project_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_codebuild_project_test.go b/aws/resource_aws_codebuild_project_test.go index 4ff33fa4d60..620971eaac5 100644 --- a/aws/resource_aws_codebuild_project_test.go +++ b/aws/resource_aws_codebuild_project_test.go @@ -3398,7 +3398,7 @@ resource "aws_codebuild_project" "test" { func testAccAWSCodeBuildProjectConfig_VpcConfig1(rName string) string { return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` data "aws_availability_zones" "available" { - # InvalidInputException: CodeBuild currently doesn't support VPC in us-west-2d, please select subnets in other availability zones. + # InvalidInputException: CodeBuild currently doesn't support VPC in usw2-az4, please select subnets in other availability zones. exclude_zone_ids = ["usw2-az4"] state = "available" @@ -3459,7 +3459,7 @@ resource "aws_codebuild_project" "test" { func testAccAWSCodeBuildProjectConfig_VpcConfig2(rName string) string { return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` data "aws_availability_zones" "available" { - # InvalidInputException: CodeBuild currently doesn't support VPC in us-west-2d, please select subnets in other availability zones. + # InvalidInputException: CodeBuild currently doesn't support VPC in usw2-az4, please select subnets in other availability zones. exclude_zone_ids = ["usw2-az4"] state = "available" From f493f0fe1b5da84c813a6e2f6bef7aff34015360 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 5 Jan 2021 10:57:24 -0500 Subject: [PATCH 2/4] tests/resource/codebuild_project: Standardized config with composeConfig() --- aws/resource_aws_codebuild_project_test.go | 326 ++++++++++++--------- 1 file changed, 192 insertions(+), 134 deletions(-) diff --git a/aws/resource_aws_codebuild_project_test.go b/aws/resource_aws_codebuild_project_test.go index 620971eaac5..1c93aea9d5c 100644 --- a/aws/resource_aws_codebuild_project_test.go +++ b/aws/resource_aws_codebuild_project_test.go @@ -2295,7 +2295,7 @@ POLICY } func testAccAWSCodeBuildProjectConfig_basic(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2315,11 +2315,11 @@ resource "aws_codebuild_project" "test" { type = "GITHUB" } } -`, rName, testAccAWSCodeBuildGitHubSourceLocationFromEnv()) +`, rName, testAccAWSCodeBuildGitHubSourceLocationFromEnv())) } func testAccAWSCodebuildProjectConfig_BadgeEnabled(rName string, badgeEnabled bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { badge_enabled = %t name = "%s" @@ -2340,11 +2340,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, badgeEnabled, rName) +`, badgeEnabled, rName)) } func testAccAWSCodeBuildProjectConfig_BuildTimeout(rName string, buildTimeout int) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { build_timeout = %d name = "%s" @@ -2365,11 +2365,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, buildTimeout, rName) +`, buildTimeout, rName)) } func testAccAWSCodeBuildProjectConfig_QueuedTimeout(rName string, queuedTimeout int) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { queued_timeout = %d name = "%s" @@ -2390,11 +2390,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, queuedTimeout, rName) +`, queuedTimeout, rName)) } func testAccAWSCodeBuildProjectConfig_Cache(rName, cacheLocation, cacheType string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2419,11 +2419,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, cacheLocation, cacheType) +`, rName, cacheLocation, cacheType)) } func testAccAWSCodeBuildProjectConfig_LocalCache(rName, modeType string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2448,11 +2448,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, modeType) +`, rName, modeType)) } func testAccAWSCodeBuildProjectConfig_Description(rName, description string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { description = "%s" name = "%s" @@ -2473,11 +2473,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, description, rName) +`, description, rName)) } func testAccAWSCodeBuildProjectConfig_SourceVersion(rName, sourceVersion string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2499,11 +2499,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, sourceVersion) +`, rName, sourceVersion)) } func testAccAWSCodeBuildProjectConfig_EncryptionKey(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_kms_key" "test" { description = "Terraform acc test" deletion_window_in_days = 7 @@ -2529,11 +2529,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName) +`, rName)) } func testAccAWSCodeBuildProjectConfig_Environment_EnvironmentVariable_One(rName, key1, value1 string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -2558,11 +2558,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, key1, value1) +`, rName, key1, value1)) } func testAccAWSCodeBuildProjectConfig_Environment_EnvironmentVariable_Two(rName, key1, value1, key2, value2 string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -2592,11 +2592,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, key1, value1, key2, value2) +`, rName, key1, value1, key2, value2)) } func testAccAWSCodeBuildProjectConfig_Environment_EnvironmentVariable_Zero(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -2616,11 +2616,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName) +`, rName)) } func testAccAWSCodeBuildProjectConfig_Environment_EnvironmentVariable_Type(rName, environmentVariableType string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2651,11 +2651,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, environmentVariableType) +`, rName, environmentVariableType)) } func testAccAWSCodeBuildProjectConfig_Environment_Certificate(rName string, bName string, oName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_s3_bucket_object" "test" { bucket = aws_s3_bucket.test.bucket key = "%s" @@ -2682,11 +2685,11 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, oName, rName) +`, oName, rName)) } func testAccAWSCodeBuildProjectConfig_Environment_RegistryCredential1(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -2722,11 +2725,11 @@ resource "aws_secretsmanager_secret_version" "test" { secret_id = aws_secretsmanager_secret.test.id secret_string = jsonencode(map("username", "user", "password", "pass")) } -`, rName) +`, rName)) } func testAccAWSCodeBuildProjectConfig_Environment_RegistryCredential2(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -2762,11 +2765,11 @@ resource "aws_secretsmanager_secret_version" "test" { secret_id = aws_secretsmanager_secret.test.id secret_string = jsonencode(map("username", "user", "password", "pass")) } -`, rName) +`, rName)) } func testAccAWSCodeBuildProjectConfig_LogsConfig_CloudWatchLogs(rName, status, gName, sName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2794,11 +2797,14 @@ resource "aws_codebuild_project" "test" { } } } -`, rName, status, gName, sName) +`, rName, status, gName, sName)) } func testAccAWSCodeBuildProjectConfig_LogsConfig_S3Logs(rName, bName, status, location string, encryptionDisabled bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2826,11 +2832,11 @@ resource "aws_codebuild_project" "test" { } } } -`, rName, status, location, encryptionDisabled) +`, rName, status, location, encryptionDisabled)) } func testAccAWSCodeBuildProjectConfig_Source_Auth(rName, authResource, authType string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2855,11 +2861,11 @@ resource "aws_codebuild_project" "test" { } } } -`, rName, authResource, authType) +`, rName, authResource, authType)) } func testAccAWSCodeBuildProjectConfig_Source_GitCloneDepth(rName string, gitCloneDepth int) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2880,11 +2886,11 @@ resource "aws_codebuild_project" "test" { type = "GITHUB" } } -`, rName, gitCloneDepth) +`, rName, gitCloneDepth)) } func testAccAWSCodeBuildProjectConfig_Source_GitSubmodulesConfig_CodeCommit(rName string, fetchSubmodules bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2908,11 +2914,11 @@ resource "aws_codebuild_project" "test" { } } } -`, rName, fetchSubmodules) +`, rName, fetchSubmodules)) } func testAccAWSCodeBuildProjectConfig_Source_GitSubmodulesConfig_GitHub(rName string, fetchSubmodules bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2936,11 +2942,11 @@ resource "aws_codebuild_project" "test" { } } } -`, rName, fetchSubmodules) +`, rName, fetchSubmodules)) } func testAccAWSCodeBuildProjectConfig_Source_GitSubmodulesConfig_GitHubEnterprise(rName string, fetchSubmodules bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -2964,11 +2970,11 @@ resource "aws_codebuild_project" "test" { } } } -`, rName, fetchSubmodules) +`, rName, fetchSubmodules)) } func testAccAWSCodeBuildProjectConfig_SecondarySources_GitSubmodulesConfig_CodeCommit(rName string, fetchSubmodules bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%[1]s" service_role = aws_iam_role.test.arn @@ -3012,11 +3018,11 @@ resource "aws_codebuild_project" "test" { } } } -`, rName, fetchSubmodules) +`, rName, fetchSubmodules)) } func testAccAWSCodeBuildProjectConfig_SecondarySources_GitSubmodulesConfig_GitHub(rName string, fetchSubmodules bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%[1]s" service_role = aws_iam_role.test.arn @@ -3060,11 +3066,11 @@ resource "aws_codebuild_project" "test" { } } } -`, rName, fetchSubmodules) +`, rName, fetchSubmodules)) } func testAccAWSCodeBuildProjectConfig_SecondarySources_GitSubmodulesConfig_GitHubEnterprise(rName string, fetchSubmodules bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%[1]s" service_role = aws_iam_role.test.arn @@ -3108,11 +3114,11 @@ resource "aws_codebuild_project" "test" { } } } -`, rName, fetchSubmodules) +`, rName, fetchSubmodules)) } func testAccAWSCodeBuildProjectConfig_Source_InsecureSSL(rName string, insecureSSL bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -3133,11 +3139,11 @@ resource "aws_codebuild_project" "test" { type = "GITHUB" } } -`, rName, insecureSSL) +`, rName, insecureSSL)) } func testAccAWSCodeBuildProjectConfig_Source_ReportBuildStatus_Bitbucket(rName string, reportBuildStatus bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %q service_role = aws_iam_role.test.arn @@ -3158,11 +3164,11 @@ resource "aws_codebuild_project" "test" { type = "BITBUCKET" } } -`, rName, reportBuildStatus) +`, rName, reportBuildStatus)) } func testAccAWSCodeBuildProjectConfig_Source_ReportBuildStatus_GitHub(rName string, reportBuildStatus bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %q service_role = aws_iam_role.test.arn @@ -3183,11 +3189,11 @@ resource "aws_codebuild_project" "test" { type = "GITHUB" } } -`, rName, reportBuildStatus) +`, rName, reportBuildStatus)) } func testAccAWSCodeBuildProjectConfig_Source_ReportBuildStatus_GitHubEnterprise(rName string, reportBuildStatus bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %q service_role = aws_iam_role.test.arn @@ -3208,11 +3214,11 @@ resource "aws_codebuild_project" "test" { type = "GITHUB_ENTERPRISE" } } -`, rName, reportBuildStatus) +`, rName, reportBuildStatus)) } func testAccAWSCodeBuildProjectConfig_Source_Type_Bitbucket(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %q service_role = aws_iam_role.test.arn @@ -3232,11 +3238,11 @@ resource "aws_codebuild_project" "test" { type = "BITBUCKET" } } -`, rName, testAccAWSCodeBuildBitbucketSourceLocationFromEnv()) +`, rName, testAccAWSCodeBuildBitbucketSourceLocationFromEnv())) } func testAccAWSCodeBuildProjectConfig_Source_Type_CodeCommit(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %q service_role = aws_iam_role.test.arn @@ -3256,11 +3262,11 @@ resource "aws_codebuild_project" "test" { type = "CODECOMMIT" } } -`, rName) +`, rName)) } func testAccAWSCodeBuildProjectConfig_Source_Type_CodePipeline(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %q service_role = aws_iam_role.test.arn @@ -3279,11 +3285,11 @@ resource "aws_codebuild_project" "test" { type = "CODEPIPELINE" } } -`, rName) +`, rName)) } func testAccAWSCodeBuildProjectConfig_Source_Type_GitHubEnterprise(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %q service_role = aws_iam_role.test.arn @@ -3303,11 +3309,11 @@ resource "aws_codebuild_project" "test" { type = "GITHUB_ENTERPRISE" } } -`, rName) +`, rName)) } func testAccAWSCodeBuildProjectConfig_Source_Type_S3(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_s3_bucket" "test" { bucket = %[1]q } @@ -3337,11 +3343,11 @@ resource "aws_codebuild_project" "test" { type = "S3" } } -`, rName) +`, rName)) } func testAccAWSCodeBuildProjectConfig_Source_Type_NoSource(rName string, rLocation string, rBuildspec string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %q service_role = aws_iam_role.test.arn @@ -3362,11 +3368,11 @@ resource "aws_codebuild_project" "test" { buildspec = %q } } -`, rName, rLocation, rBuildspec) +`, rName, rLocation, rBuildspec)) } func testAccAWSCodeBuildProjectConfig_Tags(rName, tagKey, tagValue string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -3392,11 +3398,14 @@ resource "aws_codebuild_project" "test" { %s = "%s" } } -`, rName, tagKey, tagValue) +`, rName, tagKey, tagValue)) } func testAccAWSCodeBuildProjectConfig_VpcConfig1(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAvailableAZsNoOptInConfig(), + fmt.Sprintf(` data "aws_availability_zones" "available" { # InvalidInputException: CodeBuild currently doesn't support VPC in usw2-az4, please select subnets in other availability zones. exclude_zone_ids = ["usw2-az4"] @@ -3453,22 +3462,14 @@ resource "aws_codebuild_project" "test" { vpc_id = aws_vpc.test.id } } -`, rName) +`, rName)) } func testAccAWSCodeBuildProjectConfig_VpcConfig2(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` -data "aws_availability_zones" "available" { - # InvalidInputException: CodeBuild currently doesn't support VPC in usw2-az4, please select subnets in other availability zones. - exclude_zone_ids = ["usw2-az4"] - state = "available" - - filter { - name = "opt-in-status" - values = ["opt-in-not-required"] - } -} - + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAvailableAZsNoOptInConfig(), + fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" } @@ -3477,7 +3478,7 @@ resource "aws_subnet" "test" { count = 2 availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = "10.0.${count.index}.0/24" + cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, 0) vpc_id = aws_vpc.test.id tags = { @@ -3514,11 +3515,11 @@ resource "aws_codebuild_project" "test" { vpc_id = aws_vpc.test.id } } -`, rName) +`, rName)) } func testAccAWSCodeBuildProjectConfig_WindowsServer2019Container(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -3538,11 +3539,11 @@ resource "aws_codebuild_project" "test" { type = "GITHUB" } } -`, rName, testAccAWSCodeBuildGitHubSourceLocationFromEnv()) +`, rName, testAccAWSCodeBuildGitHubSourceLocationFromEnv())) } func testAccAWSCodeBuildProjectConfig_ARMContainer(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -3562,11 +3563,14 @@ resource "aws_codebuild_project" "test" { type = "GITHUB" } } -`, rName, testAccAWSCodeBuildGitHubSourceLocationFromEnv()) +`, rName, testAccAWSCodeBuildGitHubSourceLocationFromEnv())) } func testAccAWSCodebuildProjectConfig_Artifacts_ArtifactIdentifier(rName string, bName string, artifactIdentifier string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3588,11 +3592,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, artifactIdentifier) +`, rName, artifactIdentifier)) } func testAccAWSCodebuildProjectConfig_Artifacts_EncryptionDisabled(rName string, bName string, encryptionDisabled bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -3614,11 +3621,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, encryptionDisabled) +`, rName, encryptionDisabled)) } func testAccAWSCodebuildProjectConfig_Artifacts_Location(rName, bName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3639,11 +3649,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName) +`, rName)) } func testAccAWSCodebuildProjectConfig_Artifacts_Name(rName string, bName string, name string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3665,11 +3678,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, name) +`, rName, name)) } func testAccAWSCodebuildProjectConfig_Artifacts_NamespaceType(rName, namespaceType string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3691,11 +3707,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, namespaceType) +`, rName, namespaceType)) } func testAccAWSCodebuildProjectConfig_Artifacts_OverrideArtifactName(rName string, bName string, overrideArtifactName bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -3717,11 +3736,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, overrideArtifactName) +`, rName, overrideArtifactName)) } func testAccAWSCodebuildProjectConfig_Artifacts_Packaging(rName, packaging string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3743,11 +3765,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, packaging) +`, rName, packaging)) } func testAccAWSCodebuildProjectConfig_Artifacts_Path(rName, path string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3769,11 +3794,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, path) +`, rName, path)) } func testAccAWSCodebuildProjectConfig_Artifacts_Type(rName string, bName string, artifactType string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3794,11 +3822,14 @@ resource "aws_codebuild_project" "test" { location = "${aws_s3_bucket.test.bucket}/" } } -`, rName, artifactType) +`, rName, artifactType)) } func testAccAWSCodebuildProjectConfig_SecondaryArtifacts(rName string, bName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -3831,11 +3862,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName) +`, rName)) } func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_ArtifactIdentifier(rName string, bName string, artifactIdentifier string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3862,11 +3896,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, artifactIdentifier) +`, rName, artifactIdentifier)) } func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_EncryptionDisabled(rName string, bName string, encryptionDisabled bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -3894,11 +3931,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, encryptionDisabled) +`, rName, encryptionDisabled)) } func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Location(rName, bName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3925,11 +3965,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName) +`, rName)) } func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Name(rName string, bName string, name string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3957,11 +4000,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, name) +`, rName, name)) } func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_NamespaceType(rName, namespaceType string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -3989,11 +4035,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, namespaceType) +`, rName, namespaceType)) } func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_OverrideArtifactName(rName string, bName string, overrideArtifactName bool) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = "%s" service_role = aws_iam_role.test.arn @@ -4021,11 +4070,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, overrideArtifactName) +`, rName, overrideArtifactName)) } func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Packaging(rName, packaging string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -4053,11 +4105,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, packaging) +`, rName, packaging)) } func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Path(rName, path string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -4085,11 +4140,14 @@ resource "aws_codebuild_project" "test" { location = "https://github.com/hashicorp/packer.git" } } -`, rName, path) +`, rName, path)) } func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Type(rName string, bName string, artifactType string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` + return composeConfig( + testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName), + fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %[1]q service_role = aws_iam_role.test.arn @@ -4116,11 +4174,11 @@ resource "aws_codebuild_project" "test" { type = "CODECOMMIT" } } -`, rName, artifactType) +`, rName, artifactType)) } func testAccAWSCodeBuildProjectConfig_SecondarySources_CodeCommit(rName string) string { - return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` + return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(` resource "aws_codebuild_project" "test" { name = %q service_role = aws_iam_role.test.arn @@ -4152,5 +4210,5 @@ resource "aws_codebuild_project" "test" { source_identifier = "secondarySource2" } } -`, rName) +`, rName)) } From b3dc0ebb29473dce2c79f97ab9b5f4bb55af4f03 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 5 Jan 2021 11:00:16 -0500 Subject: [PATCH 3/4] tests/resource/codebuild_project: Fix duplicate AZ config --- aws/resource_aws_codebuild_project_test.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/aws/resource_aws_codebuild_project_test.go b/aws/resource_aws_codebuild_project_test.go index 1c93aea9d5c..2982f1ce2c0 100644 --- a/aws/resource_aws_codebuild_project_test.go +++ b/aws/resource_aws_codebuild_project_test.go @@ -3406,17 +3406,6 @@ func testAccAWSCodeBuildProjectConfig_VpcConfig1(rName string) string { testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), testAccAvailableAZsNoOptInConfig(), fmt.Sprintf(` -data "aws_availability_zones" "available" { - # InvalidInputException: CodeBuild currently doesn't support VPC in usw2-az4, please select subnets in other availability zones. - exclude_zone_ids = ["usw2-az4"] - state = "available" - - filter { - name = "opt-in-status" - values = ["opt-in-not-required"] - } -} - resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" } From 76c0f34f50cc74cde2d9a6aaf2cfbd08ba598cfa Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 5 Jan 2021 11:13:18 -0500 Subject: [PATCH 4/4] tests/resource/codebuild_project: Fix VPC issue --- aws/resource_aws_codebuild_project_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_codebuild_project_test.go b/aws/resource_aws_codebuild_project_test.go index 2982f1ce2c0..fa27484da2f 100644 --- a/aws/resource_aws_codebuild_project_test.go +++ b/aws/resource_aws_codebuild_project_test.go @@ -3467,7 +3467,7 @@ resource "aws_subnet" "test" { count = 2 availability_zone = data.aws_availability_zones.available.names[count.index] - cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, 0) + cidr_block = "10.0.${count.index}.0/24" vpc_id = aws_vpc.test.id tags = {