core: fix inheritence checks in ConfigTreeDependencies

Due to some disagreement about what representation of provider addresses
we were using, the inherited providers map wasn't matching. Now we'll
consistenly use the "compact" form (just the provider name and optional
alias).

Also includes some other tweaks to make this test better-behaved.
This commit is contained in:
Martin Atkins 2018-05-08 16:13:02 -07:00
parent 880d971328
commit e40e3b9ad8
2 changed files with 6 additions and 9 deletions

View File

@ -35,6 +35,7 @@ func configTreeConfigDependencies(root *configs.Config, inheritProviders map[str
// *isn't* at the root, but in practice that can never happen.
return &moduledeps.Module{
Name: "root",
Providers: make(moduledeps.Providers),
}
}
@ -109,7 +110,7 @@ func configTreeConfigDependencies(root *configs.Config, inheritProviders map[str
}
reason := moduledeps.ProviderDependencyImplicit
if _, inherited := inheritProviders[addr.String()]; inherited {
if _, inherited := inheritProviders[addr.StringCompact()]; inherited {
reason = moduledeps.ProviderDependencyInherited
}

View File

@ -3,7 +3,7 @@ package terraform
import (
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/go-test/deep"
"github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform/moduledeps"
"github.com/hashicorp/terraform/plugin/discovery"
@ -249,12 +249,8 @@ func TestModuleTreeDependencies(t *testing.T) {
}
got := ConfigTreeDependencies(root, test.State)
if !got.Equal(test.Want) {
t.Errorf(
"wrong dependency tree\ngot: %s\nwant: %s",
spew.Sdump(got),
spew.Sdump(test.Want),
)
for _, problem := range deep.Equal(got, test.Want) {
t.Error(problem)
}
})
}