Skip to content

Commit 50abed3

Browse files
smiller171Scott Miller
authored andcommitted
Merge pull request #1 from rhythmictech:postgres
allow using any rds engine
2 parents abcc77b + 86621c8 commit 50abed3

File tree

7 files changed

+121
-108
lines changed

7 files changed

+121
-108
lines changed

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"terraform.indexing": {
3+
"enabled": false,
4+
"liveIndexing": false,
5+
"exclude": [
6+
"**/*"
7+
]
8+
}
9+
}

instance.tf

Lines changed: 0 additions & 36 deletions
This file was deleted.

main.tf

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
resource "aws_db_instance" "this" {
2+
allocated_storage = var.storage
3+
backup_retention_period = var.backup_retention_period
4+
copy_tags_to_snapshot = true
5+
db_subnet_group_name = aws_db_subnet_group.mysql.id
6+
deletion_protection = true
7+
engine = var.engine
8+
engine_version = var.engine_version
9+
iam_database_authentication_enabled = true
10+
instance_class = var.instance_class
11+
multi_az = var.multi_az
12+
password = random_string.password.result
13+
port = var.port
14+
storage_encrypted = true
15+
storage_type = var.storage_type
16+
final_snapshot_identifier = "${var.name}-final-snapshot"
17+
skip_final_snapshot = var.skip_final_snapshot
18+
username = var.username
19+
vpc_security_group_ids = [aws_security_group.mysql.id]
20+
21+
enabled_cloudwatch_logs_exports = [
22+
"audit",
23+
"error",
24+
"general",
25+
"slowquery",
26+
]
27+
28+
tags = merge(
29+
local.base_tags,
30+
var.tags,
31+
{
32+
"Name" = "${var.name}-mysql-db"
33+
},
34+
)
35+
}
36+
37+
resource "aws_db_subnet_group" "this" {
38+
subnet_ids = var.subnet_ids
39+
40+
tags = merge(
41+
local.base_tags,
42+
var.tags,
43+
{
44+
"Name" = "${var.name}-subnet-group"
45+
},
46+
)
47+
}
48+
49+
resource "aws_security_group" "this" {
50+
vpc_id = var.vpc_id
51+
52+
ingress {
53+
from_port = var.port
54+
to_port = var.port
55+
protocol = "tcp"
56+
security_groups = var.allowed_security_groups
57+
cidr_blocks = var.allowed_cidr_blocks
58+
ipv6_cidr_blocks = var.allowed_ipv6_cidr_blocks
59+
}
60+
61+
tags = merge(
62+
local.base_tags,
63+
var.tags,
64+
{
65+
"Name" = "${var.name}-security-group"
66+
},
67+
)
68+
}
69+
70+
resource "random_string" "password" {
71+
length = 40
72+
special = true
73+
min_special = 5
74+
override_special = "!#$%^&*()-_=+[]{}<>:?"
75+
76+
keepers = {
77+
pass_version = var.pass_version
78+
}
79+
}
80+
81+
resource "aws_secretsmanager_secret" "password" {
82+
description = "MySQL database password"
83+
84+
tags = merge(
85+
local.base_tags,
86+
var.tags,
87+
{
88+
"Name" = "${var.name}-mysql-pass-secret"
89+
},
90+
)
91+
}
92+
93+
resource "aws_secretsmanager_secret_version" "password_val" {
94+
secret_id = aws_secretsmanager_secret.mysql-pass.id
95+
secret_string = random_string.password.result
96+
}

networking.tf

Lines changed: 0 additions & 33 deletions
This file was deleted.

outputs.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
output "password-arn" {
2-
value = aws_secretsmanager_secret.mysql-pass.arn
2+
value = aws_secretsmanager_secret.password.arn
33
}
44

55
output "password-version" {
6-
value = aws_secretsmanager_secret_version.password-val.version_id
6+
value = aws_secretsmanager_secret_version.password_val.version_id
77
}
88

99
output "instance" {
1010
value = {
11-
id = aws_db_instance.mysql.id
12-
username = aws_db_instance.mysql.username
13-
address = aws_db_instance.mysql.address
11+
id = aws_db_instance.this.id
12+
username = aws_db_instance.this.username
13+
address = aws_db_instance.this.address
1414
}
1515
}
1616

1717
output "instance-id" {
18-
value = aws_db_instance.mysql.id
18+
value = aws_db_instance.this.id
1919
}
2020

2121
output "username" {
22-
value = aws_db_instance.mysql.username
22+
value = aws_db_instance.this.username
2323
}
2424

2525
output "address" {
26-
value = aws_db_instance.mysql.address
26+
value = aws_db_instance.this.address
2727
}
2828

password.tf

Lines changed: 0 additions & 28 deletions
This file was deleted.

variables.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ variable "storage_type" {
5656
default = "gp2"
5757
}
5858

59-
variable "mysql_version" {
60-
description = "Version of MySQL to use"
59+
variable "engine" {
60+
description = "Which RDS Engine to use"
61+
type = "string"
62+
default = "mysql"
63+
}
64+
65+
variable "engine_version" {
66+
description = "Version of database engine to use"
6167
type = string
6268
default = "5.6"
6369
}
@@ -103,4 +109,3 @@ variable "pass_version" {
103109
type = string
104110
default = 1
105111
}
106-

0 commit comments

Comments
 (0)