-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
63 lines (55 loc) · 1.85 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
# ------------------------------------------------------------------------------
# security group constraining access to RDS instance
# ------------------------------------------------------------------------------
resource "aws_security_group" "rds" {
vpc_id = aws_vpc.rds.id
name_prefix = var.project_name
description = "allow TSQL"
tags = merge(
{
"Name" = "${var.project_name}-tsql"
},
var.tags,
)
ingress {
from_port = var.db_port
to_port = var.db_port
protocol = "tcp"
cidr_blocks = concat(var.access_cidr, [var.vpc_cidr])
}
}
resource "aws_db_subnet_group" "rds" {
name_prefix = var.project_name
subnet_ids = aws_subnet.rds.*.id
description = "RDS Subnets"
tags = var.tags
}
resource "aws_db_instance" "rds" {
depends_on = [aws_db_subnet_group.rds]
identifier_prefix = var.project_name
license_model = var.rds_properties["license_model"]
storage_type = var.rds_properties["storage_type"]
engine = var.rds_properties["engine"]
engine_version = var.rds_properties["engine_version"]
instance_class = var.rds_properties["instance_class"]
username = var.db_user
password = var.db_password
port = var.db_port
allocated_storage = 20
max_allocated_storage = 100
backup_retention_period = 3
multi_az = false
skip_final_snapshot = true
allow_major_version_upgrade = false
apply_immediately = true
copy_tags_to_snapshot = true
publicly_accessible = true
vpc_security_group_ids = [aws_security_group.rds.id]
db_subnet_group_name = aws_db_subnet_group.rds.id
tags = merge(
{
"Name" = var.project_name
},
var.tags,
)
}