configs: include "providers" when overriding modules (#25496)

This commit is contained in:
Kristin Laemmert 2020-08-11 11:46:40 -04:00 committed by GitHub
parent 6621501ae3
commit df4627fecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 0 deletions

View File

@ -164,6 +164,10 @@ func (mc *ModuleCall) merge(omc *ModuleCall) hcl.Diagnostics {
mc.Config = MergeBodies(mc.Config, omc.Config)
if len(omc.Providers) != 0 {
mc.Providers = omc.Providers
}
// We don't allow depends_on to be overridden because that is likely to
// cause confusing misbehavior.
if len(mc.DependsOn) != 0 {

View File

@ -109,6 +109,32 @@ func TestModuleOverrideModule(t *testing.T) {
Byte: 17,
},
},
Providers: []PassedProviderConfig{
{
InChild: &ProviderConfigRef{
Name: "test",
NameRange: hcl.Range{
Filename: "testdata/valid-modules/override-module/b_override.tf",
Start: hcl.Pos{Line: 7, Column: 5, Byte: 97},
End: hcl.Pos{Line: 7, Column: 9, Byte: 101},
},
},
InParent: &ProviderConfigRef{
Name: "test",
NameRange: hcl.Range{
Filename: "testdata/valid-modules/override-module/b_override.tf",
Start: hcl.Pos{Line: 7, Column: 12, Byte: 104},
End: hcl.Pos{Line: 7, Column: 16, Byte: 108},
},
Alias: "b_override",
AliasRange: &hcl.Range{
Filename: "testdata/valid-modules/override-module/b_override.tf",
Start: hcl.Pos{Line: 7, Column: 16, Byte: 108},
End: hcl.Pos{Line: 7, Column: 27, Byte: 119},
},
},
},
},
}
// We're going to extract and nil out our hcl.Body here because DeepEqual

View File

@ -4,4 +4,8 @@ module "example" {
foo = "a_override foo"
new = "a_override new"
providers = {
test = test.a_override
}
}

View File

@ -2,4 +2,8 @@
module "example" {
new = "b_override new"
newer = "b_override newer"
providers = {
test = test.b_override
}
}

View File

@ -4,4 +4,8 @@ module "example" {
kept = "primary kept"
foo = "primary foo"
providers = {
test = test.foo
}
}