test references only from output preconditions

These references were getting dropped, which could cause the referenced
nodes to be pruned from the graph.
This commit is contained in:
James Bardin 2023-01-05 10:01:25 -05:00
parent 1790f844b3
commit 45cb0489d0

View File

@ -1784,3 +1784,51 @@ resource "test_object" "y" {
_, diags = ctx.Apply(plan, m)
assertNoErrors(t, diags)
}
// ensure all references from preconditions are tracked through plan and apply
func TestContext2Apply_preconditionErrorMessageRef(t *testing.T) {
p := testProvider("test")
ctx := testContext2(t, &ContextOpts{
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
},
})
m := testModuleInline(t, map[string]string{
"main.tf": `
module "nested" {
source = "./mod"
}
output "nested_a" {
value = module.nested.a
}
`,
"mod/main.tf": `
variable "boop" {
default = "boop"
}
variable "msg" {
default = "Incorrect boop."
}
output "a" {
value = "x"
precondition {
condition = var.boop == "boop"
error_message = var.msg
}
}
`,
})
plan, diags := ctx.Plan(m, states.NewState(), &PlanOpts{
Mode: plans.NormalMode,
})
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
assertNoErrors(t, diags)
}