0

I am trying to set up an AWS CodeBuild project in Terraform:

resource "aws_codebuild_project" "example" {
  name          = "test-project"
  description   = "test_codebuild_project"
  build_timeout = "5"
  service_role  = "${aws_iam_role.example.arn}"

  artifacts {
    type      = "S3"
    location  = "${aws_s3_bucket.example.bucket}"
    name      = "example.zip"
    packaging = "ZIP"
    path      = "dev/api/${var.app_version}"
  }

This example works fine, but it will only ever save the build artifact example.zip to the folder set when terraform apply was run, since ${var.app_version} doesn't change on subsequent runs of this build.

How do I achieve something that, for example, takes a version number from the package.json file in the repo and uses that for ${var.app_version}?

1 Answer 1

1

This should not be done from the terraform side. The AWS CodeBuild docs mention how to achieve something like this by using the buildspec, although you might be constrained by only using the env variables provided by CodeBuild to add the variation to the name.

version: 0.2         
phases:
  build:
    commands:
      - rspec HelloWorld_spec.rb
artifacts:
  files:
    - '**/*'
  name: myname-$CODEBUILD_SOURCE_VERSION 

You can find the extended explanation here: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .