-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Allow warning messages within variable validation #32594
Comments
Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again! |
This sounds reasonable to me, given that the variables for a module form part of its public API. |
I hope this request gets expanded for all constraints, not just within a module - as vars can come from the environment and having non-error warnings is often far superior than crash-and-burn checks. |
This would be a incredible for us - we're currently trying to standardise naming conventions and being able to add in a simple regex validation on inputs (for example, all lower case and dashes instead of underscores) without requiring everything to update at once would be amazing |
Hey @derekwinters, Thanks for raising this issue. It seems you're suggesting two distinct features:
Both ideas are valuable and worth exploring. Note For context, when I refer to a module’s "interface" I’m talking about its input variables and output values. 1. Deprecating input variablesWe're currently prototyping support for deprecating input variables and outputs. This would provide a similar experience to deprecating provider resource arguments, allowing module authors to gradually phase out input variables and outputs and guide users towards newer, preferred options. You can track the progress of this feature in #36016. 2. Warning diagnostic for custom conditionsCurrently, custom conditions in Terraform (like variable validation, preconditions, and postconditions) can only trigger error diagnostics. This can be limiting, as sometimes a warning might be more appropriate for a less critical validation failure. To address this, we could introduce a Here’s an example: variable "instance_type" {
type = string
validation {
condition = contains(["t2.micro", "t2.small", "t2.medium"], var.instance_type)
warning_message = "Selected instance type may not handle heavy workloads."
}
} Alternatively, in a postcondition: data "aws_instance" "example" {
instance_id = "i-1234567890abcdef0"
lifecycle {
postcondition {
condition = data.aws_instance.example.public_ip != ""
warning_message = "The instance has a public IP, potentially exposing it to the internet."
}
}
} Drawbacks of warning diagnostic for custom conditions
Next stepsI'll discuss this proposal with the team to get their feedback and explore a potential implementation. Thanks again for raising this issue. Let's continue the conversation! |
Warnings are common in all sorts of things. Loggers, missing extras in packages, imports of dependencies of dependencies (not in your pyproject.toml), wet floors... If you ignore warnings, you get what's coming. I want to warn about unconventional or "could fail in some situations" configurations, or "this configuration won't support xyz functionality" without preventing the user from doing those dangerous things. Maybe they're just setting up a quick, dirty, cheap development environment and don't care. In my IDE (PyCharm), missing Terraform variables are presented as strong warnings in the code (yellow highlighting), and errors on plan/apply. A warning would ideally result in a weak warning (zigzag line), and on plan/apply, a printed, very visible warning. It's a big request for sure, but even just printing a yellow warning on plan/apply would be enough to catch or ignore problems based on the strictness of the company/CI. |
Terraform Version
Use Cases
I want to be able to raise a warning in a Terraform module, similar to how a provider raises a warning for deprecated arguments.
We focus heavily on maintaining backwards compatibility and giving time to transition how modules are used, so we end up deprecating module variables in favor of new variables from time to time. We document this in variable descriptions and the logic that uses them handles the logic for transitioning, but being able to clearly highlight the deprecations in the plan would be very useful as well.
Attempted Solutions
The way we accomplish this today is simply in descriptions, readme/documentation, and in the implementation of the variables.
As a highly simplified example, we may want to change the name of a variable as we update legacy modules to use standard variable name structures and input types across all our modules.
Proposal
It would be useful to highlight the deprecated variables of a module within the Terraform plan. For this to work, it would need to be possible to choose warning or error for the validation.
This would then trigger a warning message at the end of the plan, similar to provider warnings or variable validation errors.
References
No response
The text was updated successfully, but these errors were encountered: