mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21:14 -06:00
core: provide config to all import context tests
We're going to use config to determine provider dependencies, so we need to always provide a config when instantiating a context or we'll end up loading no providers at all. We previously had a test for running "terraform import -config=''" to disable the config entirely, but this test is now removed because it makes no sense. The actual functionality its testing still remains for now, but it will be removed in a subsequent commit when we start requiring that a resource to be imported must already exist in configuration.
This commit is contained in:
parent
c835ef8ff3
commit
4ab8973520
@ -9,6 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func TestImport(t *testing.T) {
|
||||
defer testChdir(t, testFixturePath("import-provider-implicit"))()
|
||||
|
||||
statePath := testTempFile(t)
|
||||
|
||||
p := testProvider()
|
||||
@ -102,63 +104,6 @@ func TestImport_providerConfig(t *testing.T) {
|
||||
testStateOutput(t, statePath, testImportStr)
|
||||
}
|
||||
|
||||
func TestImport_providerConfigDisable(t *testing.T) {
|
||||
defer testChdir(t, testFixturePath("import-provider"))()
|
||||
|
||||
statePath := testTempFile(t)
|
||||
|
||||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &ImportCommand{
|
||||
Meta: Meta{
|
||||
testingOverrides: metaOverridesForProvider(p),
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
p.ImportStateFn = nil
|
||||
p.ImportStateReturn = []*terraform.InstanceState{
|
||||
&terraform.InstanceState{
|
||||
ID: "yay",
|
||||
Ephemeral: terraform.EphemeralState{
|
||||
Type: "test_instance",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
configured := false
|
||||
p.ConfigureFn = func(c *terraform.ResourceConfig) error {
|
||||
configured = true
|
||||
|
||||
if v, ok := c.Get("foo"); ok {
|
||||
return fmt.Errorf("bad value: %#v", v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-state", statePath,
|
||||
"-config", "",
|
||||
"test_instance.foo",
|
||||
"bar",
|
||||
}
|
||||
if code := c.Run(args); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
// Verify that we were called
|
||||
if !configured {
|
||||
t.Fatal("Configure should be called")
|
||||
}
|
||||
|
||||
if !p.ImportStateCalled {
|
||||
t.Fatal("ImportState should be called")
|
||||
}
|
||||
|
||||
testStateOutput(t, statePath, testImportStr)
|
||||
}
|
||||
|
||||
func TestImport_providerConfigWithVar(t *testing.T) {
|
||||
defer testChdir(t, testFixturePath("import-provider-var"))()
|
||||
|
||||
@ -1015,6 +960,8 @@ func TestRefresh_displaysOutputs(t *testing.T) {
|
||||
*/
|
||||
|
||||
func TestImport_customProvider(t *testing.T) {
|
||||
defer testChdir(t, testFixturePath("import-provider-aliased"))()
|
||||
|
||||
statePath := testTempFile(t)
|
||||
|
||||
p := testProvider()
|
||||
|
5
command/test-fixtures/import-provider-aliased/main.tf
Normal file
5
command/test-fixtures/import-provider-aliased/main.tf
Normal file
@ -0,0 +1,5 @@
|
||||
provider "test" {
|
||||
foo = "bar"
|
||||
|
||||
alias = "alias"
|
||||
}
|
4
command/test-fixtures/import-provider-implicit/main.tf
Normal file
4
command/test-fixtures/import-provider-implicit/main.tf
Normal file
@ -0,0 +1,4 @@
|
||||
# Declaring this resource implies that we depend on the
|
||||
# "test" provider, making it available for import.
|
||||
resource "test_instance" "foo" {
|
||||
}
|
@ -8,7 +8,9 @@ import (
|
||||
|
||||
func TestContextImport_basic(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -43,7 +45,9 @@ func TestContextImport_basic(t *testing.T) {
|
||||
|
||||
func TestContextImport_countIndex(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -79,7 +83,9 @@ func TestContextImport_countIndex(t *testing.T) {
|
||||
|
||||
func TestContextImport_collision(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -131,7 +137,9 @@ func TestContextImport_collision(t *testing.T) {
|
||||
|
||||
func TestContextImport_missingType(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -166,7 +174,9 @@ func TestContextImport_missingType(t *testing.T) {
|
||||
|
||||
func TestContextImport_moduleProvider(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -192,8 +202,6 @@ func TestContextImport_moduleProvider(t *testing.T) {
|
||||
return nil
|
||||
}
|
||||
|
||||
m := testModule(t, "import-provider")
|
||||
|
||||
state, err := ctx.Import(&ImportOpts{
|
||||
Module: m,
|
||||
Targets: []*ImportTarget{
|
||||
@ -221,7 +229,9 @@ func TestContextImport_moduleProvider(t *testing.T) {
|
||||
// Test that import sets up the graph properly for provider inheritance
|
||||
func TestContextImport_providerInherit(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider-inherit")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -247,8 +257,6 @@ func TestContextImport_providerInherit(t *testing.T) {
|
||||
return nil
|
||||
}
|
||||
|
||||
m := testModule(t, "import-provider-inherit")
|
||||
|
||||
_, err := ctx.Import(&ImportOpts{
|
||||
Module: m,
|
||||
Targets: []*ImportTarget{
|
||||
@ -271,8 +279,9 @@ func TestContextImport_providerInherit(t *testing.T) {
|
||||
// that configuration for import.
|
||||
func TestContextImport_providerVarConfig(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider-vars")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: testModule(t, "import-provider-vars"),
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -327,8 +336,9 @@ func TestContextImport_providerVarConfig(t *testing.T) {
|
||||
// Test that provider configs can't reference resources.
|
||||
func TestContextImport_providerNonVarConfig(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider-non-vars")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: testModule(t, "import-provider-non-vars"),
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -358,7 +368,9 @@ func TestContextImport_providerNonVarConfig(t *testing.T) {
|
||||
|
||||
func TestContextImport_refresh(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -401,7 +413,9 @@ func TestContextImport_refresh(t *testing.T) {
|
||||
|
||||
func TestContextImport_refreshNil(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -441,7 +455,9 @@ func TestContextImport_refreshNil(t *testing.T) {
|
||||
|
||||
func TestContextImport_module(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -477,7 +493,9 @@ func TestContextImport_module(t *testing.T) {
|
||||
|
||||
func TestContextImport_moduleDepth2(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -513,7 +531,9 @@ func TestContextImport_moduleDepth2(t *testing.T) {
|
||||
|
||||
func TestContextImport_moduleDiff(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -565,7 +585,9 @@ func TestContextImport_moduleDiff(t *testing.T) {
|
||||
|
||||
func TestContextImport_moduleExisting(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -617,7 +639,9 @@ func TestContextImport_moduleExisting(t *testing.T) {
|
||||
|
||||
func TestContextImport_multiState(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -657,7 +681,9 @@ func TestContextImport_multiState(t *testing.T) {
|
||||
|
||||
func TestContextImport_multiStateSame(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
@ -701,7 +727,9 @@ func TestContextImport_multiStateSame(t *testing.T) {
|
||||
|
||||
func TestContextImport_customProvider(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
|
Loading…
Reference in New Issue
Block a user