Skip to content

Commit

Permalink
tests/resource/aws_codebuild_project: Add test covering environment v…
Browse files Browse the repository at this point in the history
…ariable removal

References:

* hashicorp/terraform#20505
* #6427

The `environment` configuration block `environment_variable` configuration block came up in our `Optional: true` and `Computed: true` discovery as potentially problematic in Terraform 0.12 when the ability to use attribute syntax to zero out the configuration will require special implementation. However, it appears the functionality will actually continue to work due to the `environment` configuration block `Set` function and how updates of it are implemented.

Here we still add the covering test for when the `environment` configuration block attribute is switched from `TypeSet` to `TypeList` during future simplification work. While it would probably be okay to just remove `Computed: true` now, we take the less risky approach of just leaving this as-is for now until that simplification work is completed.

Output from acceptance testing:

```
--- PASS: TestAccAWSCodeBuildProject_Environment_EnvironmentVariable (37.91s)
```
  • Loading branch information
bflad committed Apr 4, 2019
1 parent 21c3d7d commit a9b72dd
Showing 1 changed file with 137 additions and 0 deletions.
137 changes: 137 additions & 0 deletions aws/resource_aws_codebuild_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,56 @@ func TestAccAWSCodeBuildProject_EncryptionKey(t *testing.T) {
})
}

func TestAccAWSCodeBuildProject_Environment_EnvironmentVariable(t *testing.T) {
var project1, project2, project3 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_EnvironmentVariable_One(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeBuildProjectExists(resourceName, &project1),
resource.TestCheckResourceAttr(resourceName, "environment.1380979031.environment_variable.#", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSCodeBuildProjectConfig_Environment_EnvironmentVariable_Two(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeBuildProjectExists(resourceName, &project2),
resource.TestCheckResourceAttr(resourceName, "environment.4178155002.environment_variable.#", "2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSCodeBuildProjectConfig_Environment_EnvironmentVariable_Zero(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeBuildProjectExists(resourceName, &project3),
resource.TestCheckResourceAttr(resourceName, "environment.2300252877.environment_variable.#", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSCodeBuildProject_Environment_EnvironmentVariable_Type(t *testing.T) {
var project codebuild.Project
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -1155,6 +1205,93 @@ resource "aws_codebuild_project" "test" {
`, rName)
}

func testAccAWSCodeBuildProjectConfig_Environment_EnvironmentVariable_One(rName string) string {
return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(`
resource "aws_codebuild_project" "test" {
name = %[1]q
service_role = "${aws_iam_role.test.arn}"
artifacts {
type = "NO_ARTIFACTS"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "2"
type = "LINUX_CONTAINER"
environment_variable {
name = "SOME_KEY"
value = "SOME_VALUE"
}
}
source {
type = "GITHUB"
location = "https://github.com/hashicorp/packer.git"
}
}
`, rName)
}

func testAccAWSCodeBuildProjectConfig_Environment_EnvironmentVariable_Two(rName string) string {
return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(`
resource "aws_codebuild_project" "test" {
name = %[1]q
service_role = "${aws_iam_role.test.arn}"
artifacts {
type = "NO_ARTIFACTS"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "2"
type = "LINUX_CONTAINER"
environment_variable {
name = "SOME_KEY"
value = "SOME_VALUE"
}
environment_variable {
name = "SOME_KEY2"
value = "SOME_VALUE2"
}
}
source {
type = "GITHUB"
location = "https://github.com/hashicorp/packer.git"
}
}
`, rName)
}

func testAccAWSCodeBuildProjectConfig_Environment_EnvironmentVariable_Zero(rName string) string {
return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(`
resource "aws_codebuild_project" "test" {
name = %[1]q
service_role = "${aws_iam_role.test.arn}"
artifacts {
type = "NO_ARTIFACTS"
}
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "2"
type = "LINUX_CONTAINER"
}
source {
type = "GITHUB"
location = "https://github.com/hashicorp/packer.git"
}
}
`, rName)
}

func testAccAWSCodeBuildProjectConfig_Environment_EnvironmentVariable_Type(rName, environmentVariableType string) string {
return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(`
resource "aws_codebuild_project" "test" {
Expand Down

0 comments on commit a9b72dd

Please sign in to comment.