don't add missing provider aliases to the graph
A missing provider alias should not be implicitly added to the graph. Run the AttachaProviderConfigTransformer immediately after adding the providers, since the ProviderConfigTransformer should have just added these nodes.
This commit is contained in:
parent
4b1c7a1d9b
commit
d9d21d4200
|
@ -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{
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
provider "aws" {
|
||||
foo = "bar"
|
||||
alias = "alias"
|
||||
}
|
|
@ -19,6 +19,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,
|
||||
|
@ -30,10 +34,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,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -109,6 +109,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))
|
||||
}
|
||||
|
@ -196,6 +197,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,
|
||||
|
|
Loading…
Reference in New Issue