Terraform: Duplicate required providers configuration

Error

Initializing the backend…
Terraform encountered problems during initialisation, including problems
with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

│ Error: Duplicate required providers configuration

│ on providers.tf line 15, in terraform:
│ 15: required_providers {

│ A module may have only one required providers configuration. The required providers were previously configured at
│ providers.tf:2,3-21.


│ Error: Duplicate required providers configuration

│ on providers.tf line 15, in terraform:
│ 15: required_providers {

│ A module may have only one required providers configuration. The required providers were previously configured at
│ providers.tf:2,3-21.

Answer

YOU SHOULD NOT HAVE MORE THAN TWO “terraform” block in terraform code

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "5.17.0"
    }
	azurerm = {
      source = "hashicorp/azurerm"
      version = "3.73.0"
    }
	github = {
      source = "integrations/github"
      version = "5.37.0"
    }
  }
}

provider "aws" {
  # Configuration options
}


provider "azurerm" {
  # Configuration options
}


provider "github" {
  # Configuration options
}
5 1 vote
Article Rating
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Lalit
Lalit
6 months ago

I also faced the same issue. The simple solution to create override file and add all other provider config on that file so during initialization it will merge the config.

provider.tf
==
 provider “aws” {
  region = var.region
}
==

provider_override.tf
==
terraform {
  required_providers {
    kubectl = {
      source  = “gavinbunney/kubectl”
      version = “>= 1.14.0”
    }
    helm = {
      source  = “hashicorp/helm”
      version = “>= 2.6.0”
    }
  }

 required_version = “~> 1.0”
}
==

1
0
Would love your thoughts, please comment.x
()
x