Skip to content

Commit

Permalink
#19 updated ssm with rds endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kunduso committed Sep 16, 2024
1 parent f4cad08 commit 6dd0d23
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions ssm_parameter.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter
resource "aws_ssm_parameter" "rds_secret_arn" {
name = "/${var.name}/rds-password-arn"
resource "aws_ssm_parameter" "rds_connection" {
name = "/${var.name}/rds-connection"
type = "SecureString"
key_id = aws_kms_key.encryption_rds.id
value = aws_db_instance.postgresql.master_user_secret[0].secret_arn
value = <<EOF
{
"rds_endpoint":"${aws_db_instance.postgresql.endpoint}",
"secret_arn":"${aws_db_instance.postgresql.master_user_secret[0].secret_arn}"
}
EOF
}
#Create a policy to read from the specific parameter store
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy
resource "aws_iam_policy" "ssm_parameter_policy" {
name = "${var.name}-ssm-parameter-read-policy"
name = "${var.name}-rds-connection-read-policy"
path = "/"
description = "Policy to read the RDS Password ARN stored in the SSM Parameter Store."
description = "Policy to read the RDS Endpoint and Password ARN stored in the SSM Parameter Store."
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
policy = jsonencode({
Expand All @@ -22,7 +27,7 @@ resource "aws_iam_policy" "ssm_parameter_policy" {
"ssm:GetParameters",
"ssm:GetParameter"
],
Resource = [aws_ssm_parameter.rds_secret_arn.arn]
Resource = [aws_ssm_parameter.rds_connection.arn]
}
]
})
Expand Down

0 comments on commit 6dd0d23

Please sign in to comment.