Skip to content

Commit

Permalink
feat: Integrate includes into units reading (#3563)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhakbar authored Nov 14, 2024
1 parent d5ed96d commit 4389886
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 7 additions & 3 deletions configstack/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,18 @@ func (modules TerraformModules) flagIncludedDirs(opts *options.TerragruntOptions
// flagUnitsThatAreIncluded iterates over a module slice and flags all modules that include at least one file in
// the specified include list on the TerragruntOptions ModulesThatInclude attribute.
func (modules TerraformModules) flagUnitsThatAreIncluded(opts *options.TerragruntOptions) (TerraformModules, error) {
// If no ModulesThatInclude is specified return the modules list instantly
if len(opts.ModulesThatInclude) == 0 {
// The two flags ModulesThatInclude and UnitsReading should both be considered when determining which
// units to include in the run queue.
unitsThatInclude := append(opts.ModulesThatInclude, opts.UnitsReading...)

// If no unitsThatInclude is specified return the modules list instantly
if len(unitsThatInclude) == 0 {
return modules, nil
}

modulesThatIncludeCanonicalPaths := []string{}

for _, includePath := range opts.ModulesThatInclude {
for _, includePath := range unitsThatInclude {
canonicalPath, err := util.CanonicalPath(includePath, opts.WorkingDir)
if err != nil {
return nil, err
Expand Down
11 changes: 7 additions & 4 deletions docs/_docs/04_reference/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1297,9 +1297,12 @@ and then will apply this filter on the set of modules that it found.
You can pass this argument in multiple times to provide a list of include files to consider. When multiple files are
passed in, the set will be the union of modules that includes at least one of the files in the list.

NOTE: When using relative paths, the paths are relative to the working directory. This is either the current working
**NOTE**: When using relative paths, the paths are relative to the working directory. This is either the current working
directory, or any path passed in to [terragrunt-working-dir](#terragrunt-working-dir).

**TIP**: This flag is functionally covered by the `--terragrunt-queue-include-units-reading` flag, but is more explicitly
only for the `include` configuration block.

### terragrunt-queue-include-units-reading

**CLI Arg**: `--terragrunt-queue-include-units-reading`<br/>
Expand All @@ -1313,11 +1316,11 @@ directory, or any path passed in to [terragrunt-working-dir](#terragrunt-working
- [destroy-all (DEPRECATED: use run-all)](#destroy-all-deprecated-use-run-all)
- [validate-all (DEPRECATED: use run-all)](#validate-all-deprecated-use-run-all)

This flag works very similarly to the `--terragrunt-modules-that-include` flag, but instead of looking for included configurations,
it instead looks for configurations that read a given file.
This flag works very similarly to the `--terragrunt-modules-that-include` flag, but instead of looking only for included configurations,
it also looks for configurations that read a given file.

When passed in, the `*-all` commands will include all units (modules) that read a given file into the queue. This is useful
when you want to trigger an update on all units that read a given file using HCL functions in their configurations.
when you want to trigger an update on all units that read or include a given file using HCL functions in their configurations.

Consider the following folder structure:

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/units-reading/including/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include "shared" {
path = find_in_parent_folders("shared.hcl")
}

0 comments on commit 4389886

Please sign in to comment.