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

Fix unsupported properties for lambda compute types in codebuild. #35043

Merged
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/35043.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_codebuild_project: Prevent erroneous diffs on `build_timeout` and `queued_timeout` for Lambda compute types
```
18 changes: 18 additions & 0 deletions internal/service/codebuild/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,30 @@ func ResourceProject() *schema.Resource {
Optional: true,
Default: 60,
ValidateFunc: validation.IntBetween(5, 480),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if d.Get("environment.0.type") == codebuild.EnvironmentTypeArmLambdaContainer {
return true
}
if d.Get("environment.0.type") == codebuild.EnvironmentTypeLinuxLambdaContainer {
return true
}
return false
},
},
"queued_timeout": {
Type: schema.TypeInt,
Optional: true,
Default: 480,
ValidateFunc: validation.IntBetween(5, 480),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if d.Get("environment.0.type") == codebuild.EnvironmentTypeArmLambdaContainer {
return true
}
if d.Get("environment.0.type") == codebuild.EnvironmentTypeLinuxLambdaContainer {
return true
}
return false
},
},
"badge_enabled": {
Type: schema.TypeBool,
Expand Down
58 changes: 58 additions & 0 deletions internal/service/codebuild/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,40 @@ func TestAccCodeBuildProject_armContainer(t *testing.T) {
})
}

func TestAccCodeBuildProject_linuxLambdaContainer(t *testing.T) {
ctx := acctest.Context(t)
var project codebuild.Project
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_codebuild_project.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, codebuild.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckProjectDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccProjectConfig_linuxLambdaContainer(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckProjectExists(ctx, resourceName, &project),
resource.TestCheckResourceAttr(resourceName, "environment.#", "1"),
resource.TestCheckResourceAttr(resourceName, "environment.0.compute_type", codebuild.ComputeTypeBuildLambda1gb),
resource.TestCheckResourceAttr(resourceName, "environment.0.environment_variable.#", "0"),
resource.TestCheckResourceAttr(resourceName, "environment.0.image", "aws/codebuild/amazonlinux-x86_64-lambda-standard:go1.21"),
resource.TestCheckResourceAttr(resourceName, "environment.0.privileged_mode", "false"),
resource.TestCheckResourceAttr(resourceName, "environment.0.image_pull_credentials_type", codebuild.ImagePullCredentialsTypeCodebuild),
resource.TestCheckResourceAttr(resourceName, "environment.0.type", codebuild.EnvironmentTypeLinuxLambdaContainer),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccCodeBuildProject_Artifacts_artifactIdentifier(t *testing.T) {
ctx := acctest.Context(t)
var project codebuild.Project
Expand Down Expand Up @@ -4276,6 +4310,30 @@ resource "aws_codebuild_project" "test" {
`, rName, testAccGitHubSourceLocationFromEnv()))
}

func testAccProjectConfig_linuxLambdaContainer(rName string) string {
return acctest.ConfigCompose(testAccProjectConfig_Base_ServiceRole(rName), fmt.Sprintf(`
resource "aws_codebuild_project" "test" {
name = %[1]q
service_role = aws_iam_role.test.arn

artifacts {
type = "NO_ARTIFACTS"
}

environment {
compute_type = "BUILD_LAMBDA_1GB"
image = "aws/codebuild/amazonlinux-x86_64-lambda-standard:go1.21"
type = "LINUX_LAMBDA_CONTAINER"
}

source {
location = %[2]q
type = "GITHUB"
}
}
`, rName, testAccGitHubSourceLocationFromEnv()))
}

func testAccProjectConfig_artifactsArtifactIdentifier(rName string, artifactIdentifier string) string {
return acctest.ConfigCompose(
testAccProjectConfig_Base_ServiceRole(rName),
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/codebuild_project.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ The following arguments are optional:

* `badge_enabled` - (Optional) Generates a publicly-accessible URL for the projects build badge. Available as `badge_url` attribute when enabled.
* `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.
* `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. The `build_timeout` property is not available on the `Lambda` compute type.
* `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.
Expand All @@ -246,7 +246,7 @@ The following arguments are optional:
* `logs_config` - (Optional) Configuration block. Detailed below.
* `project_visibility` - (Optional) Specifies the visibility of the project's builds. Possible values are: `PUBLIC_READ` and `PRIVATE`. Default value is `PRIVATE`.
* `resource_access_role` - The ARN of the IAM role that enables CodeBuild to access the CloudWatch Logs and Amazon S3 artifacts for the project's builds.
* `queued_timeout` - (Optional) Number of minutes, from 5 to 480 (8 hours), a build is allowed to be queued before it times out. The default is 8 hours.
* `queued_timeout` - (Optional) Number of minutes, from 5 to 480 (8 hours), a build is allowed to be queued before it times out. The default is 8 hours. The `queued_timeout` property is not available on the `Lambda` compute type.
* `secondary_artifacts` - (Optional) Configuration block. Detailed below.
* `secondary_sources` - (Optional) Configuration block. Detailed below.
* `secondary_source_version` - (Optional) Configuration block. Detailed below.
Expand Down Expand Up @@ -288,13 +288,13 @@ The following arguments are optional:
### environment

* `certificate` - (Optional) ARN of the S3 bucket, path prefix and object key that contains the PEM-encoded certificate.
* `compute_type` - (Required) Information about the compute resources the build project will use. Valid values: `BUILD_GENERAL1_SMALL`, `BUILD_GENERAL1_MEDIUM`, `BUILD_GENERAL1_LARGE`, `BUILD_GENERAL1_2XLARGE`. `BUILD_GENERAL1_SMALL` is only valid if `type` is set to `LINUX_CONTAINER`. When `type` is set to `LINUX_GPU_CONTAINER`, `compute_type` must be `BUILD_GENERAL1_LARGE`.
* `compute_type` - (Required) Information about the compute resources the build project will use. Valid values: `BUILD_GENERAL1_SMALL`, `BUILD_GENERAL1_MEDIUM`, `BUILD_GENERAL1_LARGE`, `BUILD_GENERAL1_2XLARGE`, `BUILD_LAMBDA_1GB`, `BUILD_LAMBDA_2GB`, `BUILD_LAMBDA_4GB`, `BUILD_LAMBDA_8GB`, `BUILD_LAMBDA_10GB`. `BUILD_GENERAL1_SMALL` is only valid if `type` is set to `LINUX_CONTAINER`. When `type` is set to `LINUX_GPU_CONTAINER`, `compute_type` must be `BUILD_GENERAL1_LARGE`. When `type` is set to `LINUX_LAMBDA_CONTAINER` or `ARM_LAMBDA_CONTAINER`, `compute_type` must be `BUILD_LAMBDA_XGB`.`
* `environment_variable` - (Optional) Configuration block. Detailed below.
* `image_pull_credentials_type` - (Optional) Type of credentials AWS CodeBuild uses to pull images in your build. Valid values: `CODEBUILD`, `SERVICE_ROLE`. When you use a cross-account or private registry image, you must use SERVICE_ROLE credentials. When you use an AWS CodeBuild curated image, you must use CodeBuild credentials. Defaults to `CODEBUILD`.
* `image` - (Required) Docker image to use for this build project. Valid values include [Docker images provided by CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html) (e.g `aws/codebuild/amazonlinux2-x86_64-standard:4.0`), [Docker Hub images](https://hub.docker.com/) (e.g., `hashicorp/terraform:latest`), and full Docker repository URIs such as those for ECR (e.g., `137112412989.dkr.ecr.us-west-2.amazonaws.com/amazonlinux:latest`).
* `privileged_mode` - (Optional) Whether to enable running the Docker daemon inside a Docker container. Defaults to `false`.
* `registry_credential` - (Optional) Configuration block. Detailed below.
* `type` - (Required) Type of build environment to use for related builds. Valid values: `LINUX_CONTAINER`, `LINUX_GPU_CONTAINER`, `WINDOWS_CONTAINER` (deprecated), `WINDOWS_SERVER_2019_CONTAINER`, `ARM_CONTAINER`. For additional information, see the [CodeBuild User Guide](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html).
* `type` - (Required) Type of build environment to use for related builds. Valid values: `LINUX_CONTAINER`, `LINUX_GPU_CONTAINER`, `WINDOWS_CONTAINER` (deprecated), `WINDOWS_SERVER_2019_CONTAINER`, `ARM_CONTAINER`, `LINUX_LAMBDA_CONTAINER`, `ARM_LAMBDA_CONTAINER`. For additional information, see the [CodeBuild User Guide](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html).

#### environment: environment_variable

Expand Down
Loading