Merge pull request #11393 from hashicorp/b-import-provider
terraform: import graph should setup parent refs to providers
This commit is contained in:
commit
2e47453291
|
@ -208,6 +208,53 @@ 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")
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
m := testModule(t, "import-provider-inherit")
|
||||||
|
|
||||||
|
_, err := ctx.Import(&ImportOpts{
|
||||||
|
Module: m,
|
||||||
|
Targets: []*ImportTarget{
|
||||||
|
&ImportTarget{
|
||||||
|
Addr: "module.child.aws_instance.foo",
|
||||||
|
ID: "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !configured {
|
||||||
|
t.Fatal("didn't configure provider")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Test that import will interpolate provider configuration and use
|
// Test that import will interpolate provider configuration and use
|
||||||
// that configuration for import.
|
// that configuration for import.
|
||||||
func TestContextImport_providerVarConfig(t *testing.T) {
|
func TestContextImport_providerVarConfig(t *testing.T) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
|
||||||
|
|
||||||
steps := []GraphTransformer{
|
steps := []GraphTransformer{
|
||||||
// Create all our resources from the configuration and state
|
// Create all our resources from the configuration and state
|
||||||
&ConfigTransformerOld{Module: mod},
|
&ConfigTransformer{Module: mod},
|
||||||
|
|
||||||
// Add the import steps
|
// Add the import steps
|
||||||
&ImportStateTransformer{Targets: b.ImportTargets},
|
&ImportStateTransformer{Targets: b.ImportTargets},
|
||||||
|
@ -55,8 +55,8 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
|
||||||
// Provider-related transformations
|
// Provider-related transformations
|
||||||
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
|
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
|
||||||
&ProviderTransformer{},
|
&ProviderTransformer{},
|
||||||
&DisableProviderTransformerOld{},
|
&DisableProviderTransformer{},
|
||||||
&PruneProviderTransformer{},
|
&ParentProviderTransformer{},
|
||||||
&AttachProviderConfigTransformer{Module: mod},
|
&AttachProviderConfigTransformer{Module: mod},
|
||||||
|
|
||||||
// This validates that the providers only depend on variables
|
// This validates that the providers only depend on variables
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
# Empty
|
|
@ -0,0 +1,5 @@
|
||||||
|
provider "aws" {
|
||||||
|
foo = "bar"
|
||||||
|
}
|
||||||
|
|
||||||
|
module "child" { source = "./child" }
|
Loading…
Reference in New Issue