core: Update ProviderTransformer tests for new ImportTarget interface

Prior to the refactoring to move provider address parsing/selection up
into the frontend, there was some logic here to just-in-time default a
provider config based on the given resource type.

This is now expected to happen at a higher layer, with ImportTarget
expecting an already-valid provider configuration address.

The normal import codepath was already updated with this in mind, but some
of the provider transform tests are using ImportStateTransformer as a
shortcut for getting some resource nodes added to the graph, and so those
tests now need to include a valid provider address in their ImportTarget
values.

Also includes some adjustments to test output to make the tests easier
to debug.
This commit is contained in:
Martin Atkins 2018-05-08 11:36:07 -07:00
parent f107a4bc33
commit 3ed396ad5c
2 changed files with 31 additions and 8 deletions

View File

@ -27,7 +27,7 @@ func (t *ImportStateTransformer) Transform(g *Graph) error {
type graphNodeImportState struct {
Addr addrs.AbsResourceInstance // Addr is the resource address to import into
ID string // ID is the ID to import as
ProviderAddr addrs.AbsProviderConfig // Provider address given by the user
ProviderAddr addrs.AbsProviderConfig // Provider address given by the user, or implied by the resource type
ResolvedProvider addrs.AbsProviderConfig // provider node address after resolution
states []*InstanceState
@ -41,11 +41,16 @@ var (
)
func (n *graphNodeImportState) Name() string {
return fmt.Sprintf("%s (import id: %s)", n.Addr, n.ID)
return fmt.Sprintf("%s (import id %q)", n.Addr, n.ID)
}
// GraphNodeProviderConsumer
func (n *graphNodeImportState) ProvidedBy() (addrs.AbsProviderConfig, bool) {
// We assume that n.ProviderAddr has been properly populated here.
// It's the responsibility of the code creating a graphNodeImportState
// to populate this, possibly by calling DefaultProviderConfig() on the
// resource address to infer an implied provider from the resource type
// name.
return n.ProviderAddr, false
}

View File

@ -60,6 +60,9 @@ func TestProviderTransformer_moduleChild(t *testing.T) {
"qux",
addrs.NoKey,
),
ProviderAddr: addrs.RootModuleInstance.
Child("moo", addrs.NoKey).
ProviderConfigDefault("foo"),
ID: "bar",
},
},
@ -67,6 +70,7 @@ func TestProviderTransformer_moduleChild(t *testing.T) {
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
t.Logf("graph after ImportStateTransformer:\n%s", g.String())
}
{
@ -74,6 +78,7 @@ func TestProviderTransformer_moduleChild(t *testing.T) {
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
t.Logf("graph after MissingProviderTransformer:\n%s", g.String())
}
{
@ -81,12 +86,13 @@ func TestProviderTransformer_moduleChild(t *testing.T) {
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
t.Logf("graph after ProviderTransformer:\n%s", g.String())
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testTransformProviderModuleChildStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected)
}
}
@ -271,6 +277,9 @@ func TestMissingProviderTransformer_moduleChild(t *testing.T) {
"qux",
addrs.NoKey,
),
ProviderAddr: addrs.RootModuleInstance.
Child("moo", addrs.NoKey).
ProviderConfigDefault("foo"),
ID: "bar",
},
},
@ -313,6 +322,9 @@ func TestMissingProviderTransformer_moduleGrandchild(t *testing.T) {
"qux",
addrs.NoKey,
),
ProviderAddr: addrs.RootModuleInstance.
Child("moo", addrs.NoKey).
ProviderConfigDefault("foo"),
ID: "bar",
},
},
@ -352,6 +364,9 @@ func TestParentProviderTransformer(t *testing.T) {
"qux",
addrs.NoKey,
),
ProviderAddr: addrs.RootModuleInstance.
Child("moo", addrs.NoKey).
ProviderConfigDefault("foo"),
ID: "bar",
},
},
@ -403,6 +418,9 @@ func TestParentProviderTransformer_moduleGrandchild(t *testing.T) {
"qux",
addrs.NoKey,
),
ProviderAddr: addrs.RootModuleInstance.
Child("moo", addrs.NoKey).
ProviderConfigDefault("foo"),
ID: "bar",
},
},
@ -656,27 +674,27 @@ provider.bar
`
const testTransformMissingProviderModuleChildStr = `
module.moo.foo_instance.qux (import id: bar)
module.moo.foo_instance.qux (import id "bar")
provider.foo
`
const testTransformMissingProviderModuleGrandchildStr = `
module.a.module.b.foo_instance.qux (import id: bar)
module.a.module.b.foo_instance.qux (import id "bar")
provider.foo
`
const testTransformParentProviderStr = `
module.moo.foo_instance.qux (import id: bar)
module.moo.foo_instance.qux (import id "bar")
provider.foo
`
const testTransformParentProviderModuleGrandchildStr = `
module.a.module.b.foo_instance.qux (import id: bar)
module.a.module.b.foo_instance.qux (import id "bar")
provider.foo
`
const testTransformProviderModuleChildStr = `
module.moo.foo_instance.qux (import id: bar)
module.moo.foo_instance.qux (import id "bar")
provider.foo
provider.foo
`