'Cannot override provider configuration error in installing DC/OS via Terraform on azure

Working on setting up DC/OS on Microsoft Azure using Terraform. I'm using the main.tf provided in the official documentation. Every time I run terraform init I get an error:

Error: Cannot override provider configuration │ │ on .terraform/modules/dcos/main.tf line 138, in module "dcos-infrastructure": │ 138: azurerm = azurerm

I have authenticated via az CLI specifically via the command az login --use-device-code

My terraform version is: Terraform v1.1.9 on linux_amd64

How can I resolve this? my attempts to comment out the providers still produces this error.



Solution 1:[1]

If you are using module in you main.tf file, You have to use `Provider Aliases in main file

To declare multiple configuration names for a provider within a module, add the configuration_aliases argument:

You can take reference of this aws and edit it for azure accordignly.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 2.7.0"
      configuration_aliases = [ aws.alternate ]
    }
  }
}

Passing Providers Explicitly

main.tf

provider "aws" {
  alias  = "usw2"
  region = "us-west-2"
}

# An example child module is instantiated with the alternate configuration,
# so any AWS resources it defines will use the us-west-2 region.
module "example" {
  source    = "./example"
  providers = {
    aws.alternate = aws.usw2
  }
}

You can refer this document for information, How to use provider when using module in main.tf

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RahulKumarShaw-MT