forked from terraform-aws-modules/terraform-aws-rds-aurora
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
129 lines (103 loc) · 4.03 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
provider "aws" {
region = local.region
}
locals {
name = "example-${replace(basename(path.cwd), "_", "-")}"
region = "eu-west-1"
tags = {
Owner = "user"
Environment = "dev"
}
}
################################################################################
# Supporting Resources
################################################################################
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
name = local.name
cidr = "10.99.0.0/18"
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
database_subnets = ["10.99.7.0/24", "10.99.8.0/24", "10.99.9.0/24"]
tags = local.tags
}
################################################################################
# RDS Aurora Module - PostgreSQL
################################################################################
module "aurora_postgresql" {
source = "../../"
name = "${local.name}-postgresql"
engine = "aurora-postgresql"
engine_mode = "serverless"
storage_encrypted = true
vpc_id = module.vpc.vpc_id
subnets = module.vpc.database_subnets
create_security_group = true
allowed_cidr_blocks = module.vpc.private_subnets_cidr_blocks
monitoring_interval = 60
apply_immediately = true
skip_final_snapshot = true
db_parameter_group_name = aws_db_parameter_group.example_postgresql.id
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.example_postgresql.id
# enabled_cloudwatch_logs_exports = # NOT SUPPORTED
scaling_configuration = {
auto_pause = true
min_capacity = 2
max_capacity = 16
seconds_until_auto_pause = 300
timeout_action = "ForceApplyCapacityChange"
}
}
resource "aws_db_parameter_group" "example_postgresql" {
name = "${local.name}-aurora-db-postgres-parameter-group"
family = "aurora-postgresql10"
description = "${local.name}-aurora-db-postgres-parameter-group"
tags = local.tags
}
resource "aws_rds_cluster_parameter_group" "example_postgresql" {
name = "${local.name}-aurora-postgres-cluster-parameter-group"
family = "aurora-postgresql10"
description = "${local.name}-aurora-postgres-cluster-parameter-group"
tags = local.tags
}
################################################################################
# RDS Aurora Module - MySQL
################################################################################
module "aurora_mysql" {
source = "../../"
name = "${local.name}-mysql"
engine = "aurora-mysql"
engine_mode = "serverless"
storage_encrypted = true
vpc_id = module.vpc.vpc_id
subnets = module.vpc.database_subnets
create_security_group = true
allowed_cidr_blocks = module.vpc.private_subnets_cidr_blocks
monitoring_interval = 60
apply_immediately = true
skip_final_snapshot = true
db_parameter_group_name = aws_db_parameter_group.example_mysql.id
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.example_mysql.id
# enabled_cloudwatch_logs_exports = # NOT SUPPORTED
scaling_configuration = {
auto_pause = true
min_capacity = 2
max_capacity = 16
seconds_until_auto_pause = 300
timeout_action = "ForceApplyCapacityChange"
}
}
resource "aws_db_parameter_group" "example_mysql" {
name = "${local.name}-aurora-db-mysql-parameter-group"
family = "aurora-mysql5.7"
description = "${local.name}-aurora-db-mysql-parameter-group"
tags = local.tags
}
resource "aws_rds_cluster_parameter_group" "example_mysql" {
name = "${local.name}-aurora-mysql-cluster-parameter-group"
family = "aurora-mysql5.7"
description = "${local.name}-aurora-mysql-cluster-parameter-group"
tags = local.tags
}