AWS Secrets Manager Terraform module
Terraform module which creates AWS Secrets Manager resources.
Usage
See examples directory for working examples to reference:
Standard
module "secrets_manager" {
source = "terraform-aws-modules/secrets-manager/aws"
# Secret
name_prefix = "example"
description = "Example Secrets Manager secret"
recovery_window_in_days = 30
# Policy
create_policy = true
block_public_policy = true
policy_statements = {
read = {
sid = "AllowAccountRead"
principals = [{
type = "AWS"
identifiers = ["arn:aws:iam::1234567890:root"]
}]
actions = ["secretsmanager:GetSecretValue"]
resources = ["*"]
}
}
# Version
create_random_password = true
random_password_length = 64
random_password_override_special = "!@#$%^&*()_+"
tags = {
Environment = "Development"
Project = "Example"
}
}
w/ Rotation
module "secrets_manager" {
source = "terraform-aws-modules/secrets-manager/aws"
# Secret
name_prefix = "rotated-example"
description = "Rotated example Secrets Manager secret"
recovery_window_in_days = 7
# Policy
create_policy = true
block_public_policy = true
policy_statements = {
lambda = {
sid = "LambdaReadWrite"
principals = [{
type = "AWS"
identifiers = ["arn:aws:iam:1234567890:role/lambda-function"]
}]
actions = [
"secretsmanager:DescribeSecret",
"secretsmanager:GetSecretValue",
"secretsmanager:PutSecretValue",
"secretsmanager:UpdateSecretVersionStage",
]
resources = ["*"]
}
read = {
sid = "AllowAccountRead"
principals = [{
type = "AWS"
identifiers = ["arn:aws:iam::1234567890:root"]
}]
actions = ["secretsmanager:DescribeSecret"]
resources = ["*"]
}
}
# Version
ignore_secret_changes = true
secret_string = jsonencode({
engine = "mariadb",
host = "mydb.cluster-123456789012.us-east-1.rds.amazonaws.com",
username = "Bill",
password = "Initial"
dbname = "ThisIsMySuperSecretString12356!&*()",
port = 3306
})
# Rotation
enable_rotation = true
rotation_lambda_arn = "arn:aws:lambda:us-east-1:123456789012:function:my-function"
rotation_rules = {
# This should be more sensible in production
schedule_expression = "rate(1 minute)"
}
tags = {
Environment = "Development"
Project = "Example"
}
}
Examples
Examples codified under the examples are intended to give users references for how to use the module(s) as well as testing/validating changes to the source code of the module. If contributing to the project, please be sure to make any appropriate updates to the relevant examples to allow maintainers to test your changes and to keep the examples up to date for users. Thank you!
License
Apache-2.0 Licensed. See LICENSE.