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

Proof-of-concept only: replace "any" type constraint placeholder with "inferred" #32461

Closed
wants to merge 2 commits into from

Conversation

apparentlymart
Copy link
Member

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:

  • Terraform will accept the keyword inferred in any location where the any placeholder was previously valid, with exactly the same meaning and resulting behavior.
  • Terraform will emit a warning if a module uses any, recommending to adopt inferred instead.
  • terraform fmt will automatically rewrite any to inferred, 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 and inferred exactly equivalent (no deprecation warnings) and include the terraform fmt change for at least one whole minor release before explicitly deprecating any, 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 accept inferred at all) or generating noisy warnings on newer versions of Terraform.

Updating the docs to primarily describe inferred and to mention any only as a deprecated feature, along with the terraform fmt change, would hopefully go a long way to discourage using any 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.

These have equivalent functionality but "inferred" is preferred because it
is more explicit about what it means. Historically we've seen that many
people expect "any" to mean full dynamic typing, when in fact it is just
a request for Terraform to infer an exact type automatically.
@apparentlymart apparentlymart self-assigned this Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant