forked from hyprnz/terraform-aws-data-storage-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rds.tf
85 lines (73 loc) · 2.96 KB
/
rds.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
locals {
username = length(var.rds_username) > 0 ? format("%suser", var.rds_username) : format("%suser", var.rds_database_name)
}
resource "aws_db_instance" "this" {
count = var.enable_datastore && var.create_rds_instance && (! var.use_rds_snapshot) ? 1 : 0
name = var.rds_database_name
identifier = var.rds_identifier
engine = var.rds_engine
engine_version = var.rds_engine_version
instance_class = var.rds_instance_class
username = local.username
password = var.rds_password
db_subnet_group_name = var.rds_subnet_group
vpc_security_group_ids = var.rds_security_group_ids
allocated_storage = var.rds_allocated_storage
max_allocated_storage = var.rds_max_allocated_storage
backup_retention_period = var.backup_retention_period
iops = var.rds_iops
monitoring_interval = var.rds_monitoring_interval
monitoring_role_arn = var.rds_monitoring_role_arn
performance_insights_enabled = var.rds_enable_performance_insights
backup_window = var.rds_backup_window
skip_final_snapshot = var.rds_skip_final_snapshot
storage_encrypted = var.rds_storage_encrypted
kms_key_id = var.rds_storage_encryption_kms_key_arn
tags = merge(
{
"rds_engine" = var.rds_engine
},
var.tags,
var.rds_tags,
)
}
data "aws_db_snapshot" "latest_snapshot" {
count = var.use_rds_snapshot ? 1 : 0
db_instance_identifier = var.rds_identifier
most_recent = true
}
resource "aws_db_instance" "snapshot" {
count = var.enable_datastore && var.use_rds_snapshot && (! var.create_rds_instance) ? 1 : 0
name = var.rds_database_name
identifier = var.rds_identifier
engine = var.rds_engine
engine_version = var.rds_engine_version
instance_class = var.rds_instance_class
username = local.username
password = var.rds_password
snapshot_identifier = data.aws_db_snapshot.latest_snapshot[0].id
option_group_name = var.rds_option_group_name
db_subnet_group_name = var.rds_subnet_group
vpc_security_group_ids = var.rds_security_group_ids
allocated_storage = var.rds_allocated_storage
max_allocated_storage = var.rds_max_allocated_storage
backup_retention_period = var.backup_retention_period
iops = var.rds_iops
monitoring_interval = var.rds_monitoring_interval
monitoring_role_arn = var.rds_monitoring_role_arn
performance_insights_enabled = var.rds_enable_performance_insights
backup_window = var.rds_backup_window
skip_final_snapshot = var.rds_skip_final_snapshot
storage_encrypted = var.rds_storage_encrypted
kms_key_id = var.rds_storage_encryption_kms_key_arn
tags = merge(
{
"rds_engine" = var.rds_engine
},
var.tags,
var.rds_tags,
)
lifecycle {
ignore_changes = [snapshot_identifier]
}
}