Skip to content
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

add concurrent build limit to aws_codebuild_project #18320

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/18320.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_codebuild_project: Add `concurrent_build_limit` argument to specify build concurrency.
```
14 changes: 14 additions & 0 deletions aws/resource_aws_codebuild_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ func resourceAwsCodeBuildProject() *schema.Resource {
},
},
},
"concurrent_build_limit": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntAtLeast(1),
},
"description": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -747,6 +752,10 @@ func resourceAwsCodeBuildProjectCreate(d *schema.ResourceData, meta interface{})
params.Cache = expandProjectCache(v.([]interface{}))
}

if v, ok := d.GetOk("concurrent_build_limit"); ok {
params.ConcurrentBuildLimit = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("description"); ok {
params.Description = aws.String(v.(string))
}
Expand Down Expand Up @@ -1277,6 +1286,7 @@ func resourceAwsCodeBuildProjectRead(d *schema.ResourceData, meta interface{}) e
}

d.Set("arn", project.Arn)
d.Set("concurrent_build_limit", project.ConcurrentBuildLimit)
d.Set("description", project.Description)
d.Set("encryption_key", project.EncryptionKey)
d.Set("name", project.Name)
Expand Down Expand Up @@ -1363,6 +1373,10 @@ func resourceAwsCodeBuildProjectUpdate(d *schema.ResourceData, meta interface{})
}
}

if d.HasChange("concurrent_build_limit") {
params.ConcurrentBuildLimit = aws.Int64(int64(d.Get("concurrent_build_limit").(int)))
}

if d.HasChange("description") {
params.Description = aws.String(d.Get("description").(string))
}
Expand Down
59 changes: 59 additions & 0 deletions aws/resource_aws_codebuild_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,40 @@ func TestAWSCodeBuildProject_nameValidation(t *testing.T) {
}
}

func TestAccAWSCodeBuildProject_ConcurrentBuildLimit(t *testing.T) {
var project 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,
ErrorCheck: testAccErrorCheck(t, codebuild.EndpointsID),
CheckDestroy: testAccCheckAWSCodeBuildProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCodeBuildProjectConfig_ConcurrentBuildLimit(rName, 4),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeBuildProjectExists(resourceName, &project),
resource.TestCheckResourceAttr(resourceName, "concurrent_build_limit", "4"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSCodeBuildProjectConfig_ConcurrentBuildLimit(rName, 12),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeBuildProjectExists(resourceName, &project),
resource.TestCheckResourceAttr(resourceName, "concurrent_build_limit", "12"),
),
},
},
})
}

func TestAccAWSCodeBuildProject_Environment_RegistryCredential(t *testing.T) {
var project codebuild.Project
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -4350,3 +4384,28 @@ resource "aws_codebuild_project" "test" {
}
`, rName)
}

func testAccAWSCodeBuildProjectConfig_ConcurrentBuildLimit(rName string, concurrentBuildLimit int) string {
return composeConfig(testAccAWSCodeBuildProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(`
resource "aws_codebuild_project" "test" {
concurrent_build_limit = %d
name = "%s"
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"
}
}
`, concurrentBuildLimit, rName))
}
1 change: 1 addition & 0 deletions website/docs/r/codebuild_project.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ The following arguments are optional:
* `build_batch_config` - (Optional) Defines the batch build options for the project.
* `build_timeout` - (Optional) Number of minutes, from 5 to 480 (8 hours), for AWS CodeBuild to wait until timing out any related build that does not get marked as completed. The default is 60 minutes.
* `cache` - (Optional) Configuration block. Detailed below.
* `concurrent_build_limit` - (Optional) Specify a maximum number of concurrent builds for the project. The value specified must be greater than 0 and less than the account concurrent running builds limit.
* `description` - (Optional) Short description of the project.
* `encryption_key` - (Optional) AWS Key Management Service (AWS KMS) customer master key (CMK) to be used for encrypting the build project's build output artifacts.
* `logs_config` - (Optional) Configuration block. Detailed below.
Expand Down