forked from azavea/terraform-aws-postgresql-rds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
124 lines (106 loc) · 4.02 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
#
# Security group resources
#
resource "aws_security_group" "postgresql" {
vpc_id = "${var.vpc_id}"
tags {
Name = "sgDatabaseServer"
Project = "${var.project}"
Environment = "${var.environment}"
}
}
#
# RDS resources
#
resource "aws_db_instance" "postgresql" {
allocated_storage = "${var.allocated_storage}"
engine = "postgres"
engine_version = "${var.engine_version}"
identifier = "${var.database_identifier}"
instance_class = "${var.instance_type}"
storage_type = "${var.storage_type}"
name = "${var.database_name}"
password = "${var.database_password}"
username = "${var.database_username}"
backup_retention_period = "${var.backup_retention_period}"
backup_window = "${var.backup_window}"
maintenance_window = "${var.maintenance_window}"
auto_minor_version_upgrade = "${var.auto_minor_version_upgrade}"
final_snapshot_identifier = "${var.final_snapshot_identifier}"
skip_final_snapshot = "${var.skip_final_snapshot}"
copy_tags_to_snapshot = "${var.copy_tags_to_snapshot}"
multi_az = "${var.multi_availability_zone}"
port = "${var.database_port}"
vpc_security_group_ids = ["${aws_security_group.postgresql.id}"]
db_subnet_group_name = "${var.subnet_group}"
parameter_group_name = "${var.parameter_group}"
storage_encrypted = "${var.storage_encrypted}"
tags {
Name = "DatabaseServer"
Project = "${var.project}"
Environment = "${var.environment}"
}
}
#
# CloudWatch resources
#
resource "aws_cloudwatch_metric_alarm" "database_cpu" {
alarm_name = "alarm${var.environment}DatabaseServerCPUUtilization"
alarm_description = "Database server CPU utilization"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/RDS"
period = "300"
statistic = "Average"
threshold = "${var.alarm_cpu_threshold}"
dimensions {
DBInstanceIdentifier = "${aws_db_instance.postgresql.id}"
}
alarm_actions = ["${var.alarm_actions}"]
}
resource "aws_cloudwatch_metric_alarm" "database_disk_queue" {
alarm_name = "alarm${var.environment}DatabaseServerDiskQueueDepth"
alarm_description = "Database server disk queue depth"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "DiskQueueDepth"
namespace = "AWS/RDS"
period = "60"
statistic = "Average"
threshold = "${var.alarm_disk_queue_threshold}"
dimensions {
DBInstanceIdentifier = "${aws_db_instance.postgresql.id}"
}
alarm_actions = ["${var.alarm_actions}"]
}
resource "aws_cloudwatch_metric_alarm" "database_disk_free" {
alarm_name = "alarm${var.environment}DatabaseServerFreeStorageSpace"
alarm_description = "Database server free storage space"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "FreeStorageSpace"
namespace = "AWS/RDS"
period = "60"
statistic = "Average"
threshold = "${var.alarm_free_disk_threshold}"
dimensions {
DBInstanceIdentifier = "${aws_db_instance.postgresql.id}"
}
alarm_actions = ["${var.alarm_actions}"]
}
resource "aws_cloudwatch_metric_alarm" "database_memory_free" {
alarm_name = "alarm${var.environment}DatabaseServerFreeableMemory"
alarm_description = "Database server freeable memory"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "FreeableMemory"
namespace = "AWS/RDS"
period = "60"
statistic = "Average"
threshold = "${var.alarm_free_memory_threshold}"
dimensions {
DBInstanceIdentifier = "${aws_db_instance.postgresql.id}"
}
alarm_actions = ["${var.alarm_actions}"]
}