Proof-of-concept only: replace "any" type constraint placeholder with "inferred" #32461
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These changes are just an experiment with the idea of renaming the "any" type constraint placeholder with another keyword "inferred" which has exactly the same functionality but is more explicit about what it represents.
Since adding
any
in Terraform v0.12 it's become a bit of an attractive nuisance, because its name makes people think it represents full dynamic typing but really it represents automatic inference of a single exact type. For simple situations the automatic inference does something essentially equivalent to full dynamic typing and so new module authors will often try it and see that it seems to work as they expected even though they have made an incorrect assumption about its purpose, and then only run into trouble later when their module is in real-world use but it's become hard to revise the design without breaking backward compatibility.This PR is just trying out one possible idea for how to address this. It includes the following:
inferred
in any location where theany
placeholder was previously valid, with exactly the same meaning and resulting behavior.any
, recommending to adoptinferred
instead.terraform fmt
will automatically rewriteany
toinferred
, to make it easy to migrate and thus silence the warnings.This is not viable to ship as-is and is not intended to be. The goal here is only to evaluate the technical complexity of making this change, which seems to be relatively light.
If we did want to do something in this direction in a future release, I expect we'd want to roll it out more gradually rather than all in one go like this.
Specifically, I'd recommend to make
any
andinferred
exactly equivalent (no deprecation warnings) and include theterraform fmt
change for at least one whole minor release before explicitly deprecatingany
, so that there is a suitable window for module authors to migrate before their modules start generating warnings. We may choose to increase that window over multiple minor releases to ease the tradeoff between ending support for earlier Terraform versions (that won't acceptinferred
at all) or generating noisy warnings on newer versions of Terraform.Updating the docs to primarily describe
inferred
and to mentionany
only as a deprecated feature, along with theterraform fmt
change, would hopefully go a long way to discourage usingany
for totally new modules. But we also know that new Terraform users often use existing public modules as a foundation for their learning and so long-deprecated patterns tend to stick around as long as there are highly-visible public modules still using them, and so the effectiveness of this change would be limited as long as there isn't an incentive to update existing modules to use the new keyword.This is just here to illustrate one possible path forward. There's no plan to do anything real with this right now, and a final plan in this area might involve doing something entirely different than what I tried here.