diff --git a/terraform/context_import_test.go b/terraform/context_import_test.go index c20abc25f..31ab41ce4 100644 --- a/terraform/context_import_test.go +++ b/terraform/context_import_test.go @@ -732,6 +732,95 @@ func TestContextImport_multiStateSame(t *testing.T) { } } +func TestContextImport_noConfigModuleImport(t *testing.T) { + p := testProvider("aws") + m := testModuleInline(t, map[string]string{ + "main.tf": ` +locals { + xs = toset(["foo"]) +} + +module "a" { + for_each = local.xs + source = "./a" +} + +module "b" { + for_each = local.xs + source = "./b" + y = module.a[each.key].y +} +`, + "a/main.tf": ` +output "y" { + value = "bar" +} +`, + "b/main.tf": ` +variable "y" { + type = string +} + +resource "test_resource" "unused" { + value = var.y +} +`, + }) + + p.GetSchemaReturn = &ProviderSchema{ + Provider: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, + }, + ResourceTypes: map[string]*configschema.Block{ + "test_resource": { + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + }, + }, + }, + } + + p.ImportResourceStateResponse = providers.ImportResourceStateResponse{ + ImportedResources: []providers.ImportedResource{ + { + TypeName: "test_resource", + State: cty.ObjectVal(map[string]cty.Value{ + "id": cty.StringVal("test"), + }), + }, + }, + } + + ctx := testContext2(t, &ContextOpts{ + Config: m, + Providers: map[addrs.Provider]providers.Factory{ + addrs.NewDefaultProvider("test"): testProviderFuncFixed(p), + }, + }) + + state, diags := ctx.Import(&ImportOpts{ + Targets: []*ImportTarget{ + &ImportTarget{ + Addr: addrs.RootModuleInstance.ResourceInstance( + addrs.ManagedResourceMode, "test_resource", "test", addrs.NoKey, + ), + ID: "test", + }, + }, + }) + if diags.HasErrors() { + t.Fatal(diags.ErrWithWarnings()) + } + + ri := state.ResourceInstance(mustResourceInstanceAddr("test_resource.test")) + expected := `{"id":"test"}` + if string(ri.Current.AttrsJSON) != expected { + t.Fatalf("expected %q, got %q\n", expected, ri.Current.AttrsJSON) + } +} + const testImportStr = ` aws_instance.foo: ID = foo diff --git a/terraform/node_module_variable.go b/terraform/node_module_variable.go index 707d0986f..b635685d1 100644 --- a/terraform/node_module_variable.go +++ b/terraform/node_module_variable.go @@ -153,7 +153,7 @@ func (n *nodeModuleVariable) Execute(ctx EvalContext, op walkOperation) error { var err error switch op { - case walkPlan, walkApply, walkDestroy, walkImport: + case walkPlan, walkApply, walkDestroy: vals, err = n.EvalModuleCallArgument(ctx, false) if err != nil { return err