-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
34 lines (29 loc) · 1.24 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
locals {
stack = var.stack != "" ? var.stack : var.environment
}
resource "random_password" "random_db_password" {
length = 30
special = true
override_special = "!#$%&_"
}
resource "random_id" "identifier" {
byte_length = 2
}
resource "random_id" "final_snapshot_id" {
byte_length = 4
}
resource "aws_db_instance" "db" {
identifier = replace("${local.stack}-${var.app_name}-${random_id.identifier.hex}", "_", "")
snapshot_identifier = var.snapshot_identifier
allocated_storage = var.snapshot_identifier != "" ? null : var.allocated_storage
storage_type = "gp2"
engine = var.snapshot_identifier != "" ? null : "${var.db_engine}"
engine_version = var.snapshot_identifier != "" ? null : "${var.db_engine_version}"
instance_class = "${var.db_instance_class}"
name = var.snapshot_identifier != "" ? null : "${var.db_name}"
username = var.snapshot_identifier != "" ? null : "${var.db_username}"
password = "${aws_ssm_parameter.password.value}"
vpc_security_group_ids = "${var.vpc_security_group_ids}"
db_subnet_group_name = "${var.subnet_group_name}"
final_snapshot_identifier = "A${random_id.final_snapshot_id.hex}"
}