2016-04-26 12:47:56 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
2016-05-10 11:15:19 -05:00
|
|
|
"fmt"
|
2016-04-26 12:47:56 -05:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2018-05-04 21:24:06 -05:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
2018-05-11 20:32:28 -05:00
|
|
|
"github.com/hashicorp/terraform/config/configschema"
|
2018-05-04 21:24:06 -05:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
2016-04-26 12:47:56 -05:00
|
|
|
)
|
|
|
|
|
2016-04-28 12:25:58 -05:00
|
|
|
func TestContextImport_basic(t *testing.T) {
|
2016-04-26 12:47:56 -05:00
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-04-26 12:47:56 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-04-26 12:47:56 -05:00
|
|
|
})
|
|
|
|
|
2016-04-28 12:25:58 -05:00
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-04-28 04:46:46 -05:00
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-04-28 04:46:46 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2016-04-26 12:47:56 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
actual := strings.TrimSpace(state.String())
|
2016-04-28 04:46:46 -05:00
|
|
|
expected := strings.TrimSpace(testImportStr)
|
2016-04-26 12:47:56 -05:00
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
2016-04-28 04:46:46 -05:00
|
|
|
|
2016-08-19 18:14:33 -05:00
|
|
|
func TestContextImport_countIndex(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-08-19 18:14:33 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-08-19 18:14:33 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.IntKey(0),
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-08-19 18:14:33 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
|
|
|
expected := strings.TrimSpace(testImportCountIndexStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 17:53:48 -05:00
|
|
|
func TestContextImport_collision(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-04-30 17:53:48 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-04-30 17:53:48 -05:00
|
|
|
|
|
|
|
State: &State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.foo": &ResourceState{
|
|
|
|
Type: "aws_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-04-30 17:53:48 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
|
|
|
expected := strings.TrimSpace(testImportCollisionStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 16:55:26 -05:00
|
|
|
func TestContextImport_missingType(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-04-30 16:55:26 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-04-30 16:55:26 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-04-30 16:56:22 -05:00
|
|
|
state, err := ctx.Import(&ImportOpts{
|
2016-04-30 16:55:26 -05:00
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-04-30 16:55:26 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should error")
|
|
|
|
}
|
2016-04-30 16:56:22 -05:00
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
2016-04-30 17:53:48 -05:00
|
|
|
expected := "<no state>"
|
2016-04-30 16:56:22 -05:00
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
2016-04-30 16:55:26 -05:00
|
|
|
}
|
|
|
|
|
2016-05-10 11:15:19 -05:00
|
|
|
func TestContextImport_moduleProvider(t *testing.T) {
|
2018-05-11 20:32:28 -05:00
|
|
|
p := mockProviderWithResourceTypeSchema("aws_instance", &configschema.Block{})
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-05-10 11:15:19 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-05-10 11:15:19 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
configured := false
|
|
|
|
p.ConfigureFn = func(c *ResourceConfig) error {
|
|
|
|
configured = true
|
|
|
|
|
|
|
|
if v, ok := c.Get("foo"); !ok || v.(string) != "bar" {
|
|
|
|
return fmt.Errorf("bad")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2016-05-10 11:15:19 -05:00
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-05-10 11:15:19 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !configured {
|
|
|
|
t.Fatal("didn't configure provider")
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
2016-11-02 12:29:58 -05:00
|
|
|
expected := strings.TrimSpace(testImportStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 18:02:21 -05:00
|
|
|
// Importing into a module requires a provider config in that module.
|
|
|
|
func TestContextImport_providerModule(t *testing.T) {
|
2017-01-24 17:36:45 -06:00
|
|
|
p := testProvider("aws")
|
2017-10-17 18:02:21 -05:00
|
|
|
m := testModule(t, "import-provider-module")
|
2017-01-24 17:36:45 -06:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2017-01-24 17:36:45 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
configured := false
|
|
|
|
p.ConfigureFn = func(c *ResourceConfig) error {
|
|
|
|
configured = true
|
|
|
|
|
|
|
|
if v, ok := c.Get("foo"); !ok || v.(string) != "bar" {
|
|
|
|
return fmt.Errorf("bad")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := ctx.Import(&ImportOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-01-24 17:36:45 -06:00
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.Child("child", addrs.NoKey).ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2017-01-24 17:36:45 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !configured {
|
|
|
|
t.Fatal("didn't configure provider")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 12:29:58 -05:00
|
|
|
// Test that import will interpolate provider configuration and use
|
|
|
|
// that configuration for import.
|
|
|
|
func TestContextImport_providerVarConfig(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider-vars")
|
2016-11-02 12:29:58 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2018-05-04 21:24:06 -05:00
|
|
|
Variables: InputValues{
|
|
|
|
"foo": &InputValue{
|
|
|
|
Value: cty.StringVal("foo"),
|
|
|
|
SourceType: ValueFromCaller,
|
|
|
|
},
|
2016-11-02 12:29:58 -05:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
configured := false
|
|
|
|
p.ConfigureFn = func(c *ResourceConfig) error {
|
|
|
|
configured = true
|
|
|
|
|
|
|
|
if v, ok := c.Get("foo"); !ok || v.(string) != "bar" {
|
|
|
|
return fmt.Errorf("bad value: %#v", v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-11-02 12:29:58 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !configured {
|
|
|
|
t.Fatal("didn't configure provider")
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
2016-05-10 11:15:19 -05:00
|
|
|
expected := strings.TrimSpace(testImportStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 13:08:16 -05:00
|
|
|
// Test that provider configs can't reference resources.
|
|
|
|
func TestContextImport_providerNonVarConfig(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider-non-vars")
|
2016-11-02 13:08:16 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-11-02 13:08:16 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-11-02 13:08:16 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 12:28:23 -05:00
|
|
|
func TestContextImport_refresh(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-04-28 12:28:23 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-04-28 12:28:23 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
p.RefreshFn = func(info *InstanceInfo, s *InstanceState) (*InstanceState, error) {
|
|
|
|
return &InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Attributes: map[string]string{"foo": "bar"},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-04-28 12:28:23 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
|
|
|
expected := strings.TrimSpace(testImportRefreshStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-09 15:39:34 -05:00
|
|
|
func TestContextImport_refreshNil(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-05-09 15:39:34 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-05-09 15:39:34 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
p.RefreshFn = func(info *InstanceInfo, s *InstanceState) (*InstanceState, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-05-09 15:39:34 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should error")
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
|
|
|
expected := "<no state>"
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 00:09:34 -05:00
|
|
|
func TestContextImport_module(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-04-30 00:09:34 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-04-30 00:09:34 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.Child("foo", addrs.NoKey).ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-04-30 00:09:34 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
2016-04-30 01:28:58 -05:00
|
|
|
expected := strings.TrimSpace(testImportModuleStr)
|
2016-04-30 00:09:34 -05:00
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 01:59:11 -05:00
|
|
|
func TestContextImport_moduleDepth2(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-04-30 01:59:11 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-04-30 01:59:11 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.Child("a", addrs.NoKey).Child("b", addrs.NoKey).ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-04-30 01:59:11 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
|
|
|
expected := strings.TrimSpace(testImportModuleDepth2Str)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 17:01:31 -05:00
|
|
|
func TestContextImport_moduleDiff(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-04-30 17:01:31 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-04-30 17:01:31 -05:00
|
|
|
|
|
|
|
State: &State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "bar"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.bar": &ResourceState{
|
|
|
|
Type: "aws_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.Child("foo", addrs.NoKey).ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-04-30 17:01:31 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
|
|
|
expected := strings.TrimSpace(testImportModuleDiffStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 17:00:18 -05:00
|
|
|
func TestContextImport_moduleExisting(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-04-30 17:00:18 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-04-30 17:00:18 -05:00
|
|
|
|
|
|
|
State: &State{
|
|
|
|
Modules: []*ModuleState{
|
|
|
|
&ModuleState{
|
|
|
|
Path: []string{"root", "foo"},
|
|
|
|
Resources: map[string]*ResourceState{
|
|
|
|
"aws_instance.bar": &ResourceState{
|
|
|
|
Type: "aws_instance",
|
|
|
|
Primary: &InstanceState{
|
|
|
|
ID: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.Child("foo", addrs.NoKey).ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-04-30 17:00:18 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
|
|
|
expected := strings.TrimSpace(testImportModuleExistingStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 17:04:40 -05:00
|
|
|
func TestContextImport_multiState(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-04-30 17:04:40 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-04-30 17:04:40 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
&InstanceState{
|
|
|
|
ID: "bar",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance_thing"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-04-30 17:04:40 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
|
|
|
expected := strings.TrimSpace(testImportMultiStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 17:29:03 -05:00
|
|
|
func TestContextImport_multiStateSame(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-04-30 17:29:03 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-04-30 17:29:03 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
&InstanceState{
|
|
|
|
ID: "bar",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance_thing"},
|
|
|
|
},
|
|
|
|
&InstanceState{
|
|
|
|
ID: "qux",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance_thing"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
2018-05-11 20:32:28 -05:00
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault("aws"),
|
2016-04-30 17:29:03 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
|
|
|
expected := strings.TrimSpace(testImportMultiSameStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 13:16:34 -06:00
|
|
|
// import missing a provider alias should fail
|
|
|
|
func TestContextImport_customProviderMissing(t *testing.T) {
|
2016-11-23 03:44:52 -06:00
|
|
|
p := testProvider("aws")
|
2017-04-21 19:19:37 -05:00
|
|
|
m := testModule(t, "import-provider")
|
2016-11-23 03:44:52 -06:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-04-21 19:40:46 -05:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
2016-11-23 03:44:52 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-11-06 13:16:34 -06:00
|
|
|
_, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigAliased("aws", "alias"),
|
2017-11-06 13:16:34 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContextImport_customProvider(t *testing.T) {
|
|
|
|
p := testProvider("aws")
|
|
|
|
m := testModule(t, "import-provider-alias")
|
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2017-11-06 13:16:34 -06:00
|
|
|
ProviderResolver: ResourceProviderResolverFixed(
|
|
|
|
map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
})
|
|
|
|
|
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-11-23 03:44:52 -06:00
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
2018-05-04 21:24:06 -05:00
|
|
|
Addr: addrs.RootModuleInstance.ResourceInstance(
|
|
|
|
addrs.ManagedResourceMode, "aws_instance", "foo", addrs.NoKey,
|
|
|
|
),
|
|
|
|
ID: "bar",
|
|
|
|
ProviderAddr: addrs.RootModuleInstance.ProviderConfigAliased("aws", "alias"),
|
2016-11-23 03:44:52 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
|
|
|
expected := strings.TrimSpace(testImportCustomProviderStr)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 12:25:58 -05:00
|
|
|
const testImportStr = `
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = foo
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-28 12:25:58 -05:00
|
|
|
`
|
2016-04-28 12:28:23 -05:00
|
|
|
|
2016-08-19 18:14:33 -05:00
|
|
|
const testImportCountIndexStr = `
|
|
|
|
aws_instance.foo.0:
|
|
|
|
ID = foo
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-08-19 18:14:33 -05:00
|
|
|
`
|
|
|
|
|
2016-04-30 17:53:48 -05:00
|
|
|
const testImportCollisionStr = `
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = bar
|
|
|
|
`
|
|
|
|
|
2016-04-30 01:28:58 -05:00
|
|
|
const testImportModuleStr = `
|
|
|
|
<no state>
|
|
|
|
module.foo:
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = foo
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-30 01:28:58 -05:00
|
|
|
`
|
|
|
|
|
2016-04-30 01:59:11 -05:00
|
|
|
const testImportModuleDepth2Str = `
|
|
|
|
<no state>
|
|
|
|
module.a.b:
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = foo
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-30 01:59:11 -05:00
|
|
|
`
|
|
|
|
|
2016-04-30 17:01:31 -05:00
|
|
|
const testImportModuleDiffStr = `
|
|
|
|
module.bar:
|
|
|
|
aws_instance.bar:
|
|
|
|
ID = bar
|
|
|
|
module.foo:
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = foo
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-30 17:01:31 -05:00
|
|
|
`
|
|
|
|
|
2016-04-30 17:00:18 -05:00
|
|
|
const testImportModuleExistingStr = `
|
|
|
|
module.foo:
|
|
|
|
aws_instance.bar:
|
|
|
|
ID = bar
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = foo
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-30 17:00:18 -05:00
|
|
|
`
|
|
|
|
|
2016-04-30 17:04:40 -05:00
|
|
|
const testImportMultiStr = `
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = foo
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-30 17:04:40 -05:00
|
|
|
aws_instance_thing.foo:
|
|
|
|
ID = bar
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-30 17:04:40 -05:00
|
|
|
`
|
|
|
|
|
2016-04-30 17:29:03 -05:00
|
|
|
const testImportMultiSameStr = `
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = foo
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-30 17:29:03 -05:00
|
|
|
aws_instance_thing.foo:
|
|
|
|
ID = bar
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-30 17:29:03 -05:00
|
|
|
aws_instance_thing.foo-1:
|
|
|
|
ID = qux
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-30 17:29:03 -05:00
|
|
|
`
|
|
|
|
|
2016-04-28 12:28:23 -05:00
|
|
|
const testImportRefreshStr = `
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = foo
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws
|
2016-04-28 12:28:23 -05:00
|
|
|
foo = bar
|
|
|
|
`
|
2016-11-23 03:44:52 -06:00
|
|
|
|
|
|
|
const testImportCustomProviderStr = `
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = foo
|
2017-11-07 19:58:04 -06:00
|
|
|
provider = provider.aws.alias
|
2016-11-23 03:44:52 -06:00
|
|
|
`
|