-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
256d799
commit bfbd0b7
Showing
8 changed files
with
208 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
*.lock.hcl | ||
|
||
# .tfstate files | ||
*.tfstate | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
locals { | ||
vpc_cidr = "10.0.0.0/16" | ||
|
||
azs_primary = slice(data.aws_availability_zones.available_primary.names, 0, 3) | ||
azs_secondary = slice(data.aws_availability_zones.available_secondary.names, 0, 3) | ||
} | ||
|
||
# Primary region | ||
data "aws_availability_zones" "available_primary" {} | ||
|
||
provider "aws" { | ||
alias = "primary" | ||
region = "eu-west-1" | ||
} | ||
|
||
module "vpc_primary" { | ||
source = "terraform-aws-modules/vpc/aws" | ||
version = "~> 4.0" | ||
|
||
name = "example" | ||
azs = local.azs_primary | ||
cidr = local.vpc_cidr | ||
database_subnets = [for k, v in local.azs_primary : cidrsubnet(local.vpc_cidr, 8, k + 6)] | ||
private_subnets = [for k, v in local.azs_primary : cidrsubnet(local.vpc_cidr, 8, k + 3)] | ||
public_subnets = [for k, v in local.azs_primary : cidrsubnet(local.vpc_cidr, 8, k)] | ||
} | ||
|
||
resource "random_string" "master_password" { | ||
length = 16 | ||
special = false | ||
} | ||
|
||
module "aurora_primary" { | ||
providers = { | ||
aws = aws.primary | ||
} | ||
|
||
source = "../.." | ||
|
||
name = "example" | ||
engine = "postgresql" | ||
engine_mode = "serverlessv2" | ||
engine_version = "16.4" | ||
global_database_primary = true | ||
instance_count = 2 # 1 Writer, 1 Reader | ||
master_password = random_string.master_password.result | ||
subnet_ids = module.vpc_primary.private_subnets | ||
|
||
security_group_ingress_rules = [ | ||
{ | ||
cidr_ipv4 = local.vpc_cidr | ||
description = "Allow access from the VPC CIDR range" | ||
} | ||
] | ||
} | ||
|
||
# Secondary region | ||
provider "aws" { | ||
alias = "secondary" | ||
region = "eu-central-1" | ||
} | ||
|
||
data "aws_availability_zones" "available_secondary" {} | ||
|
||
module "vpc_secondary" { | ||
providers = { | ||
aws = aws.secondary | ||
} | ||
|
||
source = "terraform-aws-modules/vpc/aws" | ||
version = "~> 4.0" | ||
|
||
name = "example" | ||
azs = local.azs_secondary | ||
cidr = local.vpc_cidr | ||
database_subnets = [for k, v in local.azs_secondary : cidrsubnet(local.vpc_cidr, 8, k + 6)] | ||
private_subnets = [for k, v in local.azs_secondary : cidrsubnet(local.vpc_cidr, 8, k + 3)] | ||
public_subnets = [for k, v in local.azs_secondary : cidrsubnet(local.vpc_cidr, 8, k)] | ||
} | ||
|
||
module "aurora_secondary" { | ||
providers = { | ||
aws = aws.secondary | ||
} | ||
|
||
source = "../.." | ||
|
||
name = "example" | ||
engine = "postgresql" | ||
engine_mode = "serverlessv2" | ||
engine_version = "16.4" | ||
instance_count = 1 # 1 Reader | ||
subnet_ids = module.vpc_secondary.private_subnets | ||
|
||
global_database_secondary = { | ||
global_cluster_identifier = module.aurora_primary.global_cluster_identifier | ||
} | ||
|
||
security_group_ingress_rules = [ | ||
{ | ||
cidr_ipv4 = local.vpc_cidr | ||
description = "Allow access from the VPC CIDR range" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.81.0" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 3.4.0" | ||
} | ||
} | ||
required_version = ">= 1.8" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ terraform { | |
version = ">= 5.81.0" | ||
} | ||
} | ||
required_version = ">= 1.3" | ||
required_version = ">= 1.8" | ||
} |