Skip to content

Commit 48ff4f4

Browse files
committed
remove mysql references and make password more secure
1 parent 50abed3 commit 48ff4f4

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

main.tf

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1+
terraform {
2+
required_providers {
3+
random = ">= 2.2.0"
4+
}
5+
}
6+
17
resource "aws_db_instance" "this" {
28
allocated_storage = var.storage
39
backup_retention_period = var.backup_retention_period
410
copy_tags_to_snapshot = true
5-
db_subnet_group_name = aws_db_subnet_group.mysql.id
11+
db_subnet_group_name = aws_db_subnet_group.this.id
612
deletion_protection = true
713
engine = var.engine
814
engine_version = var.engine_version
915
iam_database_authentication_enabled = true
1016
instance_class = var.instance_class
1117
multi_az = var.multi_az
12-
password = random_string.password.result
18+
password = random_password.password.result
1319
port = var.port
1420
storage_encrypted = true
1521
storage_type = var.storage_type
1622
final_snapshot_identifier = "${var.name}-final-snapshot"
1723
skip_final_snapshot = var.skip_final_snapshot
1824
username = var.username
19-
vpc_security_group_ids = [aws_security_group.mysql.id]
25+
vpc_security_group_ids = [aws_security_group.this.id]
2026

2127
enabled_cloudwatch_logs_exports = [
2228
"audit",
@@ -29,7 +35,7 @@ resource "aws_db_instance" "this" {
2935
local.base_tags,
3036
var.tags,
3137
{
32-
"Name" = "${var.name}-mysql-db"
38+
"Name" = "${var.name}-postgres-db"
3339
},
3440
)
3541
}
@@ -67,7 +73,7 @@ resource "aws_security_group" "this" {
6773
)
6874
}
6975

70-
resource "random_string" "password" {
76+
resource "random_password" "password" {
7177
length = 40
7278
special = true
7379
min_special = 5
@@ -79,18 +85,19 @@ resource "random_string" "password" {
7985
}
8086

8187
resource "aws_secretsmanager_secret" "password" {
82-
description = "MySQL database password"
88+
name_prefix = var.name
89+
description = "${var.name} database password"
8390

8491
tags = merge(
8592
local.base_tags,
8693
var.tags,
8794
{
88-
"Name" = "${var.name}-mysql-pass-secret"
95+
"Name" = "${var.name}-pass-secret"
8996
},
9097
)
9198
}
9299

93100
resource "aws_secretsmanager_secret_version" "password_val" {
94-
secret_id = aws_secretsmanager_secret.mysql-pass.id
95-
secret_string = random_string.password.result
101+
secret_id = aws_secretsmanager_secret.password.id
102+
secret_string = random_password.password.result
96103
}

variables.tf

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
locals {
2-
base_tags = {
3-
tf_module = "rds"
4-
}
5-
}
6-
71
variable "name" {
82
description = "common name for resources in this module"
93
type = string
10-
default = "mysql-rds"
4+
default = "postgres-rds"
115
}
126

137
variable "tags" {
@@ -59,13 +53,13 @@ variable "storage_type" {
5953
variable "engine" {
6054
description = "Which RDS Engine to use"
6155
type = "string"
62-
default = "mysql"
56+
default = "postgres"
6357
}
6458

6559
variable "engine_version" {
6660
description = "Version of database engine to use"
6761
type = string
68-
default = "5.6"
62+
default = "11.5"
6963
}
7064

7165
variable "instance_class" {
@@ -83,7 +77,7 @@ variable "multi_az" {
8377
variable "username" {
8478
description = "username of master user"
8579
type = string
86-
default = "mysql_user"
80+
default = "postgres_user"
8781
}
8882

8983
variable "backup_retention_period" {
@@ -95,7 +89,7 @@ variable "backup_retention_period" {
9589
variable "port" {
9690
description = "Port the database should listen on"
9791
type = string
98-
default = "3306"
92+
default = "5432"
9993
}
10094

10195
variable "skip_final_snapshot" {

0 commit comments

Comments
 (0)