|
| 1 | +provider "aws" { |
| 2 | + region = "us-east-1" |
| 3 | +} |
| 4 | + |
| 5 | +###################################### |
| 6 | +# Data sources to get VPC and subnets |
| 7 | +###################################### |
| 8 | +data "aws_vpc" "default" { |
| 9 | + default = true |
| 10 | +} |
| 11 | + |
| 12 | +data "aws_subnet_ids" "all" { |
| 13 | + vpc_id = data.aws_vpc.default.id |
| 14 | +} |
| 15 | + |
| 16 | +############# |
| 17 | +# RDS Aurora |
| 18 | +############# |
| 19 | +module "aurora" { |
| 20 | + source = "../../" |
| 21 | + name = "aurora-example-postgresql" |
| 22 | + engine = "aurora-postgresql" |
| 23 | + engine_version = "11.6" |
| 24 | + subnets = data.aws_subnet_ids.all.ids |
| 25 | + vpc_id = data.aws_vpc.default.id |
| 26 | + replica_count = 3 |
| 27 | + instance_type = "db.r5.large" |
| 28 | + apply_immediately = true |
| 29 | + skip_final_snapshot = true |
| 30 | + db_parameter_group_name = aws_db_parameter_group.aurora_db_postgres11_parameter_group.id |
| 31 | + db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_postgres11_parameter_group.id |
| 32 | + // enabled_cloudwatch_logs_exports = ["audit", "error", "general", "slowquery"] |
| 33 | + security_group_description = "" |
| 34 | + |
| 35 | + instances_parameters = [ |
| 36 | + // List index should be equal to `replica_count` |
| 37 | + // Omitted keys replaced by module defaults |
| 38 | + { |
| 39 | + instance_type = "db.r5.2xlarge" |
| 40 | + publicly_accessible = true |
| 41 | + }, |
| 42 | + { |
| 43 | + instance_type = "db.r5.2xlarge" |
| 44 | + }, |
| 45 | + { |
| 46 | + instance_name = "reporting" |
| 47 | + instance_type = "db.r5.large" |
| 48 | + instance_promotion_tier = 15 |
| 49 | + } |
| 50 | + ] |
| 51 | +} |
| 52 | + |
| 53 | +resource "aws_db_parameter_group" "aurora_db_postgres11_parameter_group" { |
| 54 | + name = "test-aurora-db-postgres11-parameter-group" |
| 55 | + family = "aurora-postgresql11" |
| 56 | + description = "test-aurora-db-postgres11-parameter-group" |
| 57 | +} |
| 58 | + |
| 59 | +resource "aws_rds_cluster_parameter_group" "aurora_cluster_postgres11_parameter_group" { |
| 60 | + name = "test-aurora-postgres11-cluster-parameter-group" |
| 61 | + family = "aurora-postgresql11" |
| 62 | + description = "test-aurora-postgres11-cluster-parameter-group" |
| 63 | +} |
| 64 | + |
| 65 | +############################ |
| 66 | +# Example of security group |
| 67 | +############################ |
| 68 | +resource "aws_security_group" "app_servers" { |
| 69 | + name_prefix = "app-servers-" |
| 70 | + description = "For application servers" |
| 71 | + vpc_id = data.aws_vpc.default.id |
| 72 | +} |
| 73 | + |
| 74 | +resource "aws_security_group_rule" "allow_access" { |
| 75 | + type = "ingress" |
| 76 | + from_port = module.aurora.this_rds_cluster_port |
| 77 | + to_port = module.aurora.this_rds_cluster_port |
| 78 | + protocol = "tcp" |
| 79 | + source_security_group_id = aws_security_group.app_servers.id |
| 80 | + security_group_id = module.aurora.this_security_group_id |
| 81 | +} |
0 commit comments