I'm updating my project to use the latest version of terraform. Each terraform directory in my project has it's own versions.tf file:
terraform
├── s3
│ ├── main.tf
│ └── variables.tf
│ └── versions.tf
├── pinpoint
├── main.tf
└── variables.tf
└── versions.tf
To keep things clean and avoid repeating myself by updating the version in every versions.tf, I was wondering if it was possible to have just one versions.tf file in the project that all directories can use like this:
terraform
├── s3
│ ├── main.tf
│ └── variables.tf
├── pinpoint
│ ├── main.tf
│ └── variables.tf
│
└── versions.tf
Is this possible? Is there a way to reference another versions file? (terraform version 0.12.31)
The typical content of versions.tf
is a description of the providers needed by each specific module and, if needed, the version of Terraform that module is intended to support.
There should be no reason to share these declarations between modules because they are module-specific: one module might require a newer version of a provider than another, for example. It is not repetition to state the requirements for each module just because some of them happen to currently have the same requirements, because these modules should be able to evolve independently over time rather than always changing their requirements in lockstep.
Terraform will automatically select the newest available version of each required provider that meets the constraints of all modules involved in a particular configuration, so as long as all of your modules can agree on one version they are compatible with there is no need to tightly coordinate them.
Note that the required_providers
block is intended to represent the set of provider versions that your module is known to be compatible with. That's not the appropriate place to select only a single version of a provider. Terraform automatically records the single selected version of each provider in the dependency lock file, so you can check that file into version control to fix a particular set of version selections, and then run terraform init -upgrade
whenever you want to update that file to select newer available versions that are also compatible with your modules' version constraints.
If you really do still want to share a file between multiple configurations then you can achieve that using a symbolic links mechanism provided by your operating system, to make the same file appear to be in multiple directories. In that case Terraform isn't aware that the file is shared across all of them and so it will still treat each directory as separate, but you can update the real file and then all of the symbolic links will refer to the updated copy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With