diff --git a/.changelog/12130.txt b/.changelog/12130.txt new file mode 100644 index 00000000000..8a47d1df19f --- /dev/null +++ b/.changelog/12130.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_codebuild_project: Add `file_system_locations` argument +``` \ No newline at end of file diff --git a/aws/resource_aws_codebuild_project.go b/aws/resource_aws_codebuild_project.go index 268d0423be2..ac1a15326cf 100644 --- a/aws/resource_aws_codebuild_project.go +++ b/aws/resource_aws_codebuild_project.go @@ -274,6 +274,36 @@ func resourceAwsCodeBuildProject() *schema.Resource { }, }, }, + "file_system_locations": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "identifier": { + Type: schema.TypeString, + Optional: true, + }, + "location": { + Type: schema.TypeString, + Optional: true, + }, + "mount_options": { + Type: schema.TypeString, + Optional: true, + }, + "mount_point": { + Type: schema.TypeString, + Optional: true, + }, + "type": { + Type: schema.TypeString, + Optional: true, + Default: codebuild.FileSystemTypeEfs, + ValidateFunc: validation.StringInSlice(codebuild.FileSystemType_Values(), false), + }, + }, + }, + }, "logs_config": { Type: schema.TypeList, Optional: true, @@ -659,6 +689,7 @@ func resourceAwsCodeBuildProjectCreate(d *schema.ResourceData, meta interface{}) projectSecondarySources := expandProjectSecondarySources(d) projectLogsConfig := expandProjectLogsConfig(d) projectBatchConfig := expandCodeBuildBuildBatchConfig(d) + projectFileSystemLocations := expandProjectFileSystemLocations(d) if aws.StringValue(projectSource.Type) == codebuild.SourceTypeNoSource { if aws.StringValue(projectSource.Buildspec) == "" { @@ -671,15 +702,16 @@ func resourceAwsCodeBuildProjectCreate(d *schema.ResourceData, meta interface{}) } params := &codebuild.CreateProjectInput{ - Environment: projectEnv, - Name: aws.String(d.Get("name").(string)), - Source: &projectSource, - Artifacts: &projectArtifacts, - SecondaryArtifacts: projectSecondaryArtifacts, - SecondarySources: projectSecondarySources, - LogsConfig: projectLogsConfig, - BuildBatchConfig: projectBatchConfig, - Tags: tags.IgnoreAws().CodebuildTags(), + Environment: projectEnv, + Name: aws.String(d.Get("name").(string)), + Source: &projectSource, + Artifacts: &projectArtifacts, + SecondaryArtifacts: projectSecondaryArtifacts, + SecondarySources: projectSecondarySources, + LogsConfig: projectLogsConfig, + BuildBatchConfig: projectBatchConfig, + FileSystemLocations: projectFileSystemLocations, + Tags: tags.IgnoreAws().CodebuildTags(), } if v, ok := d.GetOk("cache"); ok { @@ -753,6 +785,47 @@ func resourceAwsCodeBuildProjectCreate(d *schema.ResourceData, meta interface{}) return resourceAwsCodeBuildProjectRead(d, meta) } +func expandProjectFileSystemLocations(d *schema.ResourceData) []*codebuild.ProjectFileSystemLocation { + fileSystemLocations := make([]*codebuild.ProjectFileSystemLocation, 0) + + configsList := d.Get("file_system_locations").(*schema.Set).List() + + if len(configsList) == 0 { + return nil + } + + for _, config := range configsList { + art := expandProjectFileSystemLocation(config.(map[string]interface{})) + fileSystemLocations = append(fileSystemLocations, &art) + } + + return fileSystemLocations +} + +func expandProjectFileSystemLocation(data map[string]interface{}) codebuild.ProjectFileSystemLocation { + projectFileSystemLocation := codebuild.ProjectFileSystemLocation{ + Type: aws.String(data["type"].(string)), + } + + if data["identifier"].(string) != "" { + projectFileSystemLocation.Identifier = aws.String(data["identifier"].(string)) + } + + if data["location"].(string) != "" { + projectFileSystemLocation.Location = aws.String(data["location"].(string)) + } + + if data["mount_options"].(string) != "" { + projectFileSystemLocation.MountOptions = aws.String(data["mount_options"].(string)) + } + + if data["mount_point"].(string) != "" { + projectFileSystemLocation.MountPoint = aws.String(data["mount_point"].(string)) + } + + return projectFileSystemLocation +} + func expandProjectSecondaryArtifacts(d *schema.ResourceData) []*codebuild.ProjectArtifacts { artifacts := make([]*codebuild.ProjectArtifacts, 0) @@ -1191,6 +1264,10 @@ func resourceAwsCodeBuildProjectRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("error setting environment: %s", err) } + if err := d.Set("file_system_locations", flattenAwsCodeBuildProjectFileSystemLocations(project.FileSystemLocations)); err != nil { + return fmt.Errorf("error setting file_system_locations: %s", err) + } + if err := d.Set("cache", flattenAwsCodebuildProjectCache(project.Cache)); err != nil { return fmt.Errorf("error setting cache: %s", err) } @@ -1264,6 +1341,11 @@ func resourceAwsCodeBuildProjectUpdate(d *schema.ResourceData, meta interface{}) params.Environment = projectEnv } + if d.HasChange("file_system_locations") { + projectFileSystemLocations := expandProjectFileSystemLocations(d) + params.FileSystemLocations = projectFileSystemLocations + } + if d.HasChange("source") { projectSource := expandProjectSource(d) params.Source = &projectSource @@ -1394,6 +1476,54 @@ func resourceAwsCodeBuildProjectDelete(d *schema.ResourceData, meta interface{}) return err } +func flattenAwsCodeBuildProjectFileSystemLocations(apiObjects []*codebuild.ProjectFileSystemLocation) []interface{} { + if len(apiObjects) == 0 { + return nil + } + + var tfList []interface{} + + for _, apiObject := range apiObjects { + if apiObject == nil { + continue + } + + tfList = append(tfList, flattenAwsCodeBuildProjectFileSystemLocation(apiObject)) + } + + return tfList +} + +func flattenAwsCodeBuildProjectFileSystemLocation(apiObject *codebuild.ProjectFileSystemLocation) map[string]interface{} { + if apiObject == nil { + return nil + } + + tfMap := map[string]interface{}{} + + if v := apiObject.Identifier; v != nil { + tfMap["identifier"] = aws.StringValue(v) + } + + if v := apiObject.Location; v != nil { + tfMap["location"] = aws.StringValue(v) + } + + if v := apiObject.MountOptions; v != nil { + tfMap["mount_options"] = aws.StringValue(v) + } + + if v := apiObject.MountPoint; v != nil { + tfMap["mount_point"] = aws.StringValue(v) + } + + if v := apiObject.Type; v != nil { + tfMap["type"] = aws.StringValue(v) + } + + return tfMap +} + func flattenAwsCodeBuildLogsConfig(logsConfig *codebuild.LogsConfig) []interface{} { if logsConfig == nil { return []interface{}{} diff --git a/aws/resource_aws_codebuild_project_test.go b/aws/resource_aws_codebuild_project_test.go index 5762435e49f..9fd5d51380a 100644 --- a/aws/resource_aws_codebuild_project_test.go +++ b/aws/resource_aws_codebuild_project_test.go @@ -203,6 +203,8 @@ func TestAccAWSCodeBuildProject_Cache(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_codebuild_project.test" + s3Location1 := rName + "-1" + s3Location2 := rName + "-2" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, @@ -236,20 +238,20 @@ func TestAccAWSCodeBuildProject_Cache(t *testing.T) { ), }, { - Config: testAccAWSCodeBuildProjectConfig_Cache(rName, "some-bucket", "S3"), + Config: testAccAWSCodeBuildProjectConfig_Cache(rName, s3Location1, "S3"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "cache.#", "1"), - resource.TestCheckResourceAttr(resourceName, "cache.0.location", "some-bucket"), + resource.TestCheckResourceAttr(resourceName, "cache.0.location", s3Location1), resource.TestCheckResourceAttr(resourceName, "cache.0.type", "S3"), ), }, { - Config: testAccAWSCodeBuildProjectConfig_Cache(rName, "some-new-bucket", "S3"), + Config: testAccAWSCodeBuildProjectConfig_Cache(rName, s3Location2, "S3"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "cache.#", "1"), - resource.TestCheckResourceAttr(resourceName, "cache.0.location", "some-new-bucket"), + resource.TestCheckResourceAttr(resourceName, "cache.0.location", s3Location2), resource.TestCheckResourceAttr(resourceName, "cache.0.type", "S3"), ), }, @@ -308,6 +310,56 @@ func TestAccAWSCodeBuildProject_Description(t *testing.T) { }) } +func TestAccAWSCodeBuildProject_FileSystemLocations(t *testing.T) { + var project codebuild.Project + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_project.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + ErrorCheck: testAccErrorCheck(t, codebuild.EndpointsID, "efs"), //using efs.EndpointsID will import efs and make linters sad + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeBuildProjectConfig_FileSystemLocations(rName, "/mount1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "environment.#", "1"), + resource.TestCheckResourceAttr(resourceName, "environment.0.compute_type", codebuild.ComputeTypeBuildGeneral1Small), + resource.TestCheckResourceAttr(resourceName, "environment.0.environment_variable.#", "0"), + resource.TestCheckResourceAttr(resourceName, "environment.0.image", "2"), + resource.TestCheckResourceAttr(resourceName, "environment.0.privileged_mode", "true"), + resource.TestCheckResourceAttr(resourceName, "environment.0.type", codebuild.EnvironmentTypeLinuxContainer), + resource.TestCheckResourceAttr(resourceName, "file_system_locations.#", "1"), + resource.TestCheckResourceAttr(resourceName, "file_system_locations.0.identifier", "test"), + resource.TestMatchResourceAttr(resourceName, "file_system_locations.0.location", regexp.MustCompile(`/directory-path$`)), + resource.TestCheckResourceAttr(resourceName, "file_system_locations.0.mount_options", "nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=450,retrans=3"), + resource.TestCheckResourceAttr(resourceName, "file_system_locations.0.mount_point", "/mount1"), + resource.TestCheckResourceAttr(resourceName, "file_system_locations.0.type", codebuild.FileSystemTypeEfs), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodeBuildProjectConfig_FileSystemLocations(rName, "/mount2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "file_system_locations.#", "1"), + resource.TestCheckResourceAttr(resourceName, "file_system_locations.0.identifier", "test"), + resource.TestMatchResourceAttr(resourceName, "file_system_locations.0.location", regexp.MustCompile(`/directory-path$`)), + resource.TestCheckResourceAttr(resourceName, "file_system_locations.0.mount_options", "nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=450,retrans=3"), + resource.TestCheckResourceAttr(resourceName, "file_system_locations.0.mount_point", "/mount2"), + resource.TestCheckResourceAttr(resourceName, "file_system_locations.0.type", codebuild.FileSystemTypeEfs), + ), + }, + }, + }) +} + func TestAccAWSCodeBuildProject_SourceVersion(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") @@ -501,7 +553,6 @@ func TestAccAWSCodeBuildProject_Environment_EnvironmentVariable_Value(t *testing func TestAccAWSCodeBuildProject_Environment_Certificate(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") oName := "certificate.pem" resourceName := "aws_codebuild_project.test" @@ -512,10 +563,10 @@ func TestAccAWSCodeBuildProject_Environment_Certificate(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodeBuildProjectConfig_Environment_Certificate(rName, bName, oName), + Config: testAccAWSCodeBuildProjectConfig_Environment_Certificate(rName, oName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), - testAccCheckAWSCodeBuildProjectCertificate(&project, fmt.Sprintf("%s/%s", bName, oName)), + testAccCheckAWSCodeBuildProjectCertificate(&project, fmt.Sprintf("%s/%s", rName, oName)), ), }, { @@ -575,7 +626,6 @@ func TestAccAWSCodeBuildProject_LogsConfig_CloudWatchLogs(t *testing.T) { func TestAccAWSCodeBuildProject_LogsConfig_S3Logs(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" resource.ParallelTest(t, resource.TestCase{ @@ -585,25 +635,25 @@ func TestAccAWSCodeBuildProject_LogsConfig_S3Logs(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodeBuildProjectConfig_LogsConfig_S3Logs(rName, bName, codebuild.LogsConfigStatusTypeEnabled, bName+"/build-log", false), + Config: testAccAWSCodeBuildProjectConfig_LogsConfig_S3Logs(rName, codebuild.LogsConfigStatusTypeEnabled, rName+"/build-log", false), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "logs_config.0.s3_logs.0.status", codebuild.LogsConfigStatusTypeEnabled), - resource.TestMatchResourceAttr(resourceName, "logs_config.0.s3_logs.0.location", regexp.MustCompile(`tf-acc-test-bucket-[0-9]+/build-log$`)), + resource.TestCheckResourceAttr(resourceName, "logs_config.0.s3_logs.0.location", rName+"/build-log"), resource.TestCheckResourceAttr(resourceName, "logs_config.0.s3_logs.0.encryption_disabled", "false"), ), }, { - Config: testAccAWSCodeBuildProjectConfig_LogsConfig_S3Logs(rName, bName, codebuild.LogsConfigStatusTypeEnabled, bName+"/build-log", true), + Config: testAccAWSCodeBuildProjectConfig_LogsConfig_S3Logs(rName, codebuild.LogsConfigStatusTypeEnabled, rName+"/build-log", true), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "logs_config.0.s3_logs.0.status", codebuild.LogsConfigStatusTypeEnabled), - resource.TestMatchResourceAttr(resourceName, "logs_config.0.s3_logs.0.location", regexp.MustCompile(`tf-acc-test-bucket-[0-9]+/build-log$`)), + resource.TestCheckResourceAttr(resourceName, "logs_config.0.s3_logs.0.location", rName+"/build-log"), resource.TestCheckResourceAttr(resourceName, "logs_config.0.s3_logs.0.encryption_disabled", "true"), ), }, { - Config: testAccAWSCodeBuildProjectConfig_LogsConfig_S3Logs(rName, bName, codebuild.LogsConfigStatusTypeDisabled, "", false), + Config: testAccAWSCodeBuildProjectConfig_LogsConfig_S3Logs(rName, codebuild.LogsConfigStatusTypeDisabled, "", false), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "logs_config.0.s3_logs.0.status", codebuild.LogsConfigStatusTypeDisabled), @@ -1434,7 +1484,6 @@ func TestAccAWSCodeBuildProject_ARMContainer(t *testing.T) { func TestAccAWSCodeBuildProject_Artifacts_ArtifactIdentifier(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" artifactIdentifier1 := "artifactIdentifier1" @@ -1447,7 +1496,7 @@ func TestAccAWSCodeBuildProject_Artifacts_ArtifactIdentifier(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_Artifacts_ArtifactIdentifier(rName, bName, artifactIdentifier1), + Config: testAccAWSCodebuildProjectConfig_Artifacts_ArtifactIdentifier(rName, artifactIdentifier1), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), @@ -1460,7 +1509,7 @@ func TestAccAWSCodeBuildProject_Artifacts_ArtifactIdentifier(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_Artifacts_ArtifactIdentifier(rName, bName, artifactIdentifier2), + Config: testAccAWSCodebuildProjectConfig_Artifacts_ArtifactIdentifier(rName, artifactIdentifier2), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), @@ -1474,7 +1523,6 @@ func TestAccAWSCodeBuildProject_Artifacts_ArtifactIdentifier(t *testing.T) { func TestAccAWSCodeBuildProject_Artifacts_EncryptionDisabled(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" resource.ParallelTest(t, resource.TestCase{ @@ -1484,7 +1532,7 @@ func TestAccAWSCodeBuildProject_Artifacts_EncryptionDisabled(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_Artifacts_EncryptionDisabled(rName, bName, true), + Config: testAccAWSCodebuildProjectConfig_Artifacts_EncryptionDisabled(rName, true), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), @@ -1497,7 +1545,7 @@ func TestAccAWSCodeBuildProject_Artifacts_EncryptionDisabled(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_Artifacts_EncryptionDisabled(rName, bName, false), + Config: testAccAWSCodebuildProjectConfig_Artifacts_EncryptionDisabled(rName, false), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), @@ -1510,9 +1558,8 @@ func TestAccAWSCodeBuildProject_Artifacts_EncryptionDisabled(t *testing.T) { func TestAccAWSCodeBuildProject_Artifacts_Location(t *testing.T) { var project codebuild.Project - rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") - bName2 := acctest.RandomWithPrefix("tf-acc-test-bucket2") + rName1 := acctest.RandomWithPrefix("tf-acc-test") + rName2 := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_codebuild_project.test" resource.ParallelTest(t, resource.TestCase{ @@ -1522,11 +1569,11 @@ func TestAccAWSCodeBuildProject_Artifacts_Location(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_Artifacts_Location(rName, bName), + Config: testAccAWSCodebuildProjectConfig_Artifacts_Location(rName1, rName1), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), - resource.TestCheckResourceAttr(resourceName, "artifacts.0.location", bName), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.location", rName1), ), }, { @@ -1535,11 +1582,11 @@ func TestAccAWSCodeBuildProject_Artifacts_Location(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_Artifacts_Location(rName, bName2), + Config: testAccAWSCodebuildProjectConfig_Artifacts_Location(rName1, rName2), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), - resource.TestCheckResourceAttr(resourceName, "artifacts.0.location", bName2), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.location", rName2), ), }, }, @@ -1549,7 +1596,6 @@ func TestAccAWSCodeBuildProject_Artifacts_Location(t *testing.T) { func TestAccAWSCodeBuildProject_Artifacts_Name(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" name1 := "name1" @@ -1562,7 +1608,7 @@ func TestAccAWSCodeBuildProject_Artifacts_Name(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_Artifacts_Name(rName, bName, name1), + Config: testAccAWSCodebuildProjectConfig_Artifacts_Name(rName, name1), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), @@ -1575,7 +1621,7 @@ func TestAccAWSCodeBuildProject_Artifacts_Name(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_Artifacts_Name(rName, bName, name2), + Config: testAccAWSCodebuildProjectConfig_Artifacts_Name(rName, name2), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), @@ -1625,7 +1671,6 @@ func TestAccAWSCodeBuildProject_Artifacts_NamespaceType(t *testing.T) { func TestAccAWSCodeBuildProject_Artifacts_OverrideArtifactName(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" resource.ParallelTest(t, resource.TestCase{ @@ -1635,7 +1680,7 @@ func TestAccAWSCodeBuildProject_Artifacts_OverrideArtifactName(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_Artifacts_OverrideArtifactName(rName, bName, true), + Config: testAccAWSCodebuildProjectConfig_Artifacts_OverrideArtifactName(rName, true), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), @@ -1648,7 +1693,7 @@ func TestAccAWSCodeBuildProject_Artifacts_OverrideArtifactName(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_Artifacts_OverrideArtifactName(rName, bName, false), + Config: testAccAWSCodebuildProjectConfig_Artifacts_OverrideArtifactName(rName, false), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), @@ -1734,7 +1779,6 @@ func TestAccAWSCodeBuildProject_Artifacts_Path(t *testing.T) { func TestAccAWSCodeBuildProject_Artifacts_Type(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" type1 := codebuild.ArtifactsTypeS3 @@ -1747,7 +1791,7 @@ func TestAccAWSCodeBuildProject_Artifacts_Type(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_Artifacts_Type(rName, bName, type1), + Config: testAccAWSCodebuildProjectConfig_Artifacts_Type(rName, type1), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), @@ -1760,7 +1804,7 @@ func TestAccAWSCodeBuildProject_Artifacts_Type(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_Artifacts_Type(rName, bName, type2), + Config: testAccAWSCodebuildProjectConfig_Artifacts_Type(rName, type2), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), @@ -1774,7 +1818,6 @@ func TestAccAWSCodeBuildProject_Artifacts_Type(t *testing.T) { func TestAccAWSCodeBuildProject_SecondaryArtifacts(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" resource.ParallelTest(t, resource.TestCase{ @@ -1784,7 +1827,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts(rName, bName), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "2"), @@ -1796,7 +1839,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_none(rName, bName), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_none(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "0"), @@ -1809,7 +1852,6 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts(t *testing.T) { func TestAccAWSCodeBuildProject_SecondaryArtifacts_ArtifactIdentifier(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" artifactIdentifier1 := "artifactIdentifier1" @@ -1822,7 +1864,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_ArtifactIdentifier(t *testing CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_ArtifactIdentifier(rName, bName, artifactIdentifier1), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_ArtifactIdentifier(rName, artifactIdentifier1), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), @@ -1837,7 +1879,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_ArtifactIdentifier(t *testing ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_ArtifactIdentifier(rName, bName, artifactIdentifier2), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_ArtifactIdentifier(rName, artifactIdentifier2), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), @@ -1853,7 +1895,6 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_ArtifactIdentifier(t *testing func TestAccAWSCodeBuildProject_SecondaryArtifacts_OverrideArtifactName(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" resource.ParallelTest(t, resource.TestCase{ @@ -1863,7 +1904,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_OverrideArtifactName(t *testi CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_OverrideArtifactName(rName, bName, true), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_OverrideArtifactName(rName, true), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), @@ -1878,7 +1919,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_OverrideArtifactName(t *testi ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_OverrideArtifactName(rName, bName, false), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_OverrideArtifactName(rName, false), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), @@ -1894,7 +1935,6 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_OverrideArtifactName(t *testi func TestAccAWSCodeBuildProject_SecondaryArtifacts_EncryptionDisabled(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" resource.ParallelTest(t, resource.TestCase{ @@ -1904,7 +1944,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_EncryptionDisabled(t *testing CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_EncryptionDisabled(rName, bName, true), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_EncryptionDisabled(rName, true), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), @@ -1919,7 +1959,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_EncryptionDisabled(t *testing ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_EncryptionDisabled(rName, bName, false), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_EncryptionDisabled(rName, false), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), @@ -1934,9 +1974,8 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_EncryptionDisabled(t *testing func TestAccAWSCodeBuildProject_SecondaryArtifacts_Location(t *testing.T) { var project codebuild.Project - rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") - bName2 := acctest.RandomWithPrefix("tf-acc-test-bucket2") + rName1 := acctest.RandomWithPrefix("tf-acc-test") + rName2 := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_codebuild_project.test" resource.ParallelTest(t, resource.TestCase{ @@ -1946,12 +1985,12 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_Location(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Location(rName, bName), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Location(rName1, rName1), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "secondary_artifacts.*", map[string]string{ - "location": bName, + "location": rName1, }), ), }, @@ -1961,12 +2000,12 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_Location(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Location(rName, bName2), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Location(rName1, rName2), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "secondary_artifacts.*", map[string]string{ - "location": bName2, + "location": rName2, }), ), }, @@ -1979,7 +2018,6 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_Name(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" name1 := "name1" @@ -1992,7 +2030,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_Name(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Name(rName, bName, name1), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Name(rName, name1), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), @@ -2007,7 +2045,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_Name(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Name(rName, bName, name2), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Name(rName, name2), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), @@ -2146,7 +2184,6 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_Path(t *testing.T) { func TestAccAWSCodeBuildProject_SecondaryArtifacts_Type(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") - bName := acctest.RandomWithPrefix("tf-acc-test-bucket") resourceName := "aws_codebuild_project.test" resource.ParallelTest(t, resource.TestCase{ @@ -2156,7 +2193,7 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts_Type(t *testing.T) { CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Type(rName, bName, codebuild.ArtifactsTypeS3), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Type(rName, codebuild.ArtifactsTypeS3), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), @@ -2382,37 +2419,27 @@ func testAccPreCheckAWSCodeBuild(t *testing.T) { } } -func testAccAWSCodeBuildProjectConfig_Base_Bucket(rName string) string { - return fmt.Sprintf(` -resource "aws_s3_bucket" "test" { - bucket = "%s" - force_destroy = true -} -`, rName) -} - func testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName string) string { return fmt.Sprintf(` resource "aws_iam_role" "test" { - name = "%s" + name = %[1]q assume_role_policy = <