forked from aws-ia/terraform-aws-rds-aurora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
608 lines (543 loc) · 23.9 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
###########
# Defaults
###########
provider "aws" {
alias = "primary"
region = var.region
}
provider "aws" {
alias = "secondary"
region = var.sec_region
}
#########################
# Collect data
#########################
data "aws_availability_zones" "region_p" {
state = "available"
provider = aws.primary
}
data "aws_availability_zones" "region_s" {
state = "available"
provider = aws.secondary
}
/*
data "aws_subnet_ids" "private" {
vpc_id = var.vpc_id
}
*/
data "aws_rds_engine_version" "family" {
engine = var.engine
version = var.engine == "aurora-postgresql" ? var.engine_version_pg : var.engine_version_mysql
provider = aws.primary
}
data "aws_iam_policy_document" "monitoring_rds_assume_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["monitoring.rds.amazonaws.com"]
}
}
}
data "aws_partition" "current" {}
#########################
# Create Unique password
#########################
resource "random_password" "master_password" {
length = 10
special = false
}
####################################
# Generate Final snapshot identifier
####################################
resource "random_id" "snapshot_id" {
keepers = {
id = var.identifier
}
byte_length = 4
}
###########
# DB Subnet
###########
resource "aws_db_subnet_group" "private_p" {
provider = aws.primary
name = "${var.name}-sg"
subnet_ids = var.private_subnet_ids_p
tags = {
Name = "My DB subnet group"
}
}
resource "aws_db_subnet_group" "private_s" {
provider = aws.secondary
count = var.setup_globaldb ? 1 : 0
name = "${var.name}-sg"
subnet_ids = var.private_subnet_ids_s
tags = {
Name = "My DB subnet group"
}
}
###########
# KMS
###########
resource "aws_kms_key" "kms_p" {
provider = aws.primary
count = var.storage_encrypted || (!var.setup_globaldb && var.manage_master_user_password) ? 1 : 0
description = "KMS key for Aurora Storage Encryption and master user Secrets Manager secret"
tags = var.tags
# following causes terraform destroy to fail. But this is needed so that Aurora encrypted snapshots can be restored for your production workload.
lifecycle {
prevent_destroy = true
}
}
resource "aws_kms_key" "kms_s" {
provider = aws.secondary
count = var.setup_globaldb && var.storage_encrypted ? 1 : 0
description = "KMS key for Aurora Storage Encryption"
tags = var.tags
# following causes terraform destroy to fail. But this is needed so that Aurora encrypted snapshots can be restored for your production workload.
lifecycle {
prevent_destroy = true
}
}
###########
# IAM
###########
resource "aws_iam_role" "rds_enhanced_monitoring" {
description = "IAM Role for RDS Enhanced monitoring"
path = "/"
assume_role_policy = data.aws_iam_policy_document.monitoring_rds_assume_role.json
managed_policy_arns = ["arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole"]
tags = var.tags
}
#############
# RDS Aurora
#############
# Aurora Global DB
resource "aws_rds_global_cluster" "globaldb" {
count = var.setup_globaldb ? 1 : 0
provider = aws.primary
global_cluster_identifier = "${var.identifier}-globaldb"
engine = (var.snapshot_identifier == "") ? var.engine : null
engine_version = (var.snapshot_identifier == "") ? (var.engine == "aurora-postgresql" ? var.engine_version_pg : var.engine_version_mysql) : null
database_name = (var.snapshot_identifier == "") ? var.database_name : null
storage_encrypted = var.storage_encrypted
# Uncomment the following line for restoring cluster from snapshot. Conditionally specifying null for the argument still creating Terraform Cycle error.
# source_db_cluster_identifier = (var.snapshot_identifier == "") ? null : aws_rds_cluster.primary.arn
force_destroy = (var.snapshot_identifier == "") ? null : true
lifecycle {
ignore_changes = [source_db_cluster_identifier]
}
}
resource "aws_rds_cluster" "primary" {
provider = aws.primary
# Comment the following line for restoring cluster from snapshot. Conditionally specifying null for the argument still creating Terraform Cycle error.
global_cluster_identifier = var.setup_globaldb && (var.snapshot_identifier == "") ? aws_rds_global_cluster.globaldb[0].id : null
cluster_identifier = "${var.identifier}-${var.region}"
engine = var.engine
engine_version = var.engine == "aurora-postgresql" ? var.engine_version_pg : var.engine_version_mysql
allow_major_version_upgrade = var.allow_major_version_upgrade
availability_zones = [data.aws_availability_zones.region_p.names[0], data.aws_availability_zones.region_p.names[1], data.aws_availability_zones.region_p.names[2]]
db_subnet_group_name = aws_db_subnet_group.private_p.name
port = var.port == "" ? var.engine == "aurora-postgresql" ? "5432" : "3306" : var.port
database_name = var.setup_as_secondary || (var.snapshot_identifier != "") ? null : var.database_name
# Aurora global DB currently doesn't support master password management with AWS Secrets Manager
manage_master_user_password = !var.setup_globaldb && var.manage_master_user_password ? var.manage_master_user_password : null
master_user_secret_kms_key_id = !var.setup_globaldb && var.manage_master_user_password ? aws_kms_key.kms_p[0].arn : null
master_username = var.setup_as_secondary || (var.snapshot_identifier != "") ? null : var.username
master_password = (var.setup_as_secondary || (var.snapshot_identifier != "")) || (!var.setup_globaldb && var.manage_master_user_password) ? null : (var.password == "" ? random_password.master_password.result : var.password)
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_parameter_group_p.id
db_instance_parameter_group_name = var.allow_major_version_upgrade ? aws_db_parameter_group.aurora_db_parameter_group_p.id : null
backup_retention_period = var.backup_retention_period
preferred_backup_window = var.preferred_backup_window
#tfsec:ignore:aws-rds-encrypt-cluster-storage-data
storage_encrypted = var.storage_encrypted
kms_key_id = var.storage_encrypted ? aws_kms_key.kms_p[0].arn : null
storage_type = var.storage_type
apply_immediately = true
skip_final_snapshot = var.skip_final_snapshot
final_snapshot_identifier = var.skip_final_snapshot ? null : "${var.final_snapshot_identifier_prefix}-${var.identifier}-${var.region}-${random_id.snapshot_id.hex}"
snapshot_identifier = var.snapshot_identifier != "" ? var.snapshot_identifier : null
enabled_cloudwatch_logs_exports = local.logs_set
tags = var.tags
dynamic "serverlessv2_scaling_configuration" {
for_each = var.instance_class == "db.serverless" ? [local.serverlessv2_scaling_configuration] : []
content {
max_capacity = serverlessv2_scaling_configuration.value.max_capacity
min_capacity = serverlessv2_scaling_configuration.value.min_capacity
}
}
depends_on = [
# When this Aurora cluster is setup as a secondary, setting up the dependency makes sure to delete this cluster 1st before deleting current primary Cluster during terraform destroy
# Comment out the following line if this cluster has changed role to be the primary Aurora cluster because of a failover for terraform destroy to work
# aws_rds_cluster_instance.secondary,
]
lifecycle {
ignore_changes = [
replication_source_identifier,
global_cluster_identifier,
snapshot_identifier,
# Since Terraform doesn't allow to conditionally specify a lifecycle policy, this can't be done dynamically.
# Uncomment the following line for Aurora Global Database to do major version upgrade as per https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_global_cluster
# engine_version,
]
}
}
#tfsec:ignore:aws-rds-enable-performance-insights-encryption tfsec:ignore:aws-rds-enable-performance-insights
resource "aws_rds_cluster_instance" "primary" {
count = var.primary_instance_count
provider = aws.primary
identifier = "${var.name}-${var.region}-${count.index + 1}"
cluster_identifier = aws_rds_cluster.primary.id
engine = aws_rds_cluster.primary.engine
engine_version = var.engine == "aurora-postgresql" ? var.engine_version_pg : var.engine_version_mysql
auto_minor_version_upgrade = var.setup_globaldb ? false : var.auto_minor_version_upgrade
instance_class = var.instance_class
db_subnet_group_name = aws_db_subnet_group.private_p.name
db_parameter_group_name = aws_db_parameter_group.aurora_db_parameter_group_p.id
performance_insights_enabled = true
monitoring_interval = var.monitoring_interval
monitoring_role_arn = aws_iam_role.rds_enhanced_monitoring.arn
apply_immediately = true
tags = var.tags
}
# Secondary Aurora Cluster
resource "aws_rds_cluster" "secondary" {
count = var.setup_globaldb ? 1 : 0
provider = aws.secondary
global_cluster_identifier = aws_rds_global_cluster.globaldb[0].id
cluster_identifier = "${var.identifier}-${var.sec_region}"
engine = var.engine
engine_version = var.engine == "aurora-postgresql" ? var.engine_version_pg : var.engine_version_mysql
allow_major_version_upgrade = var.allow_major_version_upgrade
availability_zones = [data.aws_availability_zones.region_s.names[0], data.aws_availability_zones.region_s.names[1], data.aws_availability_zones.region_s.names[2]]
db_subnet_group_name = aws_db_subnet_group.private_s[0].name
port = var.port == "" ? var.engine == "aurora-postgresql" ? "5432" : "3306" : var.port
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.aurora_cluster_parameter_group_s[0].id
db_instance_parameter_group_name = var.allow_major_version_upgrade ? aws_db_parameter_group.aurora_db_parameter_group_s[0].id : null
backup_retention_period = var.backup_retention_period
preferred_backup_window = var.preferred_backup_window
source_region = var.storage_encrypted ? var.region : null
kms_key_id = var.storage_encrypted ? aws_kms_key.kms_s[0].arn : null
storage_type = var.storage_type
apply_immediately = true
skip_final_snapshot = var.skip_final_snapshot
final_snapshot_identifier = var.skip_final_snapshot ? null : "${var.final_snapshot_identifier_prefix}-${var.identifier}-${var.sec_region}-${random_id.snapshot_id.hex}"
enabled_cloudwatch_logs_exports = local.logs_set
tags = var.tags
dynamic "serverlessv2_scaling_configuration" {
for_each = var.instance_class == "db.serverless" ? [local.serverlessv2_scaling_configuration] : []
content {
max_capacity = serverlessv2_scaling_configuration.value.max_capacity
min_capacity = serverlessv2_scaling_configuration.value.min_capacity
}
}
depends_on = [
# When this Aurora cluster is setup as a secondary, setting up the dependency makes sure to delete this cluster 1st before deleting current primary Cluster during terraform destroy
# Comment out the following line if this cluster has changed role to be the primary Aurora cluster because of a failover for terraform destroy to work
aws_rds_cluster_instance.primary,
]
lifecycle {
ignore_changes = [
replication_source_identifier,
global_cluster_identifier,
# Since Terraform doesn't allow to conditionally specify a lifecycle policy, this can't be done dynamically.
# Uncomment the following line for Aurora Global Database to do major version upgrade as per https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_global_cluster
# engine_version,
]
}
}
# Secondary Cluster Instances
#tfsec:ignore:aws-rds-enable-performance-insights-encryption tfsec:ignore:aws-rds-enable-performance-insights
resource "aws_rds_cluster_instance" "secondary" {
count = var.setup_globaldb ? var.secondary_instance_count : 0
provider = aws.secondary
identifier = "${var.name}-${var.sec_region}-${count.index + 1}"
cluster_identifier = aws_rds_cluster.secondary[0].id
engine = var.engine
engine_version = var.engine == "aurora-postgresql" ? var.engine_version_pg : var.engine_version_mysql
auto_minor_version_upgrade = false
instance_class = var.instance_class
db_subnet_group_name = aws_db_subnet_group.private_s[0].name
db_parameter_group_name = aws_db_parameter_group.aurora_db_parameter_group_s[0].id
performance_insights_enabled = true
monitoring_interval = var.monitoring_interval
monitoring_role_arn = aws_iam_role.rds_enhanced_monitoring.arn
apply_immediately = true
tags = var.tags
}
#############################
# RDS Aurora Parameter Groups
##############################
resource "aws_rds_cluster_parameter_group" "aurora_cluster_parameter_group_p" {
provider = aws.primary
name_prefix = "${var.name}-cluster-"
family = data.aws_rds_engine_version.family.parameter_group_family
description = "aurora-cluster-parameter-group"
dynamic "parameter" {
for_each = var.engine == "aurora-postgresql" ? local.apg_cluster_pgroup_params : local.mysql_cluster_pgroup_params
iterator = pblock
content {
name = pblock.value.name
value = pblock.value.value
apply_method = pblock.value.apply_method
}
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_db_parameter_group" "aurora_db_parameter_group_p" {
provider = aws.primary
name_prefix = "${var.name}-db-"
family = data.aws_rds_engine_version.family.parameter_group_family
description = "aurora-db-parameter-group"
dynamic "parameter" {
for_each = var.engine == "aurora-postgresql" ? local.apg_db_pgroup_params : local.mysql_db_pgroup_params
iterator = pblock
content {
name = pblock.value.name
value = pblock.value.value
apply_method = pblock.value.apply_method
}
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_rds_cluster_parameter_group" "aurora_cluster_parameter_group_s" {
count = var.setup_globaldb ? 1 : 0
provider = aws.secondary
name_prefix = "${var.name}-cluster-"
family = data.aws_rds_engine_version.family.parameter_group_family
description = "aurora-cluster-parameter-group"
dynamic "parameter" {
for_each = var.engine == "aurora-postgresql" ? local.apg_cluster_pgroup_params : local.mysql_cluster_pgroup_params
iterator = pblock
content {
name = pblock.value.name
value = pblock.value.value
apply_method = pblock.value.apply_method
}
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_db_parameter_group" "aurora_db_parameter_group_s" {
count = var.setup_globaldb ? 1 : 0
provider = aws.secondary
name_prefix = "${var.name}-db-"
family = data.aws_rds_engine_version.family.parameter_group_family
description = "aurora-db-parameter-group"
dynamic "parameter" {
for_each = var.engine == "aurora-postgresql" ? local.apg_db_pgroup_params : local.mysql_db_pgroup_params
iterator = pblock
content {
name = pblock.value.name
value = pblock.value.value
apply_method = pblock.value.apply_method
}
}
lifecycle {
create_before_destroy = true
}
}
#############################
# Monitoring
##############################
#tfsec:ignore:aws-sns-enable-topic-encryption
resource "aws_sns_topic" "default_p" {
provider = aws.primary
name = "rds-events"
}
resource "aws_db_event_subscription" "default_p" {
provider = aws.primary
name = "${var.name}-rds-event-sub"
sns_topic = aws_sns_topic.default_p.arn
source_type = "db-cluster"
source_ids = [aws_rds_cluster.primary.id]
event_categories = [
"creation",
"deletion",
"failover",
"failure",
"maintenance",
"notification",
]
}
#tfsec:ignore:aws-sns-enable-topic-encryption
resource "aws_sns_topic" "default_s" {
count = var.setup_globaldb ? 1 : 0
provider = aws.secondary
name = "rds-events"
}
resource "aws_db_event_subscription" "default_s" {
count = var.setup_globaldb ? 1 : 0
provider = aws.secondary
name = "${var.name}-rds-event-sub"
sns_topic = aws_sns_topic.default_s[0].arn
source_type = "db-cluster"
source_ids = [aws_rds_cluster.secondary[0].id]
event_categories = [
"creation",
"deletion",
"failover",
"failure",
"maintenance",
"notification",
]
}
resource "aws_cloudwatch_metric_alarm" "cpu_util_p" {
count = var.primary_instance_count
provider = aws.primary
alarm_name = "CPU_Util-${element(split(",", join(",", aws_rds_cluster_instance.primary[*].id)), count.index)}"
alarm_description = "This metric monitors Aurora Instance CPU Utilization"
metric_name = "CPUUtilization"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
treat_missing_data = "notBreaching"
period = "60"
threshold = "80"
statistic = "Maximum"
unit = "Percent"
alarm_actions = [aws_sns_topic.default_p.arn]
namespace = "AWS/RDS"
dimensions = {
DBInstanceIdentifier = element(aws_rds_cluster_instance.primary[*].id, count.index)
}
}
resource "aws_cloudwatch_metric_alarm" "free_local_storage_p" {
count = var.primary_instance_count
provider = aws.primary
alarm_name = "Free_local_storage-${element(split(",", join(",", aws_rds_cluster_instance.primary[*].id)), count.index)}"
alarm_description = "This metric monitors Aurora Local Storage Utilization"
metric_name = "FreeLocalStorage"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "5"
treat_missing_data = "notBreaching"
period = "60"
threshold = "5368709120"
statistic = "Average"
unit = "Bytes"
alarm_actions = [aws_sns_topic.default_p.arn]
namespace = "AWS/RDS"
dimensions = {
DBInstanceIdentifier = element(aws_rds_cluster_instance.primary[*].id, count.index)
}
}
resource "aws_cloudwatch_metric_alarm" "free_random_access_memory_p" {
count = var.primary_instance_count
provider = aws.primary
alarm_name = "FreeableMemory-${element(split(",", join(",", aws_rds_cluster_instance.primary[*].id)), count.index)}"
alarm_description = "This metric monitors Aurora Instance Random Access Memory Utilization"
metric_name = "FreeableMemory"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "5"
treat_missing_data = "notBreaching"
period = "60"
threshold = "2147483648"
statistic = "Average"
unit = "Bytes"
alarm_actions = [aws_sns_topic.default_p.arn]
namespace = "AWS/RDS"
dimensions = {
DBInstanceIdentifier = element(aws_rds_cluster_instance.primary[*].id, count.index)
}
}
resource "aws_cloudwatch_metric_alarm" "pg_max_used_tx_ids_p" {
count = var.engine == "aurora-postgresql" ? 1 : 0
provider = aws.primary
alarm_name = "PG_MaxUsedTxIDs-${aws_rds_cluster.primary.id}"
alarm_description = "This metric monitors Aurora PostgreSQL Max Used Tx IDs"
metric_name = "MaximumUsedTransactionIDs"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
treat_missing_data = "notBreaching"
period = "60"
threshold = "600000000"
statistic = "Average"
unit = "Count"
alarm_actions = [aws_sns_topic.default_p.arn]
namespace = "AWS/RDS"
dimensions = {
DBClusterIdentifier = aws_rds_cluster.primary.id
Role = "WRITER"
}
}
resource "aws_cloudwatch_metric_alarm" "cpu_util_s" {
count = var.setup_globaldb ? var.secondary_instance_count : 0
provider = aws.secondary
alarm_name = "CPU_Util-${element(split(",", join(",", aws_rds_cluster_instance.secondary[*].id)), count.index)}"
alarm_description = "This metric monitors Aurora Instance CPU Utilization"
metric_name = "CPUUtilization"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
treat_missing_data = "notBreaching"
period = "60"
threshold = "80"
statistic = "Maximum"
unit = "Percent"
alarm_actions = [aws_sns_topic.default_s[0].arn]
namespace = "AWS/RDS"
dimensions = {
DBInstanceIdentifier = element(aws_rds_cluster_instance.secondary[*].id, count.index)
}
}
resource "aws_cloudwatch_metric_alarm" "free_local_storage_s" {
count = var.setup_globaldb ? var.secondary_instance_count : 0
provider = aws.secondary
alarm_name = "Free_local_storage-${element(split(",", join(",", aws_rds_cluster_instance.secondary[*].id)), count.index)}"
alarm_description = "This metric monitors Aurora Local Storage Utilization"
metric_name = "FreeLocalStorage"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "5"
treat_missing_data = "notBreaching"
period = "60"
threshold = "5368709120"
statistic = "Average"
unit = "Bytes"
alarm_actions = [aws_sns_topic.default_s[0].arn]
namespace = "AWS/RDS"
dimensions = {
DBInstanceIdentifier = element(aws_rds_cluster_instance.secondary[*].id, count.index)
}
}
resource "aws_cloudwatch_metric_alarm" "free_random_access_memory_s" {
count = var.setup_globaldb ? var.secondary_instance_count : 0
provider = aws.secondary
alarm_name = "FreeableMemory-${element(split(",", join(",", aws_rds_cluster_instance.secondary[*].id)), count.index)}"
alarm_description = "This metric monitors Aurora Instance Random Access Memory Utilization"
metric_name = "FreeableMemory"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "5"
treat_missing_data = "notBreaching"
period = "60"
threshold = "2147483648"
statistic = "Average"
unit = "Bytes"
alarm_actions = [aws_sns_topic.default_s[0].arn]
namespace = "AWS/RDS"
dimensions = {
DBInstanceIdentifier = element(aws_rds_cluster_instance.secondary[*].id, count.index)
}
}
resource "aws_cloudwatch_metric_alarm" "pg_max_used_tx_ids_s" {
count = (var.engine == "aurora-postgresql") && var.setup_globaldb ? 1 : 0
provider = aws.secondary
alarm_name = "PG_MaxUsedTxIDs-${aws_rds_cluster.secondary[0].id}"
alarm_description = "This metric monitors Aurora PostgreSQL Max Used Tx IDs"
metric_name = "MaximumUsedTransactionIDs"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
treat_missing_data = "notBreaching"
period = "60"
threshold = "600000000"
statistic = "Average"
unit = "Count"
alarm_actions = [aws_sns_topic.default_s[0].arn]
namespace = "AWS/RDS"
dimensions = {
DBClusterIdentifier = aws_rds_cluster.secondary[0].id
Role = "WRITER"
}
}