This template configures an AWS CodeBuild project with local caching options to optimize build times and performance.

Terraform Template

resource "aws_codebuild_project" "project-with-cache" {

  artifacts {
    type = "NO_ARTIFACTS"
  }
  build_timeout = 5

  cache {
    modes = ["LOCAL_DOCKER_LAYER_CACHE", "LOCAL_SOURCE_CACHE"]
    type = "LOCAL"
  }
  description = "test_codebuild_project_cache"

  environment {
    compute_type = "BUILD_GENERAL1_SMALL"
    image = "aws/codebuild/amazonlinux2-x86_64-standard:4.0"
    image_pull_credentials_type = "CODEBUILD"
    type = "LINUX_CONTAINER"
  }
  name = "test-project-cache"
  queued_timeout = 5
  service_role = "aws_iam_role.example.arn"

  source {
    git_clone_depth = 1
    location = "https://github.com/mitchellh/packer.git"
    type = "GITHUB"
  }

  tags = {
    Environment = "Test"
  }
}