You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Declaring two `dependency` blocks with the same label in one `terragrunt.hcl` configuration file parsed without error, and then quietly resolved every reference to that label to whichever block came last. The blocks before it were silently overridden:
9
+
10
+
```hcl
11
+
dependency "vpc" {
12
+
config_path = "../vpc-us-east-1"
13
+
}
14
+
15
+
dependency "vpc" {
16
+
config_path = "../vpc-us-west-2"
17
+
}
18
+
19
+
inputs = {
20
+
# Reads ../vpc-us-west-2.
21
+
vpc_id = dependency.vpc.outputs.vpc_id
22
+
}
23
+
```
24
+
25
+
Terragrunt now warns when it finds this. With the new [`duplicate-dependency-labels`](/reference/strict-controls/active#duplicate-dependency-labels) strict control enabled, the warning becomes an error naming the address the blocks share:
26
+
27
+
```bash
28
+
terragrunt run plan --strict-control duplicate-dependency-labels
29
+
```
30
+
31
+
```text
32
+
/path/to/terragrunt.hcl: dependency vpc is declared more than once; every dependency needs an address of its own
33
+
```
34
+
35
+
Give each block a label of its own. A configuration that was relying on the shadowing to pick the last block should keep only that block.
Copy file name to clipboardExpand all lines: docs/src/data/commands/render.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,6 +138,6 @@ dependency "shard" {
138
138
# }
139
139
```
140
140
141
-
The expanded blocks are in comments because expanded blocks are not valid HCL configurations (Terragrunt disallows having multiple `dependency` blocks with the same label). They are present as comments to help you predict how Terragrunt will expand the block with an `expansion` block.
141
+
The expanded blocks are in comments because they are not a valid Terragrunt configuration: they all carry one label, and only the last block with a given label can be referenced. Terragrunt warns about that, and rejects it outright under the `duplicate-dependency-labels` [strict control](/reference/strict-controls/active#duplicate-dependency-labels). They are present as comments to help you predict how Terragrunt will expand the block with an `expansion` block.
142
142
143
143
A `dependency` block with no `expansion` block renders as it always has.
Throw an error when two `dependency` blocks in one configuration claim the same address.
7
+
8
+
### `duplicate-dependency-labels` - Reason
9
+
10
+
Two `dependency` blocks written with the same label both parse, and Terragrunt then resolves every reference to that label to whichever block came last. The blocks before it are unreachable, with nothing to say so:
11
+
12
+
```hcl
13
+
dependency "vpc" {
14
+
config_path = "../vpc-us-east-1"
15
+
}
16
+
17
+
dependency "vpc" {
18
+
config_path = "../vpc-us-west-2"
19
+
}
20
+
21
+
inputs = {
22
+
# Reads ../vpc-us-west-2. The first block may as well not be there.
23
+
vpc_id = dependency.vpc.outputs.vpc_id
24
+
}
25
+
```
26
+
27
+
Terragrunt warns about this by default. Enabling the control turns it into an error naming the address the blocks share:
28
+
29
+
```text
30
+
/path/to/terragrunt.hcl: dependency vpc is declared more than once; every dependency needs an address of its own
31
+
```
32
+
33
+
Give each block a label of its own. A configuration that was relying on the shadowing to pick the last block should keep only that block.
34
+
35
+
Blocks are compared by the address they resolve to rather than by label alone, so the elements of a block expanded with the [`block-iteration`](/reference/experiments/active#block-iteration) experiment, which all carry the label the block was written with, remain valid.
// LegacyGCSDeprecationWarning is the warning text emitted when a plain
@@ -234,6 +238,15 @@ func New() strict.Controls {
234
238
Warning: "Using an `include` block without a label is deprecated. Please use the `include` block with a label instead. For more information, see https://docs.terragrunt.com/migrate/bare-include/",
235
239
},
236
240
241
+
&Control{
242
+
Name: DuplicateDependencyLabels,
243
+
Description: "Prevents two `dependency` blocks in one configuration from claiming the same address.",
244
+
Error: errors.New( //nolint:staticcheck // user-facing message intentionally written as full sentences
245
+
"Two `dependency` blocks address the same dependency. Give each block a label of its own.",
246
+
),
247
+
Warning: "Two `dependency` blocks address the same dependency, so only the last of them can be referenced and the rest are unreachable. Give each block a label of its own. In a future version of Terragrunt, this will result in an error.",
248
+
},
249
+
237
250
&Control{
238
251
Name: DoubleStar,
239
252
Description: "Use the `**` glob pattern to select all files in a directory and its subdirectories.",
0 commit comments