This repository provides Terraform configurations to deploy Terraform Enterprise (TFE) using the HashiCorp Validated Design (HVD) module. It supports single-region (primary only) and multi-region (primary + DR) deployments, with a documented DR failover procedure.
primary/- Primary region TFE deployment using the HVD module.dr/- DR region TFE deployment configured as the Aurora Global Database replica. Includes optional VPC creation for demo purposes.failover/- Combined Terraform workspace that updates Cloudflare DNS and triggers Aurora Global Database failover/switchover.
- Required secrets in AWS Secrets Manager (encrypted with KMS) must exist in the primary region before apply; for multi-region deployments, replicate those secrets and the KMS key to the DR region first.
Use the primary/ directory only.
- Copy and edit the variables file:
Copy-Item primary/terraform.tfvars.example primary/terraform.tfvars- Update
primary/terraform.tfvarswith your values:
regionvpc_id,lb_subnet_ids,ec2_subnet_ids,rds_subnet_ids,redis_subnet_idstfe_fqdn, secrets ARNs, and sizing settingscreate_route53_tfe_dns_record(setfalseif using Cloudflare)
- Apply:
cd primary
terraform init
terraform applyThe primary outputs include tfe_urls.tfe_lb_dns_name, which you can use for DNS in Cloudflare.
Deploy primary first, then DR.
Follow the single-region steps above and apply in primary/.
- Copy and edit the variables file:
Copy-Item dr/terraform.tfvars.example dr/terraform.tfvars- Update
dr/terraform.tfvarswith your DR region values. Indr/main.tf, set the Aurora Global Database replication inputs (these are required for the secondary region):
rds_global_cluster_id(from primary output)rds_source_region(primary region)rds_replication_source_identifier(primary RDS cluster ARN)rds_kms_key_arn(KMS key in DR region replicated from primary)
- Apply in
dr/:
cd dr
terraform init
terraform applyThe DR outputs include tfe_urls.tfe_lb_dns_name for DNS failover.
Use the failover/ directory to manage the Cloudflare DNS alias and trigger Aurora Global Database failover/switchover. The module wraps the AWS CLI using a null_resource and local-exec, so the AWS CLI must be available in the Terraform execution environment with valid AWS credentials.
- Copy and edit the variables file:
Copy-Item failover/terraform.tfvars.example failover/terraform.tfvars- Update
failover/terraform.tfvars:
cloudflare_api_tokencloudflare_zone_idactive_region(primaryordr)actionandrun_id(optional, used to control the RDS API call and force re-run)global_cluster_identifierandtarget_db_cluster_identifierare optional overrides; by default they are pulled from the primary/DR remote state outputs.
-
If you need a different DNS name, update
nameinfailover/main.tf. -
Apply:
cd failover
terraform init
terraform applySwitching DNS during failover/failback is done by changing active_region and re-applying.
Example to fail over DNS to DR:
cd failover
terraform apply -var "active_region=dr"Follow the sequence below during a regional failover.
- Bring the DR ASG to 1:
cd dr
terraform apply -var "asg_instance_count=1"- Fail over Aurora Global Database to DR using the
failover/workspace:
cd failover
terraform apply -var "action=failover-global-cluster" -var "active_region=dr"You can get the identifiers from primary/outputs.tf and dr/outputs.tf via terraform output -json.
- The same apply updates Cloudflare DNS to point to the DR NLB via
active_region=dr.
Optionally, scale down the primary ASG after failover:
cd primary
terraform apply -var "asg_instance_count=0"Use this sequence once the primary region is healthy again.
- Bring the primary ASG back to 1:
cd primary
terraform apply -var "asg_instance_count=1"- Switch the Aurora Global Database back to primary using the
failover/workspace:
cd failover
terraform apply -var "action=switchover-global-cluster" -var "active_region=primary"- The same apply updates Cloudflare DNS back to the primary NLB via
active_region=primary.
Optionally, scale down the DR ASG after failback:
cd dr
terraform apply -var "asg_instance_count=0"- Terraform HVD module: https://github.com/hashicorp/terraform-aws-terraform-enterprise-hvd
- Terraform DR guidance: https://www.hashicorp.com/en/blog/disaster-recovery-strategies-with-terraform
