Terraform Advanced — Cross-Provider Dependencies

less than 1 minute read

Referencing resources across cloud providers.


Direct References

# AWS creates a VPN endpoint
resource "aws_vpn_gateway" "main" {
  vpc_id = aws_vpc.main.id
}

# GCP creates a VPN tunnel to the AWS endpoint
resource "google_compute_vpn_tunnel" "to_aws" {
  name          = "aws-tunnel"
  peer_ip       = aws_vpn_gateway.main.id  # Cross-provider reference
  shared_secret = var.vpn_shared_secret
  # ...
}

Terraform handles the dependency automatically — GCP tunnel waits for AWS gateway.


Using terraform_remote_state

When resources are in separate states:

# In the GCP project
data "terraform_remote_state" "aws_networking" {
  backend = "s3"
  config = {
    bucket = "my-tf-state"
    key    = "aws/networking/terraform.tfstate"
    region = "us-east-1"
  }
}

resource "google_compute_vpn_tunnel" "to_aws" {
  peer_ip = data.terraform_remote_state.aws_networking.outputs.vpn_gateway_ip
}

What’s Next?

Set up GCP and Azure alongside AWS.

← Multiple Providers GCP & Azure Alongside AWS →

Updated: