Fixes depends_on when overriding modules (#32796)

Fixes #32795
This commit is contained in:
Eugene Dementyev 2023-03-09 23:53:13 +13:00 committed by GitHub
parent 189820b6ea
commit 36aac6b498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -190,12 +190,12 @@ func (mc *ModuleCall) merge(omc *ModuleCall) hcl.Diagnostics {
// We don't allow depends_on to be overridden because that is likely to
// cause confusing misbehavior.
if len(mc.DependsOn) != 0 {
if len(omc.DependsOn) != 0 {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Unsupported override",
Detail: "The depends_on argument may not be overridden.",
Subject: mc.DependsOn[0].SourceRange().Ptr(), // the first item is the closest range we have
Subject: omc.DependsOn[0].SourceRange().Ptr(), // the first item is the closest range we have
})
}

View File

@ -117,6 +117,26 @@ func TestModuleOverrideModule(t *testing.T) {
Byte: 17,
},
},
DependsOn: []hcl.Traversal{
{
hcl.TraverseRoot{
Name: "null_resource",
SrcRange: hcl.Range{
Filename: "testdata/valid-modules/override-module/primary.tf",
Start: hcl.Pos{Line: 11, Column: 17, Byte: 149},
End: hcl.Pos{Line: 11, Column: 30, Byte: 162},
},
},
hcl.TraverseAttr{
Name: "test",
SrcRange: hcl.Range{
Filename: "testdata/valid-modules/override-module/primary.tf",
Start: hcl.Pos{Line: 11, Column: 30, Byte: 162},
End: hcl.Pos{Line: 11, Column: 35, Byte: 167},
},
},
},
},
Providers: []PassedProviderConfig{
{
InChild: &ProviderConfigRef{

View File

@ -8,4 +8,6 @@ module "example" {
providers = {
test = test.foo
}
depends_on = [null_resource.test]
}
resource "null_resource" "test" {}