add implied providers during import

The CLI adds the provider references during import, but tests may not
have them specified.
This commit is contained in:
James Bardin 2018-12-04 15:39:46 -05:00
parent a65624e0c1
commit 7f9d76cbf5
3 changed files with 23 additions and 15 deletions

View File

@ -37,8 +37,7 @@ func TestContextImport_basic(t *testing.T) {
Addr: addrs.RootModuleInstance.ResourceInstance(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
),
ID: "bar",
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
ID: "bar",
},
},
})
@ -77,8 +76,7 @@ func TestContextImport_countIndex(t *testing.T) {
Addr: addrs.RootModuleInstance.ResourceInstance(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.IntKey(0),
),
ID: "bar",
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
ID: "bar",
},
},
})
@ -135,8 +133,7 @@ func TestContextImport_collision(t *testing.T) {
Addr: addrs.RootModuleInstance.ResourceInstance(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
),
ID: "bar",
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
ID: "bar",
},
},
})
@ -179,8 +176,7 @@ func TestContextImport_missingType(t *testing.T) {
Addr: addrs.RootModuleInstance.ResourceInstance(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
),
ID: "bar",
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
ID: "bar",
},
},
})
@ -233,8 +229,7 @@ func TestContextImport_moduleProvider(t *testing.T) {
Addr: addrs.RootModuleInstance.ResourceInstance(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
),
ID: "bar",
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
ID: "bar",
},
},
})
@ -291,8 +286,7 @@ func TestContextImport_providerModule(t *testing.T) {
Addr: addrs.RootModuleInstance.Child("child", addrs.NoKey).ResourceInstance(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
),
ID: "bar",
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
ID: "bar",
},
},
})
@ -349,8 +343,7 @@ func TestContextImport_providerVarConfig(t *testing.T) {
Addr: addrs.RootModuleInstance.ResourceInstance(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
),
ID: "bar",
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
ID: "bar",
},
},
})

View File

@ -0,0 +1,7 @@
provider "aws" {
foo = data.template_data_source.d.foo
}
data "template_data_source" "d" {
foo = "bar"
}

View File

@ -16,10 +16,18 @@ type ImportStateTransformer struct {
func (t *ImportStateTransformer) Transform(g *Graph) error {
for _, target := range t.Targets {
// The ProviderAddr may not be supplied for non-aliased providers.
// This will be populated if the targets come from the cli, but tests
// may not specify implied provider addresses.
providerAddr := target.ProviderAddr
if providerAddr.ProviderConfig.Type == "" {
providerAddr = target.Addr.Resource.Resource.DefaultProviderConfig().Absolute(target.Addr.Module)
}
node := &graphNodeImportState{
Addr: target.Addr,
ID: target.ID,
ProviderAddr: target.ProviderAddr,
ProviderAddr: providerAddr,
}
g.Add(node)
}