opentofu: data source with for_each don't evaluate postconditions

OpenTofu Version

1.8.4

OpenTofu Configuration Files

data "gitlab_project" "upstream" {
  for_each = { for project in var.projects : project.path => project }

  path_with_namespace = each.key

  lifecycle {
    postcondition {
      condition = self.visibility_level == "public"
      error_message = "must be public"
    }
  }
}

Debug Output

coming …

Expected Behavior

That the postcondition is evaluate for “each” element of the for_each data source.

Actual Behavior

The postcondition doesn’t seem to be evaluated even though the condition must evaluate to false. I can show this by configuring an output that gives me the result of the conditions.

Steps to Reproduce

tofu plan

(I expect it to be evaluated during the plan)

Additional Context

There was a brief discussion on Slack here: https://opentofucommunity.slack.com/archives/C05R0FD0VRU/p1736497678504159

References

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 19 (14 by maintainers)

Most upvoted comments

@ollevche and I had a brief debug session and it turns out that renaming the data source with the for_each “fixes” the problem. We have three things to look into:

  • is there some caching going on?
  • is self not correctly referencing the for_each objects and maybe randomly picking an instance
  • if the data source doesn’t have any updates when read during plan does it not evaluate the postconditions?

cc @abstractionfactory