Skip to content

v1.2.4

Latest

Choose a tag to compare

@github-actions github-actions released this 03 Dec 13:52
Immutable release. Only release title and notes can be modified.
b0230d6

πŸ’‘ Tips Added

read-not-tracked β€” Points at every file read that reading filters miss

Terragrunt does not track a file read in a part of a config it evaluates only when it runs the unit: inputs, generate, remote_state, the hooks and extra_arguments of terraform, and the inputs of a variables block. A unit with this configuration is not selected by --filter 'reading=shared/provider.tf' or by a Git filter when shared/provider.tf changes:

# terragrunt.hcl

generate "provider" {
  path      = "provider.tf"
  if_exists = "overwrite"
  contents  = file("../shared/provider.tf")
}

The inputs-read-not-tracked tip pointed only at reads in inputs. The new read-not-tracked tip replaces it and points at a call to any file-reading function in any of these parts, including mark_as_read and mark_glob_as_read:

TIP (read-not-tracked): Terragrunt does not track files read in the parts of a config it evaluates only when it runs the unit, such as `inputs`, `generate`, and hooks, so reading and Git filters miss the units and stacks that read them.

Untracked file read in `generate`
 --> app/terragrunt.hcl:4:15
  |
4 |   contents  = file("../shared/provider.tf")
  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = Call `file` in `locals` and reference the local here.

See https://docs.terragrunt.com/features/filter/attributes#reading-based-expressions

Commands that track reads, such as run --all with a reading or Git filter and find --reading, print the tip.

See Reading-Based Expressions. Suppress the tip with --no-tip read-not-tracked or --no-tips. --no-tip inputs-read-not-tracked still works and suppresses the new tip.

variables-block β€” Points at inputs too large to pass to OpenTofu/Terraform

A unit with very large inputs can stop OpenTofu/Terraform from starting, with an argument list too long error.

With the variables-block experiment enabled, Terragrunt now prints the variables-block tip before the run when a unit's inputs are large enough to risk this error. It points at each input over the limit and shows the variables block to move it to:

TIP (variables-block): Terragrunt passes inputs to OpenTofu/Terraform as `TF_VAR_` environment variables, and inputs this large can make OpenTofu/Terraform fail with `argument list too long`.

Input over the 32 KiB soft limit
 --> ./terragrunt.hcl:6:3
  |
6 |   policy = local.policy
  |   ^^^^^^ `TF_VAR_policy` would be 41 KiB.
  |
  = Move it to a `variables` block, which writes it to a variables file:

    variables {
      kind     = "tfvar"
      nullable = true

      inputs = {
        policy = local.policy
      }
    }

See https://docs.terragrunt.com/reference/hcl/blocks/variables

Suppress the tip with --no-tip variables-block or --no-tips.

πŸ§ͺ Experiments Added

commands-variable β€” Read the lists of commands by name with the commands variable

Four functions, e.g. get_terraform_commands_that_need_vars(), each return the list of OpenTofu/Terraform commands that accept one set of flags. Enable the commands-variable experiment to read the lists by name: commands.accept_vars, commands.accept_locking, commands.accept_input, and commands.accept_parallelism.

# root.hcl
terraform {
  extra_arguments "retry_lock" {
    commands  = commands.accept_locking
    arguments = ["-lock-timeout=20m"]
  }
}
terragrunt run --all --experiment commands-variable -- plan

The functions keep their behavior. See the commands variable reference.

slash-fns β€” Convert path separators with to_slash and from_slash

On Windows, the Terragrunt functions that return a path, e.g. path_relative_to_include(), separate its parts with backslashes. Enable the slash-fns experiment to convert them: to_slash(path) replaces each path separator of the operating system with a forward slash, and from_slash(path) replaces each forward slash with the path separator of the operating system.

# root.hcl
remote_state {
  backend = "s3"
  config = {
    bucket = "my-tofu-state"
    key    = "${to_slash(path_relative_to_include())}/tofu.tfstate"
    region = "us-east-1"
  }
}
terragrunt run --all --experiment slash-fns -- plan

On Linux and macOS, both functions return the path unchanged.

πŸ§ͺ Experiments Updated

mcp-command β€” Tools write to disk only under --allow=fs-rw

The mcp server now reads files from disk and keeps what Terragrunt writes in memory until the tool call returns. A new fs-rw capability lets the tools write to disk.

OpenTofu/Terraform cannot see writes held in memory, so a server started without --allow=fs-rw changes in these ways:

  • plan is served only under both --allow=exec and --allow=fs-rw, and scaffold only under --allow=fs-rw.
  • fmt refuses a call that does not set check.
  • --dangerously-allow-apply is refused at startup.
  • Dependency outputs fall back to mock_outputs, and get_outputs reads the state itself, as both do without --allow=exec.
  • catalog cannot clone a remote repository, and a git-range filter is refused.

To keep planning, add the capability to the server's arguments:

terragrunt mcp --allow=exec --allow=fs-rw --allow=http --allow=env

offline-cas β€” run --all --cas-offline reports every missing source at once

A run --all with --cas-offline skipped the dependents of a unit whose source was missing from the store, so their own missing sources only showed up on a later run:

* downloading source url git::https://example.com/vpc.git?ref=v1.0.0
  ...
* Unit 'app' did not run due to a failure in 'vpc'

It now looks up every source a unit would download before any unit runs, and fails with one error for each source the store cannot serve, naming the units that use it. Nothing runs until the store holds them all:

* unit vpc: https://example.com/vpc.git at v1.0.0 is not in the local CAS store and --cas-offline forbids fetching it; ...
* unit app: https://example.com/app.git at v1.0.0 is not in the local CAS store and --cas-offline forbids fetching it; ...

offline-cas β€” --cas-offline fails on SMB sources

A run with --cas-offline fetched an SMB source from its share, since SMB has no cheap probe and nothing was recorded to resolve it from. It now fails with an error naming the source:

smb://fileserver/share/modules/vpc has no key an online run could record for --cas-offline; pin the source, for example with a literal checksum=sha256:<hex>, or drop the flag

An SMB archive pinned with a literal checksum= resolves offline from the store once an online run has stored it.

To run on a host with no network, populate a store on a connected host and copy it across.

otel-logs - Records link to the correct span

Each otel-logs record of a unit, including the output of its hooks, now links to a span of that unit. Records logged outside a unit link to the root command span, and a failed command exports its final error there.

The log buffer now holds 32768 records. At exit, Terragrunt prints the count of records that the exporter did not confirm, e.g. records dropped from a full buffer. See OpenTelemetry.

outputs-block β€” An output block sets its own mock_strategy

The mock_strategy block of outputs applied to every output of the unit. An output block now accepts its own mock_strategy block. Each attribute it sets overrides the same attribute of the outputs block, for that output only.

outputs {
  mock_strategy {
    allowed_commands = ["validate", "plan"]
  }

  output "vpc_id" {
    mock_value = "vpc-mock-id"
  }

  output "admin_role_arn" {
    mock_value = "arn:aws:iam::123456789012:role/mock"

    mock_strategy {
      allowed_commands = ["validate"]
    }
  }
}

Before the unit is applied, a plan of a dependent reads the mock value of vpc_id and no value for admin_role_arn. The attributes of a dependency block still win over both blocks. See A mock strategy for one output.

outputs-block - hcl validate --outputs-mocked checks that dependency outputs have mock values

A dependency.<name>.outputs.<output> reference with no mock value makes run --all plan fail before the dependency is applied. With the outputs-block experiment enabled, the new --outputs-mocked flag of terragrunt hcl validate reports each such reference:

terragrunt hcl validate --outputs-mocked --experiment outputs-block
error: Unmocked dependency output
 --> app/terragrunt.hcl:7:16
  |
7 |   subnet_ids = dependency.vpc.outputs.subnet_ids
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = dependency "vpc" sets no mock value for output "subnet_ids". Add
    "subnet_ids" to the mock_outputs of the dependency block, or set
    mock_value on output "subnet_ids" in the outputs block of the unit that
    the dependency reads.

The check covers the unit, the files it includes and its terragrunt.autoinclude.hcl file, which stack generate writes from the autoinclude block of a stack unit. A reference without a mock value stays valid without the flag. See --outputs-mocked.

outputs-block β€” A dependency on a stack reads the outputs blocks of its units

A dependency block that points at a stack did not read the outputs blocks of the units in the stack, so the dependent had to set mock_outputs for each unit. It now reads the outputs block of each unit the stack generates, with the same rules as for a dependency on one unit.

dependency "networking" {
  config_path = "../networking"
}

inputs = {
  vpc_id = dependency.networking.outputs.vpc.vpc_id
}

Before the stack is applied, dependency.networking.outputs.vpc.vpc_id resolves to the mock_value that the vpc unit declares, for each command that the mock_strategy of the unit allows. Generate the stack before you run the dependent. See With a dependency on a stack.

outputs-block β€” hcl validate --outputs checks mock_outputs keys

A mock_outputs key for an output that the dependency does not declare passed terragrunt hcl validate --outputs, e.g. a key with a typo or a key for a removed output. The flag now reports each such key of an object that a dependency block writes directly as mock_outputs, with an Undeclared mock output error.

Runs do not change. A dependent still reads a mock_outputs key that the dependency does not declare. See --outputs.

values-block β€” scaffold reads the declared values

Scaffolding a unit or stack that declares a values block wrote its terragrunt.values.hcl from the values.<name> reads in its configuration. A value read outside try() came out as "TODO", even when the block gave it a default.

With the values-block experiment enabled, scaffold and the Catalog TUI now read the block. A value without a default is required. A value with a default is commented out, and Terragrunt applies the default until you uncomment it. Each entry shows its declared description and type, and so does the form:

# === Required ===

# Name of the app.
# Type: string
name = "TODO"

# === Optional (declared defaults) ===

# Region to deploy to.
# Type: string
# region = "us-east-1"

See Scaffolding units and stacks.

values-block β€” Validate declared values with validation blocks

With the values-block experiment enabled, a value block in a values block now takes one or more validation blocks. Each has a condition that reads the value as values.<name>, and an error_message to report when the condition returns false:

values {
  value "name" {
    type = string

    validation {
      condition     = can(regex("^[a-z-]+$", values.name))
      error_message = "The name must be lowercase letters and dashes, not \"${values.name}\"."
    }
  }
}

stack generate reports a value that fails, at the line of the unit or stack block that passes it:

18:10:44.033 ERROR  Error: Invalid value "name" for unit "app"
18:10:44.033 ERROR    on /path/to/live/terragrunt.stack.hcl line 6, in unit "app":
18:10:44.033 ERROR     6:     name = "Payments"
18:10:44.033 ERROR  The name must be lowercase letters and dashes, not "Payments".
18:10:44.033 ERROR  This was checked by the validation rule at ./.terragrunt-stack/app/terragrunt.hcl:5,5-15.

Terragrunt runs the same checks on terragrunt.values.hcl when it reads the unit or stack, and checks each default too. See the validation block reference.

πŸ› Bug Fixes

azurerm dependency outputs are read from state with AKS workload identity

With use_aks_workload_identity or ARM_USE_AKS_WORKLOAD_IDENTITY=true, Terragrunt ran init and output for every dependency.

Terragrunt now reads the outputs from state. It signs in as the identity that the AKS workload identity webhook injects, as OpenTofu and Terraform do.

Bootstrapping the backend uses the same identity. Before this release, with use_azuread_auth = true, Terragrunt tried the Azure CLI first. See Authenticating with Azure.

azurerm OIDC token sources match OpenTofu

With ARM_USE_OIDC=true and the token in ARM_OIDC_TOKEN, bootstrapping an azurerm backend failed:

no token file specified. Check pod configuration or set TokenFilePath in the options

Terragrunt now reads oidc_token and ARM_OIDC_TOKEN.

It also uses a token or a token file before a token request URL, as OpenTofu does. With AZURE_FEDERATED_TOKEN_FILE and a request URL both set, Terragrunt authenticates with the file.

In Azure DevOps, Terragrunt requests the token for the service connection in ado_service_connection_id or ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID. A service connection comes before a token and a token file. With ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID, Terragrunt also reads dependency outputs from state. Before this release, it ran init and output for every dependency. See Authenticating with Azure.

Deep merging a feature block with a scalar default

When a unit and a file it included with merge_strategy = "deep" declared the same feature flag, and the default was a bool, number, string, or list, commands such as run, render, and hcl validate failed:

# root.hcl
feature "enable_monitoring" {
  default = false
}

# app/terragrunt.hcl
include "root" {
  path           = find_in_parent_folders("root.hcl")
  merge_strategy = "deep"
}

feature "enable_monitoring" {
  default = true
}
json: cannot unmarshal bool into Go struct field CtyJSONOutput.value of type map[string]interface {}

The two defaults now merge the way one attribute of inputs does under the deep strategy. A bool, number, or string default in the unit replaces the included one, two lists append, and two maps merge key by key. The example above runs with enable_monitoring = true.

-detailed-exitcode=true is treated like -detailed-exitcode

OpenTofu and Terraform accept -detailed-exitcode=true as the same flag as -detailed-exitcode, but Terragrunt recognized only the bare spelling. A plan -detailed-exitcode=true with changes exits 2, and Terragrunt reported that exit as a failure:

ERROR  Run failed: 2 errors occurred:
* Failed to execute "tofu plan -detailed-exitcode=true -no-color -input=false" in ./a/.terragrunt-cache/...
  exit status 2
* Unit 'b' did not run due to a failure in 'a'

Under run --all, the unit was reported Failed and its dependents were skipped.

Terragrunt now reads -detailed-exitcode the way it reads -destroy: with one dash or two, from the command line or from extra_arguments, and with a value parsed the way OpenTofu and Terraform parse boolean flags (1, t, T, TRUE, true and True). run --all returns the aggregate exit code for every true spelling.

A second filter no longer removes a Git expression's boundary

A Git expression with a boundary stopped respecting it once the command had another positive filter, such as a path or a reading= filter:

terragrunt find --filter '(./live)...[main...HEAD]' --filter './live/app'

Terragrunt then generated every stack in the Git worktrees, including catalog stacks outside ./live, and failed on one that reads values:

failed to generate stacks in worktrees: ... Unknown variable; There is no variable named "values".

Only filters that contain a Git expression now decide how far discovery reaches in the Git worktrees. This covers a boundary set with --discovery-boundary and filters read from a filters file.

A filter with no Git expression still selects from the working directory as before. In a Git worktree it selects only inside the boundary.

hcl validate no longer crashes on errors that read a sensitive value

terragrunt hcl validate crashed when it reported an error in an expression that reads a value from sensitive():

locals {
  password = sensitive(get_env("DB_PASSWORD"))
}

exclude {
  if      = local.password == ""
  actions = ["plan"]
}

It now reports the error, and leaves the sensitive value out of it.

Pull Requests

✨ Features

  • feat: Adding mcp command fs-rw capability by @yhakbar in #7451
  • feat: Extending tips for reads by @yhakbar in #7452
  • feat(outputs-block): add nullable outputs and fix hcl validate checks by @denis256 in #7401
  • feat: add commands variable behind commands-variable experiment by @denis256 in #7423
  • feat: Adding variables-block size tip by @yhakbar in #7453
  • feat: Adding to_slash and from_slash HCL functions behind the slash-fns experiment by @yhakbar in #7466
  • feat: Adding hcl validate --outputs-mocked check for dependency outputs by @denis256 in #7465
  • feat: Adding support for declared values blocks in scaffold by @yhakbar in #7464
  • feat: Adding values validation block by @yhakbar in #7468
  • feat(outputs-block): add output types, per-output mock strategy and stack units by @denis256 in #7428

πŸ› Bug Fixes

  • fix: Matching OpenTofu for Azure OIDC token sources by @denis256 in #7446
  • fix(config): log locals decode errors in the path.download check by @denis256 in #7437
  • fix: Addressing no-dot-terragrunt-cache stabilization criteria by @denis256 in #7421
  • fix: Addressing otel-logs stabilization criteria by @denis256 in #7429
  • fix: Fixing engine TRACEPARENT by @yhakbar in #7462
  • fix: Fixing zip symlink chain escape by @yhakbar in #7463
  • fix: Keeping a Git expression boundary when another filter is present by @yhakbar in #7502
  • fix: Using the OpenTofu sensitive mark in diagnostic expression values by @yhakbar in #7507
  • fix: Treating -detailed-exitcode=true like -detailed-exitcode by @yhakbar in #7508
  • fix: Deep merging feature blocks with scalar defaults by @yhakbar in #7509
  • fix: Fixing BubbleTea tests on Windows by @yhakbar in #7525

♻️ Refactors

  • refactor(telemetry): enable otel-logs with a WithLogs option by @denis256 in #7455

πŸ“– Documentation

  • docs: clean up released version gates for v1.2.3 by @github-actions[bot] in #7435
  • docs: Linking feedback discussions for auth-provider-cache, empty-dependency-outputs, and values-block by @yhakbar in #7443
  • docs: Checking off checkboxes for experiments by @yhakbar in #7438
  • docs: Ticking remaining criteria for graduated experiments by @yhakbar in #7439
  • docs: Retargeting v1.3.0 docs and changelog entries to v1.2.4 by @denis256 in #7459

βœ… Tests

  • test: Adding offline cache suite that runs Terragrunt with no network by @yhakbar in #7467
  • test: Removing serial pins from stack generation tests and adding a parallel generation race test by @yhakbar in #7469
  • test: Replacing TestRunAllFail with an in-memory feature flag test by @yhakbar in #7513

🧹 Chores