Last active
October 3, 2023 16:49
-
-
Save smiller171/6be734957e30c5d4e4b15422634f13f4 to your computer and use it in GitHub Desktop.
Manage RDS password in Terraform in a sane way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "random_password" "db_master_pass" { | |
length = 40 | |
special = true | |
min_special = 5 | |
override_special = "!#$%^&*()-_=+[]{}<>:?" | |
keepers = { | |
pass_version = 1 | |
} | |
} | |
resource "aws_db_instance" "mysql_db" { | |
username = "mysql_user" | |
password = random_password.db_master_pass.result | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_secretsmanager_secret" "db-pass" { | |
name = "db-pass-${terraform.workspace}" | |
} | |
resource "aws_secretsmanager_secret_version" "db-pass-val" { | |
secret_id = aws_secretsmanager_secret.db-pass.id | |
secret_string = random_password.db_master_pass.result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just when I think I'm right about something, I get shown something far more clever than I could've imagined 😂