Skip to content

terragrunt.star

Move Terragrunt and Terraform module sources to a new ?ref= tag.

Edits are line-based, so comments and alignment stay as they were.

load("@fleet//terragrunt.star", "sources", "set_source_ref")
Function What it does
sources Lists every module source pinned with ?ref=.
set_source_ref Sets the ?ref= of every module source that matches.

sources

sources(repo)

Lists every module source pinned with ?ref=.

Arguments

Name Description
repo The repo passed to change(repo).

Returns: A list of dicts with path, source and ref, in file order.

Example

[s["source"] + " " + s["ref"] for s in sources(repo)]
# returns ["git::https://github.com/acme/modules.git//vpc v1.2.0"]

live/prod/vpc/terragrunt.hcl

terraform {
  source = "git::https://github.com/acme/modules.git//vpc?ref=v1.2.0"
}

Used in: terragrunt-module-ref

Source

set_source_ref

set_source_ref(repo, source, ref)

Sets the ?ref= of every module source that matches.

Covers source in terragrunt.hcl terraform blocks and in Terraform module blocks. Sources pinned to a commit SHA are left alone.

Arguments

Name Description
repo The repo passed to change(repo).
source The source before ?ref=; * matches any run of characters, so git::https://github.com/acme/modules.git//* covers every module in that repository.
ref The new tag or branch.

Returns: The list of paths that changed.

Example

set_source_ref(repo, "git::https://github.com/acme/modules.git//*", "v1.3.0")
# returns ["live/prod/vpc/terragrunt.hcl", "main.tf"]

live/prod/vpc/terragrunt.hcl

terraform {
  source = "git::https://github.com/acme/modules.git//vpc?ref=v1.2.0"
}

main.tf

module "db" {
  source = "git::https://github.com/acme/modules.git//rds?ref=v1.1.0"
}

live/prod/vpc/terragrunt.hcl

terraform {
  source = "git::https://github.com/acme/modules.git//vpc?ref=v1.3.0"
}

main.tf

module "db" {
  source = "git::https://github.com/acme/modules.git//rds?ref=v1.3.0"
}

Used in: terragrunt-module-ref

Source