Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep Merge strategy exception for some of the values #3968

Open
alandreasyans opened this issue Mar 5, 2025 · 0 comments
Open

Deep Merge strategy exception for some of the values #3968

alandreasyans opened this issue Mar 5, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@alandreasyans
Copy link

alandreasyans commented Mar 5, 2025

Conditional Deep Merge Control in Terragrunt Includes

Background

Terragrunt's deep merge strategy is a powerful feature for managing configuration across multiple HCL files. However, current implementations lack granular control over variable merging.

Current Limitations

Developers currently face challenges when:

  • Wanting to selectively merge some variables deeply
  • Needing to completely replace specific variables
  • Implementing conditional merge strategies within the same configuration

Detailed Problem Statement

Existing Merge Behavior

When using include with merge_strategy = "deep", Terragrunt performs a comprehensive deep merge of all input variables. This approach doesn't provide flexibility for:

  • Partial variable overrides
  • Selective merge control
  • Complex configuration scenarios

Proposed Solution

Introduce a mechanism to provide per-variable merge control, such as:

  • An ignore_deep_merge flag
  • Explicit merge strategy configuration
  • Conditional merge annotations

Parent source.hcl:

terraform {
  source = "${get_repo_root()}/modules//my_module"
}

inputs = {
  my_list_var1 = ["1","2","3","4"]
  my_list_var2 = ["5","6","7","8"]
}

Child child.hcl:

include "root" {
  path = find_in_parent_folders("root.hcl")
}

include "source" {
  path = "${dirname(find_in_parent_folders("root.hcl"))}/source.hcl"
  merge_strategy = "deep"
}

inputs = {
  # Proposed: Granular merge control
  my_list_var1 = ["x","y"]        # Deep merge (keeps original + new)
  my_list_var2 = ["a","b"]         # Shallow merge (replaces original)
}

Expected Behavior

my_list_var1: ["1","2","3","4", "x", "y"]
my_list_var2: ["a", "b"]

Proposed Syntax Options

Option 1: Inline Annotation

inputs = {
  my_list_var2 = ["a", "b"] # ignore_deep_merge
}
Option 2: Explicit Configuration
inputs = {
  my_list_var2 = {
    value = ["a", "b"]
    ignore_deep_merge = true
  }
}
Option 3: Merge Strategy Decorator
inputs = {
  my_list_var2 = merge(["a", "b"], {
    _merge_strategy = "shallow"
  })
}
@alandreasyans alandreasyans added the enhancement New feature or request label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant