Terraform Advanced — Multiple Providers in One Module
Use AWS, GCP, and Azure resources together.
Declaring Multiple Providers
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
provider "google" {
project = "my-gcp-project"
region = "us-central1"
}
provider "azurerm" {
features {}
}
Cross-Cloud DNS Example
# App runs on AWS
resource "aws_instance" "app" {
ami = "ami-0abcdef1234567890"
instance_type = "t3.micro"
}
# DNS managed in GCP Cloud DNS
resource "google_dns_record_set" "app" {
name = "app.example.com."
type = "A"
ttl = 300
managed_zone = "example-zone"
rrdatas = [aws_instance.app.public_ip]
}
💡 Production Tip: Keep multi-cloud in a single state only when resources are tightly coupled. Otherwise, separate states per cloud.
What’s Next?
Handle cross-provider dependencies.