4

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.

1

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

from my understanding, this variable only works with the primary source, not secondary source.
2

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]

1 Comment

from my understanding, this variable only works with the primary source, not secondary source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.