Merge pull request #16572 from hashicorp/jbardin/provider-config

don't add missing provider aliases to the graph
This commit is contained in:
James Bardin 2017-11-06 15:03:27 -05:00 committed by GitHub
commit 6302916e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 5 deletions

View File

@ -725,7 +725,8 @@ func TestContextImport_multiStateSame(t *testing.T) {
}
}
func TestContextImport_customProvider(t *testing.T) {
// import missing a provider alias should fail
func TestContextImport_customProviderMissing(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "import-provider")
ctx := testContext2(t, &ContextOpts{
@ -744,6 +745,39 @@ func TestContextImport_customProvider(t *testing.T) {
},
}
_, err := ctx.Import(&ImportOpts{
Targets: []*ImportTarget{
&ImportTarget{
Addr: "aws_instance.foo",
ID: "bar",
Provider: "aws.alias",
},
},
})
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{
Module: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
),
})
p.ImportStateReturn = []*InstanceState{
&InstanceState{
ID: "foo",
Ephemeral: EphemeralState{Type: "aws_instance"},
},
}
state, err := ctx.Import(&ImportOpts{
Targets: []*ImportTarget{
&ImportTarget{

View File

@ -0,0 +1,4 @@
provider "aws" {
foo = "bar"
alias = "alias"
}

View File

@ -18,6 +18,10 @@ func TransformProviders(providers []string, concrete ConcreteProviderNodeFunc, m
Providers: providers,
Concrete: concrete,
},
// Attach configuration to each provider instance
&AttachProviderConfigTransformer{
Module: mod,
},
// Add any remaining missing providers
&MissingProviderTransformer{
Providers: providers,
@ -29,10 +33,6 @@ func TransformProviders(providers []string, concrete ConcreteProviderNodeFunc, m
&DisableProviderTransformer{},
// Connect provider to their parent provider nodes
&ParentProviderTransformer{},
// Attach configuration to each provider instance
&AttachProviderConfigTransformer{
Module: mod,
},
)
}
@ -107,6 +107,7 @@ func (t *ProviderTransformer) Transform(g *Graph) error {
break
}
log.Printf("[DEBUG] resource %s using provider %s", dag.VertexName(pv), key)
pv.SetProvider(key)
g.Connect(dag.BasicEdge(v, target))
}
@ -194,6 +195,12 @@ func (t *MissingProviderTransformer) Transform(g *Graph) error {
continue
}
// we don't implicitly create aliased providers
if strings.Contains(p, ".") {
log.Println("[DEBUG] not adding missing provider alias", p)
continue
}
// create the misisng top-level provider
provider = t.Concrete(&NodeAbstractProvider{
NameValue: p,