Terraform: How to install multiple versions of provider plugins? [duplicate]

给你一囗甜甜゛ 提交于 2020-07-08 03:34:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!