Different providers in the same resource file

We are building a terraform file including AWS and Databricks resources. Both of these have different providers but are directly dependent on each other. In the Terraform providers file, can you include different providers to be used in the same file?

Providers:
https://registry.terraform.io/providers/databrickslabs/databricks/latest
https://registry.terraform.io/providers/hashicorp/aws/latest

1 Like

Hi @garyrizzo1992,

Yes, it is not only valid, but quite common to have multiple different providers within the same configuration.

If you have questions about using multiple providers, it would help to add an example of the configuration to show better demonstrate the issue.

I had modified the code and created separate modules. But how would you structure the provider.tf file with the providers in the initial question?

Sorry, I’m not sure what you’re asking. There is no structure to a file with provider configurations, other than the individual configurations themselves. Can you add an example of the configuration which is causing a problem to demonstrate the issue?

An example is below of one of my versions.tf and main.tf files for Terraform 14+ where I’m using AWS and Gitlab resources. Also utilizing multiple regions with AWS so you can see how that would work. Hope this helps.
versions.tf

terraform {
  required_version = ">= 0.14"
  required_providers {
    aws = {
      source = "hashicorp/aws"
    }
    gitlab = {
      source = "gitlabhq/gitlab"
    }
  }
}

main.tf

provider “aws” {
region = “us-east-1”
}

provider “aws” {
region = “us-east-2”
alias = “useast2”
}

provider “gitlab” {
token = var.TERRA_TOKEN
base_url = “https://gitlab.com/api/v4/
}