-
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
Added badge_enabled argument, exported badge_url parameter #3504
Changes from all commits
e7a1940
34fae33
2e359b2
01cf09b
a010065
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 |
---|---|---|
|
@@ -180,6 +180,16 @@ func resourceAwsCodeBuildProject() *schema.Resource { | |
Default: "60", | ||
ValidateFunc: validateAwsCodeBuildTimeout, | ||
}, | ||
"badge_enabled": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
}, | ||
"badge_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
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 we cannot set the badge URL via the API, |
||
}, | ||
"tags": tagsSchema(), | ||
"vpc_config": { | ||
Type: schema.TypeList, | ||
|
@@ -246,6 +256,10 @@ func resourceAwsCodeBuildProjectCreate(d *schema.ResourceData, meta interface{}) | |
params.VpcConfig = expandCodeBuildVpcConfig(v.([]interface{})) | ||
} | ||
|
||
if v, ok := d.GetOk("badge_enabled"); ok { | ||
params.BadgeEnabled = aws.Bool(v.(bool)) | ||
} | ||
|
||
if v, ok := d.GetOk("tags"); ok { | ||
params.Tags = tagsFromMapCodeBuild(v.(map[string]interface{})) | ||
} | ||
|
@@ -451,6 +465,7 @@ func resourceAwsCodeBuildProjectRead(d *schema.ResourceData, meta interface{}) e | |
d.Set("name", project.Name) | ||
d.Set("service_role", project.ServiceRole) | ||
d.Set("build_timeout", project.TimeoutInMinutes) | ||
d.Set("badge_url", project.Badge.BadgeRequestUrl) | ||
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. In order to prevent potential nil dereference panic, we need to wrap these in a nil check: if project.Badge != nil {
d.Set("badge_enabled", project.Badge.BadgeEnabled)
d.Set("badge_url", project.Badge.BadgeRequestUrl)
} else {
d.Set("badge_enabled", false)
d.Set("badge_url", "")
} |
||
|
||
if err := d.Set("tags", tagsToMapCodeBuild(project.Tags)); err != nil { | ||
return err | ||
|
@@ -501,6 +516,10 @@ func resourceAwsCodeBuildProjectUpdate(d *schema.ResourceData, meta interface{}) | |
params.TimeoutInMinutes = aws.Int64(int64(d.Get("build_timeout").(int))) | ||
} | ||
|
||
if d.HasChange("badge_enabled") { | ||
params.BadgeEnabled = aws.Bool(d.Get("badge_enabled").(bool)) | ||
} | ||
|
||
// The documentation clearly says "The replacement set of tags for this build project." | ||
// But its a slice of pointers so if not set for every update, they get removed. | ||
params.Tags = tagsFromMapCodeBuild(d.Get("tags").(map[string]interface{})) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -386,6 +386,25 @@ func testAccCheckAWSCodeBuildProjectDestroy(s *terraform.State) error { | |
return fmt.Errorf("Default error in CodeBuild Test") | ||
} | ||
|
||
func TestAccAWSCodeBuildProject_buildBadgeUrlValidation(t *testing.T) { | ||
name := acctest.RandString(10) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccAWSCodebuildProjectConfig_buildBadgeUrlValidation(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSCodeBuildProjectExists("aws_codebuild_project.vanilla_codebuild_project"), | ||
resource.TestMatchResourceAttr("aws_codebuild_project.vanilla_codebuild_project", "badge_url", regexp.MustCompile(`\b(https?).*\b`)), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAWSCodeBuildProjectConfig_basic(rName, vpcConfig, vpcResources string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_iam_role" "codebuild_role" { | ||
|
@@ -774,3 +793,87 @@ func testAccAWSCodeBuildProjectConfig_vpcConfig(subnets string) string { | |
} | ||
`, subnets) | ||
} | ||
|
||
func testAccAWSCodebuildProjectConfig_buildBadgeUrlValidation(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_iam_role" "codebuild_role" { | ||
name = "codebuild-role-%s" | ||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "codebuild.amazonaws.com" | ||
}, | ||
"Action": "sts:AssumeRole" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_iam_policy" "codebuild_policy" { | ||
name = "codebuild-policy-%s" | ||
path = "/service-role/" | ||
description = "Policy used in trust relationship with CodeBuild" | ||
policy = <<POLICY | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Resource": [ | ||
"*" | ||
], | ||
"Action": [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
] | ||
} | ||
] | ||
} | ||
POLICY | ||
} | ||
|
||
resource "aws_iam_policy_attachment" "codebuild_policy_attachment" { | ||
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. Minor nitpick: We generally discourage the usage of |
||
name = "codebuild-policy-attachment-%s" | ||
policy_arn = "${aws_iam_policy.codebuild_policy.arn}" | ||
roles = ["${aws_iam_role.codebuild_role.id}"] | ||
} | ||
|
||
resource "aws_codebuild_project" "vanilla_codebuild_project" { | ||
name = "test-project-%s" | ||
badge_enabled = true | ||
description = "test_codebuild_project" | ||
|
||
service_role = "${aws_iam_role.codebuild_role.arn}" | ||
|
||
artifacts { | ||
type = "NO_ARTIFACTS" | ||
} | ||
|
||
environment { | ||
compute_type = "BUILD_GENERAL1_SMALL" | ||
image = "2" | ||
type = "LINUX_CONTAINER" | ||
|
||
environment_variable = { | ||
"name" = "SOME_OTHERKEY" | ||
"value" = "SOME_OTHERVALUE" | ||
} | ||
} | ||
|
||
source { | ||
type = "GITHUB" | ||
location = "https://github.com/hashicorp/packer.git" | ||
} | ||
|
||
tags { | ||
"Environment" = "Test" | ||
} | ||
} | ||
`, rName, rName, rName, rName) | ||
} |
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.
In order for Terraform to determine that this parameter has changed from the API, we need to call
d.Set("badge_enabled", project.Badge.BadgeEnabled)
in the read function.