terraform: flattening multi-level modules works
This commit is contained in:
parent
caef7769ae
commit
7c3e355bb0
|
@ -136,6 +136,24 @@ func TestBuiltinGraphBuilder_cbdDepNonCbd_errorsWhenVerbose(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuiltinGraphBuilder_multiLevelModule(t *testing.T) {
|
||||||
|
b := &BuiltinGraphBuilder{
|
||||||
|
Root: testModule(t, "graph-builder-multi-level-module"),
|
||||||
|
Validate: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
g, err := b.Build(RootModulePath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := strings.TrimSpace(g.String())
|
||||||
|
expected := strings.TrimSpace(testBuiltinGraphBuilderMultiLevelStr)
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("bad: %s", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: This exposes a really bad bug we need to fix after we merge
|
TODO: This exposes a really bad bug we need to fix after we merge
|
||||||
the f-ast-branch. This bug still exists in master.
|
the f-ast-branch. This bug still exists in master.
|
||||||
|
@ -213,3 +231,17 @@ module.consul (expanded)
|
||||||
provider.aws
|
provider.aws
|
||||||
provider.aws
|
provider.aws
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testBuiltinGraphBuilderMultiLevelStr = `
|
||||||
|
module.foo.module.bar.output.value
|
||||||
|
module.foo.module.bar.var.bar
|
||||||
|
module.foo.module.bar.plan-destroy
|
||||||
|
module.foo.module.bar.var.bar
|
||||||
|
module.foo.var.foo
|
||||||
|
module.foo.plan-destroy
|
||||||
|
module.foo.var.foo
|
||||||
|
root
|
||||||
|
module.foo.module.bar.output.value
|
||||||
|
module.foo.module.bar.plan-destroy
|
||||||
|
module.foo.plan-destroy
|
||||||
|
`
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
variable "bar" {}
|
||||||
|
output "value" { value = "${var.bar}" }
|
|
@ -0,0 +1,6 @@
|
||||||
|
module "bar" {
|
||||||
|
source = "./bar"
|
||||||
|
bar = "${var.foo}"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "foo" {}
|
|
@ -0,0 +1,4 @@
|
||||||
|
module "foo" {
|
||||||
|
source = "./foo"
|
||||||
|
foo = "bar"
|
||||||
|
}
|
|
@ -53,6 +53,10 @@ func (t *FlattenTransformer) Transform(g *Graph) error {
|
||||||
|
|
||||||
// Go through the subgraph and flatten all the nodes
|
// Go through the subgraph and flatten all the nodes
|
||||||
for _, sv := range subgraph.Vertices() {
|
for _, sv := range subgraph.Vertices() {
|
||||||
|
if _, ok := sv.(GraphNodeSubPath); ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
fn, ok := sv.(GraphNodeFlattenable)
|
fn, ok := sv.(GraphNodeFlattenable)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
|
|
Loading…
Reference in New Issue