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:
parent
abedfd3a0f
commit
8f4395a1e9
|
@ -527,7 +527,7 @@ func TestContextImport_module(t *testing.T) {
|
||||||
state, diags := ctx.Import(&ImportOpts{
|
state, diags := ctx.Import(&ImportOpts{
|
||||||
Targets: []*ImportTarget{
|
Targets: []*ImportTarget{
|
||||||
&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,
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
||||||
),
|
),
|
||||||
ID: "bar",
|
ID: "bar",
|
||||||
|
@ -565,7 +565,7 @@ func TestContextImport_moduleDepth2(t *testing.T) {
|
||||||
state, diags := ctx.Import(&ImportOpts{
|
state, diags := ctx.Import(&ImportOpts{
|
||||||
Targets: []*ImportTarget{
|
Targets: []*ImportTarget{
|
||||||
&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,
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
||||||
),
|
),
|
||||||
ID: "baz",
|
ID: "baz",
|
||||||
|
@ -603,7 +603,7 @@ func TestContextImport_moduleDiff(t *testing.T) {
|
||||||
state, diags := ctx.Import(&ImportOpts{
|
state, diags := ctx.Import(&ImportOpts{
|
||||||
Targets: []*ImportTarget{
|
Targets: []*ImportTarget{
|
||||||
&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,
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
||||||
),
|
),
|
||||||
ID: "baz",
|
ID: "baz",
|
||||||
|
@ -765,7 +765,7 @@ aws_instance.foo.0:
|
||||||
|
|
||||||
const testImportModuleStr = `
|
const testImportModuleStr = `
|
||||||
<no state>
|
<no state>
|
||||||
module.child:
|
module.child[0]:
|
||||||
aws_instance.foo:
|
aws_instance.foo:
|
||||||
ID = foo
|
ID = foo
|
||||||
provider = provider["registry.terraform.io/hashicorp/aws"]
|
provider = provider["registry.terraform.io/hashicorp/aws"]
|
||||||
|
@ -773,7 +773,7 @@ module.child:
|
||||||
|
|
||||||
const testImportModuleDepth2Str = `
|
const testImportModuleDepth2Str = `
|
||||||
<no state>
|
<no state>
|
||||||
module.child.nested:
|
module.child[0].nested:
|
||||||
aws_instance.foo:
|
aws_instance.foo:
|
||||||
ID = foo
|
ID = foo
|
||||||
provider = provider["registry.terraform.io/hashicorp/aws"]
|
provider = provider["registry.terraform.io/hashicorp/aws"]
|
||||||
|
|
|
@ -79,10 +79,21 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
|
||||||
// analyze the configuration to find references.
|
// analyze the configuration to find references.
|
||||||
&AttachSchemaTransformer{Schemas: b.Schemas, Config: b.Config},
|
&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
|
// Connect so that the references are ready for targeting. We'll
|
||||||
// have to connect again later for providers and so on.
|
// have to connect again later for providers and so on.
|
||||||
&ReferenceTransformer{},
|
&ReferenceTransformer{},
|
||||||
|
|
||||||
|
// Make sure data sources are aware of any depends_on from the
|
||||||
|
// configuration
|
||||||
|
&attachDataResourceDependenciesTransformer{},
|
||||||
|
|
||||||
// This validates that the providers only depend on variables
|
// This validates that the providers only depend on variables
|
||||||
&ImportProviderValidateTransformer{},
|
&ImportProviderValidateTransformer{},
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ provider "aws" {
|
||||||
}
|
}
|
||||||
|
|
||||||
module "child" {
|
module "child" {
|
||||||
|
count = 1
|
||||||
source = "./child"
|
source = "./child"
|
||||||
providers = {
|
providers = {
|
||||||
aws = aws
|
aws = aws
|
||||||
|
|
Loading…
Reference in New Issue