Skip to content

Commit

Permalink
Rework the test for codebuild certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
tkbky committed Oct 9, 2018
1 parent 39923bc commit c5c262b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
4 changes: 1 addition & 3 deletions aws/resource_aws_codebuild_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ func flattenAwsCodeBuildProjectEnvironment(environment *codebuild.ProjectEnviron
envConfig["type"] = *environment.Type
envConfig["compute_type"] = *environment.ComputeType
envConfig["image"] = *environment.Image
envConfig["certificate"] = *environment.Certificate
envConfig["certificate"] = aws.StringValue(environment.Certificate)
envConfig["privileged_mode"] = *environment.PrivilegedMode

if environment.EnvironmentVariables != nil {
Expand Down Expand Up @@ -1074,13 +1074,11 @@ func resourceAwsCodeBuildProjectEnvironmentHash(v interface{}) int {
environmentType := m["type"].(string)
computeType := m["compute_type"].(string)
image := m["image"].(string)
certificate := m["certificate"].(string)
privilegedMode := m["privileged_mode"].(bool)
environmentVariables := m["environment_variable"].([]interface{})
buf.WriteString(fmt.Sprintf("%s-", environmentType))
buf.WriteString(fmt.Sprintf("%s-", computeType))
buf.WriteString(fmt.Sprintf("%s-", image))
buf.WriteString(fmt.Sprintf("%s-", certificate))
buf.WriteString(fmt.Sprintf("%t-", privilegedMode))
for _, e := range environmentVariables {
if e != nil { // Old statefiles might have nil values in them
Expand Down
30 changes: 17 additions & 13 deletions aws/resource_aws_codebuild_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ func TestAccAWSCodeBuildProject_Environment_EnvironmentVariable_Type(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"

resource.Test(t, resource.TestCase{
Expand All @@ -297,10 +299,10 @@ func TestAccAWSCodeBuildProject_Environment_Certificate(t *testing.T) {
CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCodeBuildProjectConfig_Environment_Certificate(rName),
Config: testAccAWSCodeBuildProjectConfig_Environment_Certificate(rName, bName, oName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeBuildProjectExists(resourceName, &project),
resource.TestCheckResourceAttr(resourceName, "environment.3925601246.certificate", "arn:aws:s3:::secret_bucket/cert.pem"),
resource.TestCheckResourceAttr(resourceName, "environment.1974383098.certificate", fmt.Sprintf("%s/%s", bName, oName)),
),
},
},
Expand Down Expand Up @@ -1038,10 +1040,16 @@ resource "aws_codebuild_project" "test" {
`, rName, environmentVariableType)
}

func testAccAWSCodeBuildProjectConfig_Environment_Certificate(rName string) string {
return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(`
func testAccAWSCodeBuildProjectConfig_Environment_Certificate(rName string, bName string, oName string) string {
return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + testAccAWSCodeBuildProjectConfig_Base_Bucket(bName) + fmt.Sprintf(`
resource "aws_s3_bucket_object" "test" {
bucket = "${aws_s3_bucket.test.bucket}"
key = "%s"
content = "foo"
}
resource "aws_codebuild_project" "test" {
name = %q
name = "%s"
service_role = "${aws_iam_role.test.arn}"
artifacts {
Expand All @@ -1052,19 +1060,15 @@ resource "aws_codebuild_project" "test" {
compute_type = "BUILD_GENERAL1_SMALL"
image = "2"
type = "LINUX_CONTAINER"
certificate = "arn:aws:s3:::secret_bucket/cert.pem"
certificate = "${aws_s3_bucket.test.bucket}/${aws_s3_bucket_object.test.key}"
}
source {
location = "https://example.com/organization/repository.git"
type = "GITHUB_ENTERPRISE"
auth {
resource = "FAKESOURCE"
type = "OAUTH"
}
type = "GITHUB"
location = "https://github.com/hashicorp/packer.git"
}
}
`, rName)
`, oName, rName)
}

func testAccAWSCodeBuildProjectConfig_Source_Auth(rName, authResource, authType string) string {
Expand Down

0 comments on commit c5c262b

Please sign in to comment.