问题
I am trying to deploy Azure resources through Terraform 0.12 with azurerm provider. I have AKS module which works fine with azurerm version 2.5.0, but breaks with 2.9.0. On the other hand Postgresql module works with version 2.9.0 but breaks with 2.5.0 I want to deploy both resources through a single terraform apply.
I tried below configuration but it fails at initialize phase.
provider "azurerm" {
version = "=2.9.0"
}
provider "azurerm" {
alias = "latest"
version = "=2.5.0"
}
$ terraform.exe init
Initializing the backend...
Initializing provider plugins...
- Checking for available provider plugins...
No provider "azurerm" plugins meet the constraint "=2.5.0,=2.9.0".
The version constraint is derived from the "version" argument within the provider "azurerm" block in configuration. Child modules may also apply provider version constraints. To view the provider versions requested by each module in the current configuration, run "terraform providers".
To proceed, the version constraints for this provider must be relaxed by either adjusting or removing the "version" argument in the provider blocks throughout the configuration.
Error: no suitable version is available
How to install both provider versions and point AKS module to v2.5.0 and point Postgres module to v2.9.0
回答1:
Break the code into Modules and add provider section in your module and call the modules differently in your main.tf file.
Example
modules/AKS
provider {
}
modules/DB
provider {
}
Now call your modules differently
main.tf
module "AKS" {
source = "../modules/AKS"
}
module "DB" {
source = "../modules/DB"
}
来源:https://stackoverflow.com/questions/61707700/terraform-how-to-install-multiple-versions-of-provider-plugins