terraform
terraform copied to clipboard
Improve "undeclared variable" warning if compact-warnings flag is used
Terraform Version
Terraform 1.2.7
Use Cases
Developers will get the information on which declared variable is unnecessary.
Attempted Solutions
Add the name of the variable to the message if -compact-warnings flag is used.
The message could look like this: "Value for undeclared variable: resource_group_name"
Proposal
No response
References
The screenshot shows that the warnings "Value for undeclared variable" are not telling which variable it talks about. The other message is very specific.
Thanks for this feedback, @mkemmerz!
Currently "compact warnings" is reducing the warning messages only to what would normally be the opening line of the warning, after the "Warning: " prefix, which we call the "summary" internally.
The "use_microsoft_graph" ones happen to appear more verbose here because those warnings are not really implemented properly, and are putting the full details into the summary and leaving the detail completely unpopulated. It's interesting that this bug happens to make the compact presentation more useful, but that's an accident rather than intentional!
There is some tension here because most of our diagnostic messages are authored under the assumption that they will be viewed in full, and so the details are in the detail field. Adding more information to the summary field would make it less effective as a summary in the full warnings mode.
Therefore to meet this request it seems like we might need to introduce a third message for each warning diagnostic which is a combination of the summary and a subset of the detail in "detail" to produce a compact description of the problem all in one sentence.
With that said, the current intent of this feature is that you use -compact-warnings
essentially as a way to ignore warnings without fully hiding them. We added it in response to the fact that some people were intentionally causing warnings that they didn't intend to fix and ideally they wanted to hide the warnings altogether, but we didn't want to do that because it would then prevent them from seeing any new warnings they might activate in future and therefore cause their codebase to get gradually worse without them realizing it.
Due to this being just a compromise to approximately meet that need, we've so far expected that if you don't already know what the detail is for one of your warnings you should re-run Terraform without -compact-warnings
, fix the warning, and then go back to using -compact-warnings
if you wish. Of course it would be better to fix all of the warnings and then never see any warnings at all, but we understand that isn't always possible.
Indeed, in your case you are suffering from #31118 which (due to a bug in the Azure backend's deprecation of that argument) is impossible to quiet as long as you're using the Azure backend with v1.2. That has at least been addressed in v1.3 but the removal of ADAL and so that warning isn't present at all anymore.
We will consider ways to improve this, but I expect our priority will be making sure that any change here doesn't make the non-compact warning messages worse, because the non-compact mode is the primary way we expect most users to use Terraform. Whether it'll be viable to introduce additional messages just for compact mode, or if we'll find a different compromise, remains to be seen.
Thanks again!