ensure modules are expanded during import

In order to import into a module, we have to make sure that module has
registered the expansion data.
This commit is contained in:
James Bardin 2020-06-10 17:02:41 -04:00
parent abedfd3a0f
commit 8f4395a1e9
3 changed files with 17 additions and 5 deletions

View File

@ -527,7 +527,7 @@ func TestContextImport_module(t *testing.T) {
state, diags := ctx.Import(&ImportOpts{
Targets: []*ImportTarget{
&ImportTarget{
Addr: addrs.RootModuleInstance.Child("child", addrs.NoKey).ResourceInstance(
Addr: addrs.RootModuleInstance.Child("child", addrs.IntKey(0)).ResourceInstance(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
),
ID: "bar",
@ -565,7 +565,7 @@ func TestContextImport_moduleDepth2(t *testing.T) {
state, diags := ctx.Import(&ImportOpts{
Targets: []*ImportTarget{
&ImportTarget{
Addr: addrs.RootModuleInstance.Child("child", addrs.NoKey).Child("nested", addrs.NoKey).ResourceInstance(
Addr: addrs.RootModuleInstance.Child("child", addrs.IntKey(0)).Child("nested", addrs.NoKey).ResourceInstance(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
),
ID: "baz",
@ -603,7 +603,7 @@ func TestContextImport_moduleDiff(t *testing.T) {
state, diags := ctx.Import(&ImportOpts{
Targets: []*ImportTarget{
&ImportTarget{
Addr: addrs.RootModuleInstance.Child("child", addrs.NoKey).ResourceInstance(
Addr: addrs.RootModuleInstance.Child("child", addrs.IntKey(0)).ResourceInstance(
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
),
ID: "baz",
@ -765,7 +765,7 @@ aws_instance.foo.0:
const testImportModuleStr = `
<no state>
module.child:
module.child[0]:
aws_instance.foo:
ID = foo
provider = provider["registry.terraform.io/hashicorp/aws"]
@ -773,7 +773,7 @@ module.child:
const testImportModuleDepth2Str = `
<no state>
module.child.nested:
module.child[0].nested:
aws_instance.foo:
ID = foo
provider = provider["registry.terraform.io/hashicorp/aws"]

View File

@ -79,10 +79,21 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
// analyze the configuration to find references.
&AttachSchemaTransformer{Schemas: b.Schemas, Config: b.Config},
// Create expansion nodes for all of the module calls. This must
// come after all other transformers that create nodes representing
// objects that can belong to modules.
&ModuleExpansionTransformer{
Config: b.Config,
},
// Connect so that the references are ready for targeting. We'll
// have to connect again later for providers and so on.
&ReferenceTransformer{},
// Make sure data sources are aware of any depends_on from the
// configuration
&attachDataResourceDependenciesTransformer{},
// This validates that the providers only depend on variables
&ImportProviderValidateTransformer{},

View File

@ -3,6 +3,7 @@ provider "aws" {
}
module "child" {
count = 1
source = "./child"
providers = {
aws = aws