Created
August 16, 2021 05:03
-
-
Save MikeZ77/2229ca60467d90eb5e514ebb2439693d to your computer and use it in GitHub Desktop.
RDS Proxy Secrets Manager Policies
This file contains 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
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