From 6046c1e08b7850ed89058a4d61f0441085883565 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Kuester Date: Wed, 6 Mar 2019 12:18:39 +0100 Subject: [PATCH] Add override_artifact_name flag to aws_codebuild_project --- aws/resource_aws_codebuild_project.go | 13 +++++ aws/resource_aws_codebuild_project_test.go | 58 +++++++++++++++++++ .../docs/r/codebuild_project.html.markdown | 2 + 3 files changed, 73 insertions(+) diff --git a/aws/resource_aws_codebuild_project.go b/aws/resource_aws_codebuild_project.go index 6cc8d3f18275..b05e57e446d0 100644 --- a/aws/resource_aws_codebuild_project.go +++ b/aws/resource_aws_codebuild_project.go @@ -76,6 +76,11 @@ func resourceAwsCodeBuildProject() *schema.Resource { codebuild.ArtifactsTypeNoArtifacts, }, false), }, + "override_artifact_name": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, }, Set: resourceAwsCodeBuildProjectArtifactsHash, @@ -565,6 +570,8 @@ func expandProjectArtifactData(data map[string]interface{}) codebuild.ProjectArt projectArtifacts.EncryptionDisabled = aws.Bool(data["encryption_disabled"].(bool)) } + projectArtifacts.OverrideArtifactName = aws.Bool(data["override_artifact_name"].(bool)) + if data["artifact_identifier"] != nil && data["artifact_identifier"].(string) != "" { projectArtifacts.ArtifactIdentifier = aws.String(data["artifact_identifier"].(string)) } @@ -955,6 +962,11 @@ func flattenAwsCodeBuildProjectArtifactsData(artifacts codebuild.ProjectArtifact if artifacts.EncryptionDisabled != nil { values["encryption_disabled"] = *artifacts.EncryptionDisabled } + + if artifacts.OverrideArtifactName != nil { + values["override_artifact_name"] = *artifacts.OverrideArtifactName + } + if artifacts.Location != nil { values["location"] = *artifacts.Location } @@ -1064,6 +1076,7 @@ func resourceAwsCodeBuildProjectArtifactsHash(v interface{}) int { m := v.(map[string]interface{}) buf.WriteString(fmt.Sprintf("%s-", m["type"].(string))) + buf.WriteString(fmt.Sprintf("%t-", m["override_artifact_name"].(bool))) if v, ok := m["artifact_identifier"]; ok { buf.WriteString(fmt.Sprintf("%s:", v.(string))) diff --git a/aws/resource_aws_codebuild_project_test.go b/aws/resource_aws_codebuild_project_test.go index da5d62707865..204f14405f4b 100644 --- a/aws/resource_aws_codebuild_project_test.go +++ b/aws/resource_aws_codebuild_project_test.go @@ -75,6 +75,7 @@ func TestAccAWSCodeBuildProject_basic(t *testing.T) { testAccCheckResourceAttrRegionalARN(resourceName, "arn", "codebuild", fmt.Sprintf("project/%s", rName)), resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), resource.TestCheckResourceAttr(resourceName, "artifacts.1178773975.encryption_disabled", "false"), + resource.TestCheckResourceAttr(resourceName, "artifacts.1178773975.override_artifact_name", "false"), resource.TestCheckResourceAttr(resourceName, "artifacts.1178773975.location", ""), resource.TestCheckResourceAttr(resourceName, "artifacts.1178773975.name", ""), resource.TestCheckResourceAttr(resourceName, "artifacts.1178773975.namespace_type", ""), @@ -768,6 +769,37 @@ func TestAccAWSCodeBuildProject_Artifacts_EncryptionDisabled(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{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCodebuildProjectConfig_Artifacts_OverrideArtifactName(rName, bName, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.1580844383.override_artifact_name", "true"), + ), + }, + { + Config: testAccAWSCodebuildProjectConfig_Artifacts_OverrideArtifactName(rName, bName, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSCodeBuildProjectExists(resourceName, &project), + resource.TestCheckResourceAttr(resourceName, "artifacts.#", "1"), + resource.TestCheckResourceAttr(resourceName, "artifacts.135498304.override_artifact_name", "false"), + ), + }, + }, + }) +} + func TestAccAWSCodeBuildProject_SecondaryArtifacts(t *testing.T) { var project codebuild.Project rName := acctest.RandomWithPrefix("tf-acc-test") @@ -1692,6 +1724,32 @@ resource "aws_codebuild_project" "test" { `, rName, encryptionDisabled) } +func testAccAWSCodebuildProjectConfig_Artifacts_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 { + 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(rName string, bName string) string { return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(` resource "aws_codebuild_project" "test" { diff --git a/website/docs/r/codebuild_project.html.markdown b/website/docs/r/codebuild_project.html.markdown index 6a2ed947edf9..93792ece78cf 100644 --- a/website/docs/r/codebuild_project.html.markdown +++ b/website/docs/r/codebuild_project.html.markdown @@ -164,6 +164,7 @@ The following arguments are supported: * `type` - (Required) The build output artifact's type. Valid values for this parameter are: `CODEPIPELINE`, `NO_ARTIFACTS` or `S3`. * `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. If `path` is not also specified, then `location` can also specify the path of the output artifact in the output bucket. * `name` - (Optional) The name of the project. If `type` is set to `S3`, this is the name of the output artifact object * `namespace_type` - (Optional) The namespace to use in storing build artifacts. If `type` is set to `S3`, then valid values for this parameter are: `BUILD_ID` or `NONE`. @@ -217,6 +218,7 @@ The following arguments are supported: * `type` - (Required) The build output artifact's type. Valid values for this parameter are: `CODEPIPELINE`, `NO_ARTIFACTS` or `S3`. * `artifact_identifier` - (Required) 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. If `path` is not also specified, then `location` can also specify the path of the output artifact in the output bucket. * `name` - (Optional) The name of the project. If `type` is set to `S3`, this is the name of the output artifact object * `namespace_type` - (Optional) The namespace to use in storing build artifacts. If `type` is set to `S3`, then valid values for this parameter are: `BUILD_ID` or `NONE`.