Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TDRD 512] Toggleable master password management via secrets manager integration #297

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions lambda/create_db_users.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ resource "aws_lambda_function" "create_db_users_lambda_function" {
reserved_concurrent_executions = var.reserved_concurrency
tags = var.common_tags
environment {
variables = {
DB_ADMIN_USER = aws_kms_ciphertext.environment_vars_create_db_users["db_admin_user"].ciphertext_blob
DB_ADMIN_PASSWORD = aws_kms_ciphertext.environment_vars_create_db_users["db_admin_password"].ciphertext_blob
DB_URL = aws_kms_ciphertext.environment_vars_create_db_users["db_url"].ciphertext_blob
DATABASE_NAME = aws_kms_ciphertext.environment_vars_create_db_users["database_name"].ciphertext_blob
}
variables = merge(
{
DB_ADMIN_USER = aws_kms_ciphertext.environment_vars_create_db_users["db_admin_user"].ciphertext_blob
DB_URL = aws_kms_ciphertext.environment_vars_create_db_users["db_url"].ciphertext_blob
DATABASE_NAME = aws_kms_ciphertext.environment_vars_create_db_users["database_name"].ciphertext_blob
},
var.db_admin_password != null ? {
DB_ADMIN_PASSWORD = aws_kms_ciphertext.environment_vars_create_db_users["db_admin_password"].ciphertext_blob
} : {
DB_MASTER_USER_SECRET_ARN = aws_kms_ciphertext.environment_vars_create_db_users["db_master_user_secret_arn"].ciphertext_blob
}
)
}

vpc_config {
Expand All @@ -29,7 +35,14 @@ resource "aws_lambda_function" "create_db_users_lambda_function" {
}

resource "aws_kms_ciphertext" "environment_vars_create_db_users" {
for_each = local.count_create_db_users == 0 ? {} : { db_admin_user = var.db_admin_user, db_admin_password = var.db_admin_password, db_url = "jdbc:postgresql://${var.db_url}:5432/consignmentapi", database_name = var.database_name }
for_each = local.count_create_db_users == 0 ? {} : merge(
{
db_admin_user = var.db_admin_user
db_url = "jdbc:postgresql://${var.db_url}:5432/consignmentapi"
database_name = var.database_name
},
var.db_admin_password != null ? { db_admin_password = var.db_admin_password } : { db_master_user_secret_arn = var.db_master_user_secret_arn }
)
key_id = var.kms_key_arn
plaintext = each.value
context = { "LambdaFunctionName" = local.create_db_users_function_name }
Expand Down
4 changes: 4 additions & 0 deletions lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,7 @@ variable "notifications_vpc_config" {
security_group_ids = []
}
}

variable "db_master_user_secret_arn" {
default = null
}
1 change: 1 addition & 0 deletions rds_instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ resource "aws_ssm_parameter" "database_username" {
}

resource "aws_ssm_parameter" "database_password" {
count = var.manage_master_credentials_with_secrets_manager ? 0 : 1
name = "/${var.environment}/${var.database_name}/instance/password"
type = "SecureString"
value = aws_db_instance.db_instance.password
Expand Down
2 changes: 1 addition & 1 deletion rds_instance/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ output "resource_id" {
}

output "database_master_user_secret_arn" {
value = var.manage_master_credentials_with_secrets_manager ? aws_db_instance.db_instance.master_user_secret[0].secret_arn : null
value = var.manage_master_credentials_with_secrets_manager ? join("", aws_db_instance.db_instance.master_user_secret.*.secret_arn) : null
}
Loading