terraform: fix issue merging provider version constraints

A bug in ConfigTreeDependencies, where a pointer was being updated
instead of the map value, meant that only the first provider config
version constraing to be processes was being stored. This fixes that
bug, so now the returned moduledeps.Providers could have multiple
version constraints.

The responsibility for resolving provider version selection continues to
lie in the command package's ProviderResolver (under plugins.go).
This commit is contained in:
Kristin Laemmert 2020-02-06 09:21:14 -05:00
parent c242f9389d
commit b4f21b6044
2 changed files with 8 additions and 3 deletions

View File

@ -94,7 +94,11 @@ func configTreeConfigDependencies(root *configs.Config, inheritProviders map[str
discoConstraints = discovery.NewConstraints(pCfg.Version.Required) discoConstraints = discovery.NewConstraints(pCfg.Version.Required)
} }
if existing, exists := providers[fqn]; exists { if existing, exists := providers[fqn]; exists {
existing.Constraints = existing.Constraints.Append(discoConstraints) constraints := existing.Constraints.Append(discoConstraints)
providers[fqn] = moduledeps.ProviderDependency{
Constraints: constraints,
Reason: moduledeps.ProviderDependencyExplicit,
}
} else { } else {
providers[fqn] = moduledeps.ProviderDependency{ providers[fqn] = moduledeps.ProviderDependency{
Constraints: discoConstraints, Constraints: discoConstraints,

View File

@ -42,7 +42,7 @@ func TestModuleTreeDependencies(t *testing.T) {
Name: "root", Name: "root",
Providers: moduledeps.Providers{ Providers: moduledeps.Providers{
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{ addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(), Constraints: discovery.ConstraintStr(">=1.0.0,>=2.0.0").MustParse(),
Reason: moduledeps.ProviderDependencyExplicit, Reason: moduledeps.ProviderDependencyExplicit,
}, },
}, },
@ -213,9 +213,10 @@ func TestModuleTreeDependencies(t *testing.T) {
Name: "root", Name: "root",
Providers: moduledeps.Providers{ Providers: moduledeps.Providers{
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{ addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(), Constraints: discovery.ConstraintStr(">=1.0.0,>=2.0.0").MustParse(),
Reason: moduledeps.ProviderDependencyExplicit, Reason: moduledeps.ProviderDependencyExplicit,
}, },
addrs.NewLegacyProvider("baz"): moduledeps.ProviderDependency{ addrs.NewLegacyProvider("baz"): moduledeps.ProviderDependency{
Constraints: discovery.AllVersions, Constraints: discovery.AllVersions,
Reason: moduledeps.ProviderDependencyFromState, Reason: moduledeps.ProviderDependencyFromState,