generated from DNXLabs/terraform-aws-template
-
Notifications
You must be signed in to change notification settings - Fork 9
/
aurora.tf
75 lines (66 loc) · 3.24 KB
/
aurora.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
resource "aws_rds_cluster" "aurora_cluster" {
count = var.db_type == "aurora" ? 1 : 0
cluster_identifier = var.identifier == "" ? "${var.environment_name}-${var.name}" : var.identifier
engine = var.engine
engine_version = var.engine_version
database_name = var.database_name
master_username = var.user
master_password = random_string.rds_db_password.result
backup_retention_period = var.retention
preferred_backup_window = var.preferred_backup_window
preferred_maintenance_window = var.preferred_maintenance_window
snapshot_identifier = var.snapshot_identifier != "" ? var.snapshot_identifier : null
db_subnet_group_name = try(aws_db_subnet_group.rds_subnet_group[0].id, var.db_subnet_group_id)
iam_database_authentication_enabled = var.iam_database_authentication_enabled
vpc_security_group_ids = [aws_security_group.rds_db.id]
db_cluster_parameter_group_name = var.create_cluster_parameter_group == true ? aws_rds_cluster_parameter_group.custom_cluster_pg[count.index].name : ""
apply_immediately = var.apply_immediately
storage_encrypted = var.storage_encrypted
kms_key_id = var.kms_key_arn
}
resource "aws_rds_cluster_instance" "cluster_instances" {
count = var.db_type == "aurora" ? var.count_aurora_instances : 0
identifier = var.identifier == "" ? "${var.environment_name}-${var.name}-${count.index}" : "${var.identifier}-${count.index}"
cluster_identifier = aws_rds_cluster.aurora_cluster[0].id
instance_class = var.instance_class
engine = aws_rds_cluster.aurora_cluster[0].engine
engine_version = aws_rds_cluster.aurora_cluster[0].engine_version
db_parameter_group_name = var.create_db_parameter_group == true ? aws_db_parameter_group.aurora_custom_db_pg[count.index].name : ""
publicly_accessible = var.publicly_accessible
}
resource "aws_rds_cluster_parameter_group" "custom_cluster_pg" {
count = var.db_type == "aurora" && var.create_cluster_parameter_group ? 1 : 0
name = var.parameter_group_name
#name_prefix = local.name_prefix
description = var.parameter_group_description
family = var.family
dynamic "parameter" {
for_each = var.cluster_parameters
content {
name = parameter.value.name
value = parameter.value.value
apply_method = lookup(parameter.value, "apply_method", null)
}
}
}
resource "aws_db_parameter_group" "aurora_custom_db_pg" {
count = var.db_type == "aurora" && var.create_db_parameter_group ? 1 : 0
#name = var.parameter_group_name
name_prefix = var.parameter_group_name
description = var.parameter_group_description
family = var.family
dynamic "parameter" {
for_each = var.db_parameters
content {
name = parameter.value.name
value = parameter.value.value
apply_method = lookup(parameter.value, "apply_method", null)
}
}
tags = {
"Name" = var.parameter_group_name
}
lifecycle {
create_before_destroy = true
}
}