Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable validation should allow checking other variables #24374

Closed
alexjurkiewicz opened this issue Mar 14, 2020 · 3 comments
Closed

Variable validation should allow checking other variables #24374

alexjurkiewicz opened this issue Mar 14, 2020 · 3 comments
Labels
custom-conditions Feedback on variable validation, preconditions. postconditions, checks, and test assertions duplicate issue closed because another issue already tracks this problem

Comments

@alexjurkiewicz
Copy link

alexjurkiewicz commented Mar 14, 2020

Sometimes I have variables like shut_down_on_weekends:

variable environment_type {
  type = string
  description = "test or prod"
}

variable shut_down_on_weekends {
  type = bool
  description = "You can't shut production environments down on the weekend"
  default = false
}

locals {
  actually_shut_down = var.shut_down_on_weekends && var.environment_type == "test"
}

Rather than creating an intermediate local to silently fix the issue, I would prefer to use variable validation to raise an error at planning time:

variable shut_down_on_weekends {
  type = bool
  validation {
    condition     = var.shut_down_on_weekends || var.environment_type == "test"
    error_message = "You can only shut test environments down on the weekend."
  }
}

It would be possible to write cyclic dependencies with this functionality, so some care would need to be made to ensure that case is detected.

@colans
Copy link

colans commented Jul 15, 2021

Can we mark this as a duplicate of #25609 given that it has somewhat of a plan?

@crw
Copy link
Collaborator

crw commented Mar 6, 2024

Yes, marking dupe of #25609.

@crw crw closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2024
@crw crw added the duplicate issue closed because another issue already tracks this problem label Mar 6, 2024
Copy link

github-actions bot commented Apr 6, 2024

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
custom-conditions Feedback on variable validation, preconditions. postconditions, checks, and test assertions duplicate issue closed because another issue already tracks this problem
Projects
None yet
Development

No branches or pull requests

4 participants