This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrds.tf
70 lines (62 loc) · 1.78 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
# SG
resource "aws_security_group" "sg_db" {
name = "elon-kiosk-db-sg"
description = "DB Security Group"
vpc_id = aws_vpc.vpc_main.id
tags = {
Name = "elon-kiosk-db-sg"
}
}
## SG Rules
### Ingress
resource "aws_security_group_rule" "sg_db_rule_ing_conn" {
type = "ingress"
from_port = var.DB_PORT
to_port = var.DB_PORT
protocol = "TCP"
source_security_group_id = aws_security_group.sg_apiserver.id
security_group_id = aws_security_group.sg_db.id
lifecycle {
create_before_destroy = true
}
}
### Egress
resource "aws_security_group_rule" "sg_db_rule_eg_all" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.sg_db.id
lifecycle {
create_before_destroy = true
}
}
# Subnet group
resource "aws_db_subnet_group" "subnet_group_db" {
name = "elon-kiosk-subnet-group-db"
subnet_ids = [
aws_subnet.priv_subnet_az1_db.id,
aws_subnet.priv_subnet_az2_db.id
]
tags = {
Name = "elon-kiosk-subnet-group-db"
}
}
# RDS instance
resource "aws_db_instance" "db_main" {
allocated_storage = 20
max_allocated_storage = 50
availability_zone = "ap-northeast-2a"
db_subnet_group_name = aws_db_subnet_group.subnet_group_db.name
engine = "mysql"
engine_version = "8.0.30"
instance_class = "db.t3.micro"
skip_final_snapshot = true
identifier = "elon-kiosk-db"
username = var.DB_USERNAME
password = var.DB_PASSWORD
db_name = var.DB_NAME
port = var.DB_PORT
vpc_security_group_ids = [aws_security_group.sg_db.id]
}