From b611bd72098b3fc78984451a420c1b7b6950a493 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Fri, 12 Jun 2020 12:35:30 -0400 Subject: [PATCH] reproduction test --- command/import_test.go | 55 +++++++++++++++++++ .../import-module-var-file/child/main.tf | 5 ++ .../testdata/import-module-var-file/main.tf | 6 ++ .../import-module-var-file/terraform.tfvars | 1 + 4 files changed, 67 insertions(+) create mode 100644 command/testdata/import-module-var-file/child/main.tf create mode 100644 command/testdata/import-module-var-file/main.tf create mode 100644 command/testdata/import-module-var-file/terraform.tfvars diff --git a/command/import_test.go b/command/import_test.go index 9dea385dd9..11ba76f043 100644 --- a/command/import_test.go +++ b/command/import_test.go @@ -744,6 +744,61 @@ func TestImport_missingModuleConfig(t *testing.T) { } } +func TestImportModuleVarFile(t *testing.T) { + defer testChdir(t, testFixturePath("import-module-var-file"))() + + statePath := testTempFile(t) + + p := testProvider() + p.GetSchemaReturn = &terraform.ProviderSchema{ + ResourceTypes: map[string]*configschema.Block{ + "test_instance": { + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, + }, + }, + } + + providerSource, close := newMockProviderSource(t, map[string][]string{ + "test": []string{"1.2.3"}, + }) + defer close() + + // init to install the module + ui := new(cli.MockUi) + m := Meta{ + testingOverrides: metaOverridesForProvider(testProvider()), + Ui: ui, + ProviderSource: providerSource, + } + + ic := &InitCommand{ + Meta: m, + } + if code := ic.Run([]string{}); code != 0 { + t.Fatalf("init failed\n%s", ui.ErrorWriter) + } + + // import + ui = new(cli.MockUi) + c := &ImportCommand{ + Meta: Meta{ + testingOverrides: metaOverridesForProvider(p), + Ui: ui, + }, + } + args := []string{ + "-state", statePath, + "module.child.test_instance.foo", + "bar", + } + code := c.Run(args) + if code != 0 { + t.Fatalf("import failed; expected success") + } +} + func TestImport_dataResource(t *testing.T) { defer testChdir(t, testFixturePath("import-missing-resource-config"))() diff --git a/command/testdata/import-module-var-file/child/main.tf b/command/testdata/import-module-var-file/child/main.tf new file mode 100644 index 0000000000..6a4ae0d096 --- /dev/null +++ b/command/testdata/import-module-var-file/child/main.tf @@ -0,0 +1,5 @@ +variable "foo" {} + +resource "test_instance" "foo" { + foo = var.foo +} diff --git a/command/testdata/import-module-var-file/main.tf b/command/testdata/import-module-var-file/main.tf new file mode 100644 index 0000000000..222348f9f1 --- /dev/null +++ b/command/testdata/import-module-var-file/main.tf @@ -0,0 +1,6 @@ +variable "foo" {} + +module "child" { + source = "./child" + foo = var.foo +} diff --git a/command/testdata/import-module-var-file/terraform.tfvars b/command/testdata/import-module-var-file/terraform.tfvars new file mode 100644 index 0000000000..5abc475eb9 --- /dev/null +++ b/command/testdata/import-module-var-file/terraform.tfvars @@ -0,0 +1 @@ +foo = "bar"