diff --git a/aws/resource_aws_codebuild_project.go b/aws/resource_aws_codebuild_project.go index f8b1862f0af..87507f89caa 100644 --- a/aws/resource_aws_codebuild_project.go +++ b/aws/resource_aws_codebuild_project.go @@ -38,6 +38,10 @@ func resourceAwsCodeBuildProject() *schema.Resource { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "artifact_identifier": { + Type: schema.TypeString, + Optional: true, + }, "name": { Type: schema.TypeString, Optional: true, @@ -83,6 +87,10 @@ func resourceAwsCodeBuildProject() *schema.Resource { } return false }, + ValidateFunc: validation.StringInSlice([]string{ + codebuild.ArtifactPackagingNone, + codebuild.ArtifactPackagingZip, + }, false), }, "path": { Type: schema.TypeString, @@ -344,6 +352,7 @@ func resourceAwsCodeBuildProject() *schema.Resource { codebuild.ArtifactNamespaceNone, codebuild.ArtifactNamespaceBuildId, }, false), + Default: codebuild.ArtifactNamespaceNone, }, "override_artifact_name": { Type: schema.TypeBool, @@ -353,6 +362,11 @@ func resourceAwsCodeBuildProject() *schema.Resource { "packaging": { Type: schema.TypeString, Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + codebuild.ArtifactPackagingNone, + codebuild.ArtifactPackagingZip, + }, false), + Default: codebuild.ArtifactPackagingNone, }, "path": { Type: schema.TypeString, @@ -366,9 +380,7 @@ func resourceAwsCodeBuildProject() *schema.Resource { Type: schema.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{ - codebuild.ArtifactsTypeCodepipeline, codebuild.ArtifactsTypeS3, - codebuild.ArtifactsTypeNoArtifacts, }, false), }, }, @@ -1380,16 +1392,38 @@ func resourceAwsCodeBuildProjectArtifactsHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) - buf.WriteString(fmt.Sprintf("%s-", m["type"].(string))) - if v, ok := m["artifact_identifier"]; ok { - buf.WriteString(fmt.Sprintf("%s:", v.(string))) + buf.WriteString(fmt.Sprintf("%s-", v.(string))) + } + + if v, ok := m["encryption_disabled"]; ok { + buf.WriteString(fmt.Sprintf("%t-", v.(bool))) + } + + if v, ok := m["location"]; ok { + buf.WriteString(fmt.Sprintf("%s-", v.(string))) + } + + if v, ok := m["namespace_type"]; ok { + buf.WriteString(fmt.Sprintf("%s-", v.(string))) } if v, ok := m["override_artifact_name"]; ok { buf.WriteString(fmt.Sprintf("%t-", v.(bool))) } + if v, ok := m["packaging"]; ok { + buf.WriteString(fmt.Sprintf("%s-", v.(string))) + } + + if v, ok := m["path"]; ok { + buf.WriteString(fmt.Sprintf("%s-", v.(string))) + } + + if v, ok := m["type"]; ok { + buf.WriteString(fmt.Sprintf("%s-", v.(string))) + } + return hashcode.String(buf.String()) } diff --git a/aws/resource_aws_codebuild_project_test.go b/aws/resource_aws_codebuild_project_test.go index f40389ee5b6..c7483c0146a 100644 --- a/aws/resource_aws_codebuild_project_test.go +++ b/aws/resource_aws_codebuild_project_test.go @@ -6,6 +6,8 @@ import ( "regexp" "testing" + "github.com/hashicorp/terraform/helper/hashcode" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/codebuild" "github.com/hashicorp/terraform/helper/acctest" @@ -894,6 +896,45 @@ func TestAccAWSCodeBuildProject_WindowsContainer(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" + artifactIdentifier2 := "artifactIdentifier2" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_Artifacts_ArtifactIdentifier(rName, bName, artifactIdentifier1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.artifact_identifier", artifactIdentifier1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_Artifacts_ArtifactIdentifier(rName, bName, artifactIdentifier2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.artifact_identifier", artifactIdentifier2), + ), + }, + }, + }) +} + func TestAccAWSCodeBuildProject_Artifacts_EncryptionDisabled(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") @@ -930,6 +971,82 @@ 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") + resourceName := "aws_codebuild_project.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_Artifacts_Location(rName, bName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.location", bName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_Artifacts_Location(rName, bName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.location", bName2), + ), + }, + }, + }) +} + +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" + name2 := "name2" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_Artifacts_Name(rName, bName, name1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.name", name1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_Artifacts_Name(rName, bName, name2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.name", name2), + ), + }, + }, + }) +} + func TestAccAWSCodeBuildProject_Artifacts_NamespaceType(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") @@ -981,6 +1098,7 @@ func TestAccAWSCodeBuildProject_Artifacts_OverrideArtifactName(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.override_artifact_name", "true"), ), }, { @@ -993,6 +1111,7 @@ func TestAccAWSCodeBuildProject_Artifacts_OverrideArtifactName(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.override_artifact_name", "false"), ), }, }, @@ -1069,6 +1188,45 @@ 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 + type2 := codebuild.ArtifactsTypeCodepipeline + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_Artifacts_Type(rName, bName, type1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.type", type1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_Artifacts_Type(rName, bName, type2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.0.type", type2), + ), + }, + }, + }) +} + func TestAccAWSCodeBuildProject_SecondaryArtifacts(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") @@ -1096,64 +1254,107 @@ func TestAccAWSCodeBuildProject_SecondaryArtifacts(t *testing.T) { }) } -func TestAccAWSCodeBuildProject_SecondarySources_CodeCommit(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" + artifactIdentifier2 := "artifactIdentifier2" + + hash1 := artifactHash(artifactIdentifier1, "false", bName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) + hash2 := artifactHash(artifactIdentifier2, "false", bName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodeBuildProjectConfig_SecondarySources_CodeCommit(rName), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_ArtifactIdentifier(rName, bName, artifactIdentifier1), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), - resource.TestCheckResourceAttr(resourceName, "source.3715340088.type", "CODECOMMIT"), - resource.TestCheckResourceAttr(resourceName, "secondary_sources.3525046785.source_identifier", "secondarySource1"), - resource.TestCheckResourceAttr(resourceName, "secondary_sources.2644986630.source_identifier", "secondarySource2"), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.artifact_identifier", hash1), artifactIdentifier1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_ArtifactIdentifier(rName, bName, artifactIdentifier2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.artifact_identifier", hash2), artifactIdentifier2), ), }, }, }) } -func TestAWSCodeBuildProject_nameValidation(t *testing.T) { - cases := []struct { - Value string - ErrCount int - }{ - {Value: "_test", ErrCount: 1}, - {Value: "test", ErrCount: 0}, - {Value: "1_test", ErrCount: 0}, - {Value: "test**1", ErrCount: 1}, - {Value: acctest.RandString(256), ErrCount: 1}, - } +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" - for _, tc := range cases { - _, errors := validateAwsCodeBuildProjectName(tc.Value, "aws_codebuild_project") + hash1 := artifactHash("secondaryArtifact1", "false", bName, codebuild.ArtifactNamespaceNone, "true", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) + hash2 := artifactHash("secondaryArtifact1", "false", bName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) - if len(errors) != tc.ErrCount { - t.Fatalf("Expected the AWS CodeBuild project name to trigger a validation error - %s", errors) - } - } + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_OverrideArtifactName(rName, bName, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.override_artifact_name", hash1), "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_OverrideArtifactName(rName, bName, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.override_artifact_name", hash2), "false"), + ), + }, + }, + }) } -func TestAccAWSCodeBuildProject_Environment_RegistryCredential(t *testing.T) { +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" + hash1 := artifactHash("secondaryArtifact1", "true", bName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) + hash2 := artifactHash("secondaryArtifact1", "false", bName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSCodeBuildProjectConfig_Environment_RegistryCredential1(rName), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_EncryptionDisabled(rName, bName, true), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.encryption_disabled", hash1), "true"), ), }, { @@ -1162,55 +1363,365 @@ func TestAccAWSCodeBuildProject_Environment_RegistryCredential(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSCodeBuildProjectConfig_Environment_RegistryCredential2(rName), + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_EncryptionDisabled(rName, bName, false), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.encryption_disabled", hash2), "false"), ), }, }, }) } -func testAccCheckAWSCodeBuildProjectExists(n string, project *codebuild.Project) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No CodeBuild Project ID is set") - } +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") + resourceName := "aws_codebuild_project.test" - conn := testAccProvider.Meta().(*AWSClient).codebuildconn + hash1 := artifactHash("secondaryArtifact1", "false", bName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) + hash2 := artifactHash("secondaryArtifact1", "false", bName2, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) - out, err := conn.BatchGetProjects(&codebuild.BatchGetProjectsInput{ - Names: []*string{ - aws.String(rs.Primary.ID), + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Location(rName, bName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.location", hash1), bName), + ), }, - }) - - if err != nil { - return err - } + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Location(rName, bName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.location", hash2), bName2), + ), + }, + }, + }) +} - if len(out.Projects) < 1 { - return fmt.Errorf("No project found") - } +func TestAccAWSCodeBuildProject_SecondaryArtifacts_Name(t *testing.T) { + t.Skip("Currently no solution to allow updates on name attribute") - *project = *out.Projects[0] + var project codebuild.Project + rName := acctest.RandomWithPrefix("tf-acc-test") + bName := acctest.RandomWithPrefix("tf-acc-test-bucket") + resourceName := "aws_codebuild_project.test" - return nil - } -} + name1 := "name1" + name2 := "name2" -func testAccCheckAWSCodeBuildProjectDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).codebuildconn + hash1 := artifactHash("secondaryArtifact1", "false", bName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) + hash2 := artifactHash("secondaryArtifact1", "false", bName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) - for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_codebuild_project" { - continue - } + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Name(rName, bName, name1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.name", hash1), name1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Name(rName, bName, name2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.name", hash2), name2), + ), + }, + }, + }) +} + +func TestAccAWSCodeBuildProject_SecondaryArtifacts_NamespaceType(t *testing.T) { + var project codebuild.Project + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_project.test" + + hash1 := artifactHash("secondaryArtifact1", "false", rName, codebuild.ArtifactNamespaceBuildId, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) + hash2 := artifactHash("secondaryArtifact1", "false", rName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_NamespaceType(rName, codebuild.ArtifactNamespaceBuildId), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.namespace_type", hash1), codebuild.ArtifactNamespaceBuildId), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_NamespaceType(rName, codebuild.ArtifactNamespaceNone), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.namespace_type", hash2), codebuild.ArtifactNamespaceNone), + ), + }, + }, + }) +} + +func TestAccAWSCodeBuildProject_SecondaryArtifacts_Packaging(t *testing.T) { + var project codebuild.Project + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_project.test" + + hash1 := artifactHash("secondaryArtifact1", "false", rName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingZip, "", codebuild.ArtifactsTypeS3) + hash2 := artifactHash("secondaryArtifact1", "false", rName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", codebuild.ArtifactsTypeS3) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Packaging(rName, codebuild.ArtifactPackagingZip), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.packaging", hash1), codebuild.ArtifactPackagingZip), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Packaging(rName, codebuild.ArtifactPackagingNone), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.packaging", hash2), codebuild.ArtifactPackagingNone), + ), + }, + }, + }) +} + +func TestAccAWSCodeBuildProject_SecondaryArtifacts_Path(t *testing.T) { + var project codebuild.Project + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_codebuild_project.test" + + path1 := "path1" + path2 := "path2" + + hash1 := artifactHash("secondaryArtifact1", "false", rName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, path1, codebuild.ArtifactsTypeS3) + hash2 := artifactHash("secondaryArtifact1", "false", rName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, path2, codebuild.ArtifactsTypeS3) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Path(rName, path1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.path", hash1), path1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Path(rName, path2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.path", hash2), path2), + ), + }, + }, + }) +} + +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" + + type1 := codebuild.ArtifactsTypeS3 + + hash1 := artifactHash("secondaryArtifact1", "false", bName, codebuild.ArtifactNamespaceNone, "false", codebuild.ArtifactPackagingNone, "", type1) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Type(rName, bName, type1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "secondary_artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, fmt.Sprintf("secondary_artifacts.%d.type", hash1), type1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSCodeBuildProject_SecondarySources_CodeCommit(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) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeBuildProjectConfig_SecondarySources_CodeCommit(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "source.3715340088.type", "CODECOMMIT"), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.3525046785.source_identifier", "secondarySource1"), + resource.TestCheckResourceAttr(resourceName, "secondary_sources.2644986630.source_identifier", "secondarySource2"), + ), + }, + }, + }) +} + +func TestAWSCodeBuildProject_nameValidation(t *testing.T) { + cases := []struct { + Value string + ErrCount int + }{ + {Value: "_test", ErrCount: 1}, + {Value: "test", ErrCount: 0}, + {Value: "1_test", ErrCount: 0}, + {Value: "test**1", ErrCount: 1}, + {Value: acctest.RandString(256), ErrCount: 1}, + } + + for _, tc := range cases { + _, errors := validateAwsCodeBuildProjectName(tc.Value, "aws_codebuild_project") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the AWS CodeBuild project name to trigger a validation error - %s", errors) + } + } +} + +func TestAccAWSCodeBuildProject_Environment_RegistryCredential(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) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodeBuildProjectConfig_Environment_RegistryCredential1(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSCodeBuildProjectConfig_Environment_RegistryCredential2(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + ), + }, + }, + }) +} + +func testAccCheckAWSCodeBuildProjectExists(n string, project *codebuild.Project) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No CodeBuild Project ID is set") + } + + conn := testAccProvider.Meta().(*AWSClient).codebuildconn + + out, err := conn.BatchGetProjects(&codebuild.BatchGetProjectsInput{ + Names: []*string{ + aws.String(rs.Primary.ID), + }, + }) + + if err != nil { + return err + } + + if len(out.Projects) < 1 { + return fmt.Errorf("No project found") + } + + *project = *out.Projects[0] + + return nil + } +} + +func testAccCheckAWSCodeBuildProjectDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).codebuildconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_codebuild_project" { + continue + } out, err := conn.BatchGetProjects(&codebuild.BatchGetProjectsInput{ Names: []*string{ @@ -2291,14 +2802,40 @@ resource "aws_codebuild_project" "test" { `, rName, testAccAWSCodeBuildGitHubSourceLocationFromEnv()) } -func testAccAWSCodebuildProjectConfig_Artifacts_EncryptionDisabled(rName string, bName string, encryptionDisabled bool) string { +func testAccAWSCodebuildProjectConfig_Artifacts_ArtifactIdentifier(rName string, bName string, artifactIdentifier string) string { return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` resource "aws_codebuild_project" "test" { - name = "%s" + name = %[1]q service_role = "${aws_iam_role.test.arn}" artifacts { - encryption_disabled = %t + artifact_identifier = %[2]q + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName, artifactIdentifier) +} + +func testAccAWSCodebuildProjectConfig_Artifacts_EncryptionDisabled(rName string, bName string, encryptionDisabled bool) string { + return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` +resource "aws_codebuild_project" "test" { + name = "%s" + service_role = "${aws_iam_role.test.arn}" + + artifacts { + encryption_disabled = %t location = "${aws_s3_bucket.test.bucket}" type = "S3" } @@ -2317,6 +2854,57 @@ resource "aws_codebuild_project" "test" { `, rName, encryptionDisabled) } +func testAccAWSCodebuildProjectConfig_Artifacts_Location(rName, bName string) string { + return 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}" + + artifacts { + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName) +} + +func testAccAWSCodebuildProjectConfig_Artifacts_Name(rName string, bName string, name string) string { + return 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}" + + artifacts { + name = %[2]q + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName, name) +} + func testAccAWSCodebuildProjectConfig_Artifacts_NamespaceType(rName, namespaceType string) string { return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(rName) + fmt.Sprintf(` resource "aws_codebuild_project" "test" { @@ -2351,8 +2939,8 @@ resource "aws_codebuild_project" "test" { artifacts { override_artifact_name = %t - location = "${aws_s3_bucket.test.bucket}" - type = "S3" + location = "${aws_s3_bucket.test.bucket}" + type = "S3" } environment { @@ -2421,6 +3009,31 @@ resource "aws_codebuild_project" "test" { `, rName, path) } +func testAccAWSCodebuildProjectConfig_Artifacts_Type(rName string, bName string, artifactType string) string { + return 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}" + + artifacts { + type = %[2]q + location = "${aws_s3_bucket.test.bucket}" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = %[2]q + location = "${aws_s3_bucket.test.bucket}/" + } +} +`, rName, artifactType) +} + func testAccAWSCodebuildProjectConfig_SecondaryArtifacts(rName string, bName string) string { return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` resource "aws_codebuild_project" "test" { @@ -2458,6 +3071,291 @@ resource "aws_codebuild_project" "test" { `, rName) } +func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_ArtifactIdentifier(rName string, bName string, artifactIdentifier string) string { + return 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}" + + artifacts { + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + secondary_artifacts { + artifact_identifier = %[2]q + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName, artifactIdentifier) +} + +func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_EncryptionDisabled(rName string, bName string, encryptionDisabled bool) string { + return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` +resource "aws_codebuild_project" "test" { + name = "%s" + service_role = "${aws_iam_role.test.arn}" + + artifacts { + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + secondary_artifacts { + artifact_identifier = "secondaryArtifact1" + encryption_disabled = %t + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName, encryptionDisabled) +} + +func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Location(rName, bName string) string { + return 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}" + + artifacts { + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + secondary_artifacts { + artifact_identifier = "secondaryArtifact1" + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName) +} + +func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Name(rName string, bName string, name string) string { + return 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}" + + artifacts { + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + secondary_artifacts { + artifact_identifier = "secondaryArtifact1" + name = %[2]q + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName, name) +} + +func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_NamespaceType(rName, namespaceType string) string { + return 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}" + + artifacts { + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + secondary_artifacts { + artifact_identifier = "secondaryArtifact1" + namespace_type = %[2]q + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName, namespaceType) +} + +func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_OverrideArtifactName(rName string, bName string, overrideArtifactName bool) string { + return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` +resource "aws_codebuild_project" "test" { + name = "%s" + service_role = "${aws_iam_role.test.arn}" + + artifacts { + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + secondary_artifacts { + artifact_identifier = "secondaryArtifact1" + override_artifact_name = %t + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName, overrideArtifactName) +} + +func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Packaging(rName, packaging string) string { + return 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}" + + artifacts { + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + secondary_artifacts { + artifact_identifier = "secondaryArtifact1" + packaging = %[2]q + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName, packaging) +} + +func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Path(rName, path string) string { + return 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}" + + artifacts { + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + secondary_artifacts { + artifact_identifier = "secondaryArtifact1" + path = %[2]q + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + type = "GITHUB" + location = "https://github.com/hashicorp/packer.git" + } +} +`, rName, path) +} + +func testAccAWSCodebuildProjectConfig_SecondaryArtifacts_Type(rName string, bName string, artifactType string) string { + return 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}" + + artifacts { + location = "${aws_s3_bucket.test.bucket}" + type = "S3" + } + + secondary_artifacts { + artifact_identifier = "secondaryArtifact1" + type = %[2]q + location = "${aws_s3_bucket.test.bucket}" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "2" + type = "LINUX_CONTAINER" + } + + source { + location = "https://git-codecommit.region-id.amazonaws.com/v1/repos/repo-name" + type = "CODECOMMIT" + } +} +`, rName, artifactType) +} + func testAccAWSCodeBuildProjectConfig_SecondarySources_CodeCommit(rName string) string { return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` resource "aws_codebuild_project" "test" { @@ -2493,3 +3391,11 @@ resource "aws_codebuild_project" "test" { } `, rName) } + +func artifactHash(artifactIdentifier, encryptionDisabled, location, nameSpaceType, overrideArtifactName, + packaging, path, artifactType string) int { + buf := fmt.Sprintf("%s-%s-%s-%s-%s-%s-%s-%s-", artifactIdentifier, + encryptionDisabled, location, nameSpaceType, overrideArtifactName, packaging, path, artifactType) + hash := hashcode.String(buf) + return hash +} diff --git a/website/docs/r/codebuild_project.html.markdown b/website/docs/r/codebuild_project.html.markdown index 4735e53d564..72b20a950c5 100755 --- a/website/docs/r/codebuild_project.html.markdown +++ b/website/docs/r/codebuild_project.html.markdown @@ -233,6 +233,7 @@ The following arguments are supported: `artifacts` supports the following: * `type` - (Required) The build output artifact's type. Valid values for this parameter are: `CODEPIPELINE`, `NO_ARTIFACTS` or `S3`. +* `artifact_identifier` - (Optional) The artifact identifier. Must be the same specified inside AWS CodeBuild buildspec. * `encryption_disabled` - (Optional) If set to true, output artifacts will not be encrypted. If `type` is set to `NO_ARTIFACTS` then this value will be ignored. Defaults to `false`. * `override_artifact_name` (Optional) If set to true, a name specified in the build spec file overrides the artifact name. * `location` - (Optional) Information about the build output artifact location. If `type` is set to `CODEPIPELINE` or `NO_ARTIFACTS` then this value will be ignored. If `type` is set to `S3`, this is the name of the output bucket.