-
Notifications
You must be signed in to change notification settings - Fork 8
/
rds.tf
78 lines (71 loc) · 2.38 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
locals {
aurora_engine = "aurora-mysql"
aurora_engine_version = "5.7.mysql_aurora.2.08.1"
}
resource "random_password" "mysql_password" {
length = 10
special = false
}
resource "aws_db_subnet_group" "k3s" {
name = "${var.prefix}k3s"
subnet_ids = var.inst_subnet_ids
tags = var.tags
}
resource "aws_db_instance" "k3s" {
count = var.use_aurora_db ? 0 : 1
allocated_storage = 20
storage_type = "gp2"
engine = "mysql"
engine_version = "5.7.38"
db_subnet_group_name = aws_db_subnet_group.k3s.id
instance_class = var.rds_inst_type
name = "${var.prefix}k3s"
identifier = "${var.prefix}k3s"
username = var.rds_username
password = random_password.mysql_password.result
parameter_group_name = "default.mysql5.7"
vpc_security_group_ids = [ aws_security_group.k3s_mysql.id]
skip_final_snapshot = true
tags = var.tags
}
resource "aws_rds_cluster" "k3s" {
count = var.use_aurora_db ? 1 : 0
cluster_identifier = "${var.prefix}k3s"
engine = local.aurora_engine
engine_version = local.aurora_engine_version
db_subnet_group_name = aws_db_subnet_group.k3s.id
database_name = "${var.prefix}k3s"
master_username = var.rds_username
master_password = random_password.mysql_password.result
vpc_security_group_ids = [ aws_security_group.k3s_mysql.id]
skip_final_snapshot = true
tags = var.tags
}
resource "aws_rds_cluster_instance" "k3s" {
count = var.use_aurora_db ? var.num_rds_instances : 0
identifier = "${var.prefix}k3s-${count.index}"
engine = local.aurora_engine
engine_version = local.aurora_engine_version
db_subnet_group_name = aws_db_subnet_group.k3s.id
cluster_identifier = aws_rds_cluster.k3s[0].id
instance_class = var.rds_inst_type
db_parameter_group_name = "default.aurora-mysql5.7"
}
resource "aws_security_group" "k3s_mysql" {
name = "${var.prefix}-k3sRDS"
description = "k3s rds mysql access"
vpc_id = var.vpc_id
ingress {
description = "MYSQL"
from_port = 3306
to_port = 3306
protocol = "tcp"
security_groups = [aws_security_group.master.id]
}
tags = merge(
{
Name = "${var.prefix}-k3sRDS"
},
var.tags,
)
}