From e7a1940a8abd2e2240df1a3d9a9d9d59a4c25ade Mon Sep 17 00:00:00 2001 From: vpadronblanco Date: Fri, 23 Feb 2018 14:43:26 -0500 Subject: [PATCH 1/3] Commiting test --- aws/resource_aws_codebuild_project_test.go | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/aws/resource_aws_codebuild_project_test.go b/aws/resource_aws_codebuild_project_test.go index 4e7bb2ab99d..eb5e53e113a 100644 --- a/aws/resource_aws_codebuild_project_test.go +++ b/aws/resource_aws_codebuild_project_test.go @@ -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 hclVpcConfig(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 = < Date: Fri, 23 Feb 2018 14:43:43 -0500 Subject: [PATCH 2/3] Commiting web documentation --- website/docs/r/codebuild_project.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/r/codebuild_project.html.markdown b/website/docs/r/codebuild_project.html.markdown index d9679b5d796..c94ef1a2843 100644 --- a/website/docs/r/codebuild_project.html.markdown +++ b/website/docs/r/codebuild_project.html.markdown @@ -128,6 +128,7 @@ The following arguments are supported: * `environment` - (Required) Information about the project's build environment. Environment blocks are documented below. * `source` - (Required) Information about the project's input source code. Source blocks are documented below. * `vpc_config` - (Optional) Configuration for the builds to run inside a VPC. VPC config blocks are documented below. +* `badge_enabled` - (Optional) Generates a publicly-accessible URL for the projects build badge. `artifacts` supports the following: @@ -178,3 +179,4 @@ The following attributes are exported: * `encryption_key` - The AWS Key Management Service (AWS KMS) customer master key (CMK) that was used for encrypting the build project's build output artifacts. * `name` - The projects name. * `service_role` - The ARN of the IAM service role. +* `badge_url` - The URL of the build badge From 2e359b243d7ef887f7ca8c285450d1fda0a483a3 Mon Sep 17 00:00:00 2001 From: vpadronblanco Date: Fri, 23 Feb 2018 14:44:12 -0500 Subject: [PATCH 3/3] Commiting support for badge build and exporting badge_url --- aws/resource_aws_codebuild_project.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/aws/resource_aws_codebuild_project.go b/aws/resource_aws_codebuild_project.go index eb6afb70b6d..fc928d4cad7 100644 --- a/aws/resource_aws_codebuild_project.go +++ b/aws/resource_aws_codebuild_project.go @@ -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, + }, "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) 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{}))