mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #32464 from hashicorp/jbardin/output-check-refs
Ensure we have all references for output preconditions
This commit is contained in:
commit
e200f53ec0
@ -1784,3 +1784,51 @@ resource "test_object" "y" {
|
|||||||
_, diags = ctx.Apply(plan, m)
|
_, diags = ctx.Apply(plan, m)
|
||||||
assertNoErrors(t, diags)
|
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)
|
||||||
|
}
|
||||||
|
@ -278,19 +278,21 @@ func (n *NodeApplyableOutput) ReferenceableAddrs() []addrs.Referenceable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func referencesForOutput(c *configs.Output) []*addrs.Reference {
|
func referencesForOutput(c *configs.Output) []*addrs.Reference {
|
||||||
|
var refs []*addrs.Reference
|
||||||
|
|
||||||
impRefs, _ := lang.ReferencesInExpr(c.Expr)
|
impRefs, _ := lang.ReferencesInExpr(c.Expr)
|
||||||
expRefs, _ := lang.References(c.DependsOn)
|
expRefs, _ := lang.References(c.DependsOn)
|
||||||
l := len(impRefs) + len(expRefs)
|
|
||||||
if l == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
refs := make([]*addrs.Reference, 0, l)
|
|
||||||
refs = append(refs, impRefs...)
|
refs = append(refs, impRefs...)
|
||||||
refs = append(refs, expRefs...)
|
refs = append(refs, expRefs...)
|
||||||
|
|
||||||
for _, check := range c.Preconditions {
|
for _, check := range c.Preconditions {
|
||||||
checkRefs, _ := lang.ReferencesInExpr(check.Condition)
|
condRefs, _ := lang.ReferencesInExpr(check.Condition)
|
||||||
refs = append(refs, checkRefs...)
|
refs = append(refs, condRefs...)
|
||||||
|
errRefs, _ := lang.ReferencesInExpr(check.ErrorMessage)
|
||||||
|
refs = append(refs, errRefs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return refs
|
return refs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user