Martin Stigen
Martin Stigen

Reputation: 63

How to set 'Source version' for AWS CodeBuild project in Terraform

I am working with setting up a AWS CodeBuild project in Terraform. Looking at the Terraform docs https://www.terraform.io/docs/providers/aws/r/codebuild_project.html I cannot figure out which argument to use to define the source version as highlighted in the image:

Screenshot of the AWS CodeBuild UI

Is this option supported though Terraform? I would like the CodeBuild project to build from another branch's source code than master.

Upvotes: 4

Views: 2763

Answers (2)

Neeraj
Neeraj

Reputation: 1817

You may use the source_version argument


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

  source_version = "master"

  environment {
    compute_type                = "BUILD_GENERAL1_SMALL"
    image                       = "aws/codebuild/standard:1.0"
    type                        = "LINUX_CONTAINER"
    image_pull_credentials_type = "CODEBUILD"
...
...

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

    git_submodules_config {
        fetch_submodules = true
    }
  }
}

The feature was in development. Its now available, Please find the docs and issue below.

[docs] [issue]

Upvotes: 2

Arthur Shakhlamjian
Arthur Shakhlamjian

Reputation: 89

You can use source_version as it mentioned in the doc you referenced https://www.terraform.io/docs/providers/aws/r/codebuild_project.html

source_version = "master"

Specifying branch in source_version works the same way as in AWS console, e.g.

source_version = "refs/heads/my-feature-branch"

Other examples with tag, pull requests can be found here: https://docs.aws.amazon.com/codebuild/latest/userguide/sample-source-version.html

Upvotes: 3

Related Questions