terraform: import graph should setup parent refs to providers

Fixes #11212

The import graph builder was missing the transform to setup links to
parent providers, so provider inheritance didn't work properly. This
adds that.

This also removes the `PruneProviderTransform` since that has no value
in this graph since we'll never add an unused provider.
This commit is contained in:
Mitchell Hashimoto 2017-01-24 15:36:45 -08:00
parent f84fd39ef9
commit b2fb3b1d0f
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 56 additions and 3 deletions

View File

@ -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) {

View File

@ -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

View File

@ -0,0 +1 @@
# Empty

View File

@ -0,0 +1,5 @@
provider "aws" {
foo = "bar"
}
module "child" { source = "./child" }