TGViewer
CatOps CatOps @catops · 5.07K subscribers
Post #2331 2.51K
​​Terraform variable validation, when 2+ vars depend on each other

Basically, where is the answer in SO how to do it in 0.13+ via locals, but it does not include some important details:

This check works only for known during terraform plan values of variables.
If value of any of variables in the check is not known during terraform plan, the check will be skipped and error message will pop up only after terraform apply in the next terraform plan.

The pic below is an example of how that check works.


Note, that there is a feature request to make able to refer to other variables in the variable condition check, but that's needs architecture redesign, so there no ETA when we can drop that hack.

P.S. You can achieve something similar by using lifecycle precondition and postcondition in case if you support only TF 1.2+


#terraform
  • 👍 7
More from @catops
  1. Oct 8, 2026I’m going on a vacation, which means that I likely won’t post at all or post something ver…
  2. Oct 6, 2026A colleague of mine wrote an article about data migrations. Handling data migrations witho…
  3. Oct 1, 2026​​I traded my personal information for this report, so you don’t have to! DataDog presents…
  4. Sep 29, 2026A Cybersecurity books bundle by O’Reilly on Humble Bundle. The bundle is fresh and is stil…
  5. Sep 28, 2026​​For today’s Donations Monday, I’d like to remind you about a fundraiser for a pickup tru…
  6. Sep 26, 2026Here’s Datadog’s take on the increased load on CI. In this article they explain how their…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →