mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
core: move targets transform after flatten
Allows target dependencies to be properly calculated across module boundaries, fixing scenarios where a target depends on something inside a module, but the contents of the module are not included in the targeted resources. fixes #1858
This commit is contained in:
parent
54d586f9b3
commit
cf432b3ceb
@ -6593,6 +6593,48 @@ module.child:
|
||||
`)
|
||||
}
|
||||
|
||||
// GH-1858
|
||||
func TestContext2Apply_targetedModuleDep(t *testing.T) {
|
||||
m := testModule(t, "apply-targeted-module-dep")
|
||||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
Targets: []string{"aws_instance.foo"},
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
checkStateString(t, state, `
|
||||
aws_instance.foo:
|
||||
ID = foo
|
||||
foo = foo
|
||||
type = aws_instance
|
||||
|
||||
Dependencies:
|
||||
module.child
|
||||
|
||||
module.child:
|
||||
aws_instance.mod:
|
||||
ID = foo
|
||||
|
||||
Outputs:
|
||||
|
||||
output = foo
|
||||
`)
|
||||
}
|
||||
|
||||
func TestContext2Apply_targetedModuleResource(t *testing.T) {
|
||||
m := testModule(t, "apply-targeted-module-resource")
|
||||
p := testProvider("aws")
|
||||
|
@ -140,10 +140,6 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
|
||||
// Make sure all the connections that are proxies are connected through
|
||||
&ProxyTransformer{},
|
||||
|
||||
// Optionally reduces the graph to a user-specified list of targets and
|
||||
// their dependencies.
|
||||
&TargetsTransformer{Targets: b.Targets, Destroy: b.Destroy},
|
||||
|
||||
// Make sure we have a single root
|
||||
&RootTransformer{},
|
||||
}
|
||||
@ -152,6 +148,10 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
|
||||
// We don't do the following for modules.
|
||||
if len(path) <= 1 {
|
||||
steps = append(steps,
|
||||
// Optionally reduces the graph to a user-specified list of targets and
|
||||
// their dependencies.
|
||||
&TargetsTransformer{Targets: b.Targets, Destroy: b.Destroy},
|
||||
|
||||
// Prune the providers and provisioners. This must happen
|
||||
// only once because flattened modules might depend on empty
|
||||
// providers.
|
||||
|
@ -0,0 +1,5 @@
|
||||
resource "aws_instance" "mod" { }
|
||||
|
||||
output "output" {
|
||||
value = "${aws_instance.mod.id}"
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
module "child" {
|
||||
source = "./child"
|
||||
}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
foo = "${module.child.output}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user