terraform: MissingProviderTransformer now injects missing modules

This commit is contained in:
Mitchell Hashimoto 2016-04-30 07:59:09 +02:00
parent 1d3f11f0ba
commit 6f607d0c59
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 25 additions and 4 deletions

View File

@ -1,6 +1,5 @@
package terraform
/*
import (
"strings"
"testing"
@ -127,4 +126,3 @@ aws_instance.foo:
provider = aws
foo = bar
`
*/

View File

@ -223,8 +223,13 @@ func (t *MissingProviderTransformer) Transform(g *Graph) error {
return err
}
// Add this new vertex to our check list
check = append(check, v)
// We'll need the parent provider as well, so let's
// add a dummy node to check to make sure that we add
// that parent provider.
check = append(check, &graphNodeProviderConsumerDummy{
ProviderValue: p,
PathValue: path[:len(path)-1],
})
}
m[key] = g.Add(v)
@ -509,3 +514,20 @@ func (n *graphNodeProviderFlat) DependentOn() []string {
return result
}
// graphNodeProviderConsumerDummy is a struct that never enters the real
// graph (though it could to no ill effect). It implements
// GraphNodeProviderConsumer and GraphNodeSubpath as a way to force
// certain transformations.
type graphNodeProviderConsumerDummy struct {
ProviderValue string
PathValue []string
}
func (n *graphNodeProviderConsumerDummy) Path() []string {
return n.PathValue
}
func (n *graphNodeProviderConsumerDummy) ProvidedBy() []string {
return []string{n.ProviderValue}
}

View File

@ -300,6 +300,7 @@ provider.foo (close)
const testTransformMissingProviderModuleChildStr = `
module.moo.foo_instance.qux (import id: bar)
module.moo.provider.foo
provider.foo
`
const testTransformPruneProviderBasicStr = `