-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
82 lines (76 loc) · 3.64 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
resource "aws_security_group" "rds" {
name = "rds-${var.identifier}"
vpc_id = "${var.vpc_id}"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = "${merge(var.tags, map("Name", format("rds-%s", var.identifier)))}"
}
resource "aws_rds_cluster" "default" {
apply_immediately = "${var.apply_immediately}"
availability_zones = "${var.availability_zones}"
backup_retention_period = "${var.backup_retention_period_in_days}"
cluster_identifier = "${var.identifier}"
count = "${lookup(map("0", "0"), var.aurora_instance_count, 1)}"
database_name = "${var.db_name}"
db_subnet_group_name = "${aws_db_subnet_group.rds.0.id}"
deletion_protection = "${var.deletion_protection}"
master_password = "${var.db_password}"
master_username = "${var.db_username}"
port = "${var.db_port}"
preferred_backup_window = "${var.backup_window}"
preferred_maintenance_window = "${var.maintenance_window}"
snapshot_identifier = "${var.snapshot_identifier}"
tags = "${var.tags}"
vpc_security_group_ids = ["${aws_security_group.rds.id}"]
}
resource "aws_rds_cluster_instance" "cluster_instances" {
cluster_identifier = "${aws_rds_cluster.default.0.id}"
copy_tags_to_snapshot = "${var.copy_tags_to_snapshot}"
count = "${var.aurora_instance_count}"
db_subnet_group_name = "${aws_db_subnet_group.rds.0.id}"
identifier = "${var.identifier}-${count.index}"
instance_class = "${var.instance_class}"
publicly_accessible = "${var.publicly_accessible}"
skip_final_snapshot = "${var.skip_final_snapshot}"
tags = "${var.tags}"
}
resource "aws_db_instance" "default" {
allocated_storage = "${var.rds_storage}"
allow_major_version_upgrade = "${var.rds_allow_major_version_upgrade}"
apply_immediately = "${var.apply_immediately}"
backup_retention_period = "${var.backup_retention_period_in_days}"
backup_window = "${var.backup_window}"
copy_tags_to_snapshot = "${var.copy_tags_to_snapshot}"
count = "${var.rds_instance_count}"
db_subnet_group_name = "${join("", aws_db_subnet_group.rds.*.name)}"
deletion_protection = "${var.deletion_protection}"
engine = "${var.rds_engine}"
engine_version = "${var.rds_version}"
identifier = "${var.identifier}"
instance_class = "${var.instance_class}"
iops = "${var.iops}"
maintenance_window = "${var.maintenance_window}"
multi_az = "${var.rds_multi_az}"
name = "${var.db_name}"
parameter_group_name = "${var.parameter_group_name}"
password = "${var.db_password}"
port = "${var.db_port}"
publicly_accessible = "${var.publicly_accessible}"
replicate_source_db = "${var.replicate_source_db}"
skip_final_snapshot = "${var.skip_final_snapshot}"
snapshot_identifier = "${var.snapshot_identifier}"
storage_type = "${var.rds_storage_type}"
tags = "${var.tags}"
username = "${var.db_username}"
vpc_security_group_ids = ["${aws_security_group.rds.id}"]
}
resource "aws_db_subnet_group" "rds" {
count = "${var.replicate_source_db == "" ? 1 : 0}"
name = "${var.identifier}"
subnet_ids = ["${var.subnet_ids}"]
tags = "${var.tags}"
}