Terragrunt download module from specific branch

Viewed 3640

I started recently using terragrunt and have been wondering if it's possible to download module from specific branch not specfic tag ( or in addition to tag ) rather than by default master

Download specific tag from master:

terraform {
  source = "git@github.com:<repo>/infrastructure-modules.git//gcp/bucket?ref=v.0.0.1"
}

Download specific branch from repo ?

# Pseudo code
terraform {
  source = "git@github.com:<repo>/infrastructure-modules.git//gcp/bucket?ref=v.0.0.1%branch=test"
}
2 Answers

I was able to specify a branch using following:

terraform {
  source = "git@github.com:<repo>/infrastructure-modules.git//gcp/bucket?ref=branch-name"
}

Looking at the terragrunt cli/download_source_test.go source code, there is no apparent way to specify a branch.

That means you need to add a tag to that branch, and use that tag as ref.
That being said, check first if ref=<mybranch> works.

However, the OP potatopotato confirms in the comments that referencing the branch name directly does not work.

I just made changes on branch, and:

git add
 git commit
 git tag -a 'v1.branch'
 git push --follow-tags -u origin <branch_name>

and I could use the tag reference to the branch, not master.

And German Dautin's answer points to Terraform / Module Sources / Selecting a Revision.

By default, Terraform will clone and use the default branch (referenced by HEAD) in the selected repository. You can override this using the ref argument:

module "vpc" {
  source = "git::https://example.com/vpc.git?ref=v1.2.0"
}

The value of the ref argument can be any reference that would be accepted by the git checkout command, including branch and tag names.

So using a branch name is possible.

Related