terraform: expand modules in our builder

This commit is contained in:
Mitchell Hashimoto 2015-02-07 16:29:04 -08:00
parent 4692f9809f
commit e2a3f78c08
4 changed files with 55 additions and 0 deletions

View File

@ -74,6 +74,13 @@ func (b *BuiltinGraphBuilder) Steps() []GraphTransformer {
&MissingProviderTransformer{Providers: b.Providers},
&ProviderTransformer{},
&PruneProviderTransformer{},
&VertexTransformer{
Transforms: []GraphVertexTransformer{
&ExpandTransform{
Builder: b,
},
},
},
&RootTransformer{},
}
}

View File

@ -29,6 +29,24 @@ func TestBuiltinGraphBuilder(t *testing.T) {
}
}
// This test tests that the graph builder properly expands modules.
func TestBuiltinGraphBuilder_modules(t *testing.T) {
b := &BuiltinGraphBuilder{
Root: testModule(t, "graph-builder-modules"),
}
g, err := b.Build(RootModulePath)
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testBuiltinGraphBuilderModuleStr)
if actual != expected {
t.Fatalf("bad: %s", actual)
}
}
const testBuiltinGraphBuilderBasicStr = `
aws_instance.db
provider.aws
@ -37,3 +55,15 @@ aws_instance.web
provider.aws
provider.aws
`
const testBuiltinGraphBuilderModuleStr = `
aws_instance.web
aws_security_group.firewall
module.consul (expanded)
provider.aws
aws_security_group.firewall
provider.aws
module.consul (expanded)
aws_security_group.firewall
provider.aws
`

View File

@ -0,0 +1,2 @@
provider "aws" {}
resource "aws_instance" "server" {}

View File

@ -0,0 +1,16 @@
module "consul" {
foo = "${aws_security_group.firewall.foo}"
source = "./consul"
}
provider "aws" {}
resource "aws_security_group" "firewall" {}
resource "aws_instance" "web" {
security_groups = [
"foo",
"${aws_security_group.firewall.foo}",
"${module.consul.security_group}"
]
}