The resource random_string generates a random permutation of alphanumeric characters and optionally special characters.
# Generate Password in case random_string
resource "random_string" "random" {
length = 12
special = true
override_special = "/@£$"
}
# Save Password in SSM Parameter Store
resource "aws_ssm_parameter" "random" {
name = "project01"
type = "SecureString"
value = random_string.random.result
}
# Get Password from SSM Parameter Store
data "aws_ssm_parameter" "my_rds_password" {
name = "project01"
depends_on = [aws_ssm_parameter.random]
}
Identical to random_string with the exception that the result is treated as sensitive and, thus, not displayed in console output.
# Generate Password in case random_password
resource "random_password" "password" {
length = 16
special = true
override_special = "_%@"
}
resource "aws_db_instance" "example" {
instance_class = "db.t3.micro"
allocated_storage = 64
engine = "mysql"
username = "someone"
password = random_password.password.result
}
Link: https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string