Skip to content

Instantly share code, notes, and snippets.

@MikeZ77
Created August 16, 2021 05:03
Show Gist options
  • Save MikeZ77/2229ca60467d90eb5e514ebb2439693d to your computer and use it in GitHub Desktop.
Save MikeZ77/2229ca60467d90eb5e514ebb2439693d to your computer and use it in GitHub Desktop.
RDS Proxy Secrets Manager Policies
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["rds.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "rds_proxy_policy_document" {
statement {
sid = "AllowProxyToGetDbCredsFromSecretsManager"
actions = [
"secretsmanager:GetSecretValue"
]
resources = [
aws_secretsmanager_secret.rds_secret.arn
]
}
statement {
sid = "AllowProxyToDecryptDbCredsFromSecretsManager"
actions = [
"kms:Decrypt"
]
resources = [
"*"
]
condition {
test = "StringEquals"
values = ["secretsmanager.${var.my_aws_region}.amazonaws.com"]
variable = "kms:ViaService"
}
}
}
resource "aws_iam_policy" "rds_proxy_iam_policy" {
name = "rds-proxy-policy"
policy = data.aws_iam_policy_document.rds_proxy_policy_document.json
}
resource "aws_iam_role_policy_attachment" "rds_proxy_iam_attach" {
policy_arn = aws_iam_policy.rds_proxy_iam_policy.arn
role = aws_iam_role.rds_proxy_iam_role.name
}
resource "aws_iam_role" "rds_proxy_iam_role" {
name = "rds-proxy-role"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment