-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from nimblehq/chore/104-improve-envs-secrets
[#104] Improve the way to manage environment variables and secrets
- Loading branch information
Showing
9 changed files
with
175 additions
and
51 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
resource "aws_ssm_parameter" "secret_key_base" { | ||
name = "/${var.namespace}/SECRET_KEY_BASE" | ||
resource "aws_ssm_parameter" "secret_parameters" { | ||
for_each = var.secrets | ||
|
||
name = "/${var.namespace}/${each.key}" | ||
type = "String" | ||
value = var.secret_key_base | ||
value = each.value | ||
} | ||
|
||
resource "aws_ssm_parameter" "database_url" { | ||
name = "/${var.namespace}/DATABASE_URL" | ||
type = "String" | ||
value = "postgresql://${var.rds_username}:${var.rds_password}@${var.rds_endpoint}/${var.rds_database_name}" | ||
locals { | ||
# Create a list of parameter store ARNs for granting access to ECS task execution role | ||
parameter_store_arns = [for parameter in aws_ssm_parameter.secret_parameters : parameter.arn] | ||
|
||
# Get secret names array | ||
secret_names = keys(var.secrets) | ||
|
||
# Create a map {secret_name: secret_arn} using zipmap function for iteration | ||
secret_arns = zipmap(local.secret_names, local.parameter_store_arns) | ||
|
||
# Create the formatted secrets for ECS task definition | ||
secrets_variables = [for secret_key, secret_arn in local.secrets_name_arn_map : | ||
tomap({ "name" = upper(secret_key), "valueFrom" = secret_arn }) | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
output "parameter_store" { | ||
description = "ARNs of the parameters" | ||
output "secrets_variables" { | ||
description = "The formatted secrets for ECS task definition" | ||
value = local.secrets_variables | ||
} | ||
|
||
value = { | ||
secret_base_ssm_arn = aws_ssm_parameter.secret_key_base.arn | ||
database_url_ssm_arn = aws_ssm_parameter.database_url.arn | ||
} | ||
output "parameter_store_arns" { | ||
description = "List of parameter store ARNs for granting access to ECS task execution role" | ||
value = local.parameter_store_arns | ||
} |
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
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
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