mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #1857 from hashicorp/b-multi-mod
terraform: flattening multi-level modules works
This commit is contained in:
commit
fc084cc03e
@ -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,12 @@ 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 the vertex already has a subpath then we assume it has
|
||||||
|
// already been flattened. Ignore it.
|
||||||
|
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
Block a user