Skip to content

Commit 3f6b9d8

Browse files
committed
add generate clock experiment
1 parent ee13e19 commit 3f6b9d8

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: stacks-generate-block
3+
status: active
4+
since: "1.0.1"
5+
---
6+
7+
Process generate blocks during stack generation so that dependency resolution sees correct files.
8+
9+
### `stacks-generate-block` - What it does
10+
When Terragrunt generates a stack (via `stack generate` or `stack run`), units may contain `generate` blocks with conditional logic such as `if_disabled = "remove"`. Without this experiment, those generate blocks are not processed during stack generation. This means that when a dependent unit runs and triggers dependency resolution via `tofu/terraform output -json`, the generated unit directory may contain stale or conflicting files (e.g., duplicate `required_providers` blocks), causing an error in OpenTofu/Terraform.
11+
12+
Enabling this experiment makes Terragrunt process all `generate` blocks for each unit immediately after copying files during stack generation. This ensures the generated directory is in the correct state for dependency resolution.
13+
14+
```bash
15+
terragrunt stack run --experiment stacks-generate-block -- plan
16+
```
17+
18+
### `stacks-generate-block` - How to provide feedback
19+
Provide your feedback on [#5702](https://github.com/gruntwork-io/terragrunt/issues/5702).
20+
21+
### `stacks-generate-block` - Criteria for stabilization
22+
To transition the `stacks-generate-block` feature to a stable release, the following must be addressed, at a minimum:
23+
24+
- [ ] Integration testing across different generate block configurations (`if_disabled`, `if_exists`, `disable`)
25+
- [ ] Performance impact assessment for stacks with many units containing generate blocks
26+
- [ ] Ensure correct behavior with remote sources
27+
- [ ] Community feedback on real-world usage

pkg/config/stack.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func generateComponent(ctx context.Context, l log.Logger, opts generateOpts, cmp
301301
}
302302

303303
// Process generate blocks in the generated directory so that dependency
304-
// resolution via "terraform output -json" sees the correct files (#5702).
304+
// resolution via "tofu/terraform output -json" sees the correct files (#5702).
305305
// Generate block processing is best-effort during stack generation.
306306
// Failure here doesn't prevent the stack from being generated;
307307
// the unit will simply lack the generated file adjustments.
@@ -334,6 +334,10 @@ func processUnitGenerateBlocks(ctx context.Context, l log.Logger, pctx *ParsingC
334334
return nil
335335
}
336336

337+
if cfg == nil {
338+
return nil
339+
}
340+
337341
for name, genCfg := range cfg.GenerateConfigs {
338342
if err := codegen.WriteToFile(l, unitDir, &genCfg); err != nil {
339343
return errors.Errorf("failed to process generate block %q (path %q) in %s: %w", name, genCfg.Path, unitDir, err)

0 commit comments

Comments
 (0)