mirror of
https://github.com/terraform-aws-modules/terraform-aws-rds-proxy.git
synced 2025-12-16 16:01:11 +00:00
Co-authored-by: Orest Kapko <orest.kapko@welltech.com> Co-authored-by: Amitai Getzler <amitai.getzler@explorium.ai> Co-authored-by: Orest Kapko <kapko2311@gmail.com> Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com> Co-authored-by: Anton Babenko <anton@antonbabenko.com>
144 lines
3.7 KiB
HCL
144 lines
3.7 KiB
HCL
provider "aws" {
|
|
region = local.region
|
|
}
|
|
|
|
data "aws_availability_zones" "available" {}
|
|
|
|
locals {
|
|
name = "ex-${basename(path.cwd)}"
|
|
region = "eu-west-1"
|
|
|
|
vpc_cidr = "10.0.0.0/16"
|
|
azs = slice(data.aws_availability_zones.available.names, 0, 3)
|
|
|
|
tags = {
|
|
Example = local.name
|
|
GithubRepo = "terraform-aws-rds-proxy"
|
|
GithubOrg = "terraform-aws-modules"
|
|
}
|
|
}
|
|
|
|
################################################################################
|
|
# RDS Proxy
|
|
################################################################################
|
|
|
|
module "rds_proxy" {
|
|
source = "../../"
|
|
|
|
name = local.name
|
|
iam_role_name = local.name
|
|
vpc_subnet_ids = module.vpc.private_subnets
|
|
vpc_security_group_ids = [module.rds_proxy_sg.security_group_id]
|
|
|
|
endpoints = {
|
|
read_write = {
|
|
name = "read-write-endpoint"
|
|
vpc_subnet_ids = module.vpc.private_subnets
|
|
vpc_security_group_ids = [module.rds_proxy_sg.security_group_id]
|
|
tags = local.tags
|
|
},
|
|
read_only = {
|
|
name = "read-only-endpoint"
|
|
vpc_subnet_ids = module.vpc.private_subnets
|
|
vpc_security_group_ids = [module.rds_proxy_sg.security_group_id]
|
|
target_role = "READ_ONLY"
|
|
tags = local.tags
|
|
}
|
|
}
|
|
|
|
auth = {
|
|
"root" = {
|
|
description = "Cluster generated master user password"
|
|
secret_arn = module.rds.cluster_master_user_secret[0].secret_arn
|
|
}
|
|
}
|
|
|
|
engine_family = "MYSQL"
|
|
debug_logging = true
|
|
|
|
# Target Aurora cluster
|
|
target_db_cluster = true
|
|
db_cluster_identifier = module.rds.cluster_id
|
|
|
|
tags = local.tags
|
|
}
|
|
|
|
################################################################################
|
|
# Supporting Resources
|
|
################################################################################
|
|
|
|
module "vpc" {
|
|
source = "terraform-aws-modules/vpc/aws"
|
|
version = "~> 5.0"
|
|
|
|
name = local.name
|
|
cidr = local.vpc_cidr
|
|
|
|
azs = local.azs
|
|
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
|
|
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 3)]
|
|
database_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 6)]
|
|
|
|
tags = local.tags
|
|
}
|
|
|
|
module "rds" {
|
|
source = "terraform-aws-modules/rds-aurora/aws"
|
|
version = "~> 8.0"
|
|
|
|
name = local.name
|
|
engine = "aurora-mysql"
|
|
engine_version = "8.0"
|
|
master_username = "root"
|
|
|
|
# When using RDS Proxy w/ IAM auth - Database must be username/password auth, not IAM
|
|
iam_database_authentication_enabled = false
|
|
|
|
instance_class = "db.r6g.large"
|
|
instances = {
|
|
1 = {}
|
|
2 = {}
|
|
}
|
|
|
|
vpc_id = module.vpc.vpc_id
|
|
db_subnet_group_name = module.vpc.database_subnet_group_name
|
|
security_group_rules = {
|
|
vpc_ingress = {
|
|
cidr_blocks = module.vpc.private_subnets_cidr_blocks
|
|
}
|
|
}
|
|
|
|
apply_immediately = true
|
|
skip_final_snapshot = true
|
|
|
|
tags = local.tags
|
|
}
|
|
|
|
module "rds_proxy_sg" {
|
|
source = "terraform-aws-modules/security-group/aws"
|
|
version = "~> 5.0"
|
|
|
|
name = "${local.name}-proxy"
|
|
description = "PostgreSQL RDS Proxy example security group"
|
|
vpc_id = module.vpc.vpc_id
|
|
|
|
revoke_rules_on_delete = true
|
|
|
|
ingress_with_cidr_blocks = [
|
|
{
|
|
description = "Private subnet MySQL access"
|
|
rule = "mysql-tcp"
|
|
cidr_blocks = join(",", module.vpc.private_subnets_cidr_blocks)
|
|
}
|
|
]
|
|
|
|
egress_with_cidr_blocks = [
|
|
{
|
|
description = "Database subnet MySQL access"
|
|
rule = "mysql-tcp"
|
|
cidr_blocks = join(",", module.vpc.database_subnets_cidr_blocks)
|
|
},
|
|
]
|
|
|
|
tags = local.tags
|
|
}
|