-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for setting of certificate in aws_codebuild_project
#6087
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,10 @@ func resourceAwsCodeBuildProject() *schema.Resource { | |
Optional: true, | ||
Default: false, | ||
}, | ||
"certificate": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
Set: resourceAwsCodeBuildProjectEnvironmentHash, | ||
|
@@ -619,6 +623,10 @@ func expandProjectEnvironment(d *schema.ResourceData) *codebuild.ProjectEnvironm | |
projectEnv.Type = aws.String(v.(string)) | ||
} | ||
|
||
if v := envConfig["certificate"]; v != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent the Terraform resource from always triggering this error when not set in the Terrraform configuration:
We can use this instead: if v, ok := envConfig["certificate"]; ok && v.(string) != "" {
projectEnv.Certificate = aws.String(v.(string))
} |
||
projectEnv.Certificate = aws.String(v.(string)) | ||
} | ||
|
||
if v := envConfig["environment_variable"]; v != nil { | ||
envVariables := v.([]interface{}) | ||
if len(envVariables) > 0 { | ||
|
@@ -984,6 +992,7 @@ func flattenAwsCodeBuildProjectEnvironment(environment *codebuild.ProjectEnviron | |
envConfig["type"] = *environment.Type | ||
envConfig["compute_type"] = *environment.ComputeType | ||
envConfig["image"] = *environment.Image | ||
envConfig["certificate"] = aws.StringValue(environment.Certificate) | ||
envConfig["privileged_mode"] = *environment.PrivilegedMode | ||
|
||
if environment.EnvironmentVariables != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,6 +286,29 @@ 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{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSCodeBuildProjectConfig_Environment_Certificate(rName, bName, oName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSCodeBuildProjectExists(resourceName, &project), | ||
resource.TestCheckResourceAttr(resourceName, "environment.1974383098.certificate", fmt.Sprintf("%s/%s", bName, oName)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the testAccCheckAWSCodeBuildProjectCertificate(&project, fmt.Sprintf("%s/%s", bName, oName)), and its definition: func testAccCheckAWSCodeBuildProjectCertificate(project *codebuild.Project, expectedCertificate string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if aws.StringValue(project.Environment.Certificate) != expectedCertificate {
return fmt.Errorf("CodeBuild Project certificate (%s) did not match: %s", aws.StringValue(project.Environment.Certificate), expectedCertificate)
}
return nil
}
} |
||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSCodeBuildProject_Source_Auth(t *testing.T) { | ||
var project codebuild.Project | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
|
@@ -1017,6 +1040,37 @@ resource "aws_codebuild_project" "test" { | |
`, rName, environmentVariableType) | ||
} | ||
|
||
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 = "%s" | ||
service_role = "${aws_iam_role.test.arn}" | ||
|
||
artifacts { | ||
type = "NO_ARTIFACTS" | ||
} | ||
|
||
environment { | ||
compute_type = "BUILD_GENERAL1_SMALL" | ||
image = "2" | ||
type = "LINUX_CONTAINER" | ||
certificate = "${aws_s3_bucket.test.bucket}/${aws_s3_bucket_object.test.key}" | ||
} | ||
|
||
source { | ||
type = "GITHUB" | ||
location = "https://github.com/hashicorp/packer.git" | ||
} | ||
} | ||
`, oName, rName) | ||
} | ||
|
||
func testAccAWSCodeBuildProjectConfig_Source_Auth(rName, authResource, authType string) string { | ||
return testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName) + fmt.Sprintf(` | ||
resource "aws_codebuild_project" "test" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the CodeBuild API seems to validate against
.pem
and.zip
endings, we can implement plan-time validation for that via:Also, since this attribute lives inside a
Type: schema.TypeSet
attribute, there is aSet
function which is used to detect changes.resourceAwsCodeBuildProjectEnvironmentHash
in this case.We can add the following there:
At some point we'll likely be converting many of these
TypeSet
attributes, due to their unnecessary complexity.