Introduction
Scenario
This article explains why it is not currently possible to use multiple versions of a single terraform provider and suggests a path forward.
Terraform is intending to configure real-world infrastructure, as instructed by the configuration of the *.tf files. There must be a provider for each resource configured, along with which version to use. Terraform configurations must declare which providers they require so that Terraform can install and use them.
- Terraform relies on plugins called "providers" to interact with remote systems. Terraform configurations must declare which providers they require, so that Terraform can install and use them.
-
Each provider plugin has its own set of available versions, allowing the functionality of the provider to evolve over time. Each provider dependency you declare should have a version constraint given in the version argument so Terraform can select a single version per provider that all modules are compatible with.
-
Every resource type is implemented by a provider; without providers, Terraform can't manage any kind of infrastructure. Providers are released separately from Terraform itself and have their own version numbers. In production we recommend constraining the acceptable provider versions in the configuration's provider requirements block, to make sure that terraform init does not install newer versions of the provider that are incompatible with the configuration.
-
As described in Best Practices for Provider Versions, each module should at least declare the minimum provider version it is known to work with, using the
>=
version constraint syntax: A module intended to be used as the root of a configuration — that is, as the directory where you'd run terraform apply — should also specify the maximum provider version it is intended to work with, to avoid accidental upgrades to incompatible new versions. - Providers that are published in either the public Terraform Registry or in a third-party provider registry, terraform init will automatically find, download, and install the necessary provider plugins. After successful installation, Terraform writes information about the selected providers to the dependency lock file. You should commit this file to your version control system to ensure that when you run
terraform init
again in future Terraform will select exactly the same provider versions.
For that reason, there can only be 1 version - associated with - each name of terraform provider installed, at any one time.
Recommendation
As Terraform does not support multiple versions of the same provider in a single root module, and as a consequence Terraform Enterprise does not support multiple versions of the same provider in a single workspace, the recommended workaround, is to review the underlying modules to see whether provider constraints can be loosened or the providers upgraded.
Additional Information
-
Historically, the Terraform team considered this multiple times and the outcome was to make provider upgrades easier.
- discussed here: https://discuss.hashicorp.com/t/terraform-downloading-multiple-versions-of-aws-provider/59741/3
- and here: https://discuss.hashicorp.com/t/multiple-versions-of-same-provider-explicit-module-provider/20832/2
-
and described in this closed issue: https://github.com/hashicorp/terraform/issues/16641
Note: this article discussed provider version numbers, which is different to, the use of a provider alias - that can be used to pass variable attributes to a provider, reused in several contexts (like region on the aws provider)