reproduction test

This commit is contained in:
Kristin Laemmert 2020-06-12 12:35:30 -04:00
parent 27546809a2
commit b611bd7209
4 changed files with 67 additions and 0 deletions

View File

@ -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) { func TestImport_dataResource(t *testing.T) {
defer testChdir(t, testFixturePath("import-missing-resource-config"))() defer testChdir(t, testFixturePath("import-missing-resource-config"))()

View File

@ -0,0 +1,5 @@
variable "foo" {}
resource "test_instance" "foo" {
foo = var.foo
}

View File

@ -0,0 +1,6 @@
variable "foo" {}
module "child" {
source = "./child"
foo = var.foo
}

View File

@ -0,0 +1 @@
foo = "bar"