Skip to content

Commit eed0992

Browse files
authored
fix(rds): Corrected SSM Paths for Non Existent var.name (#1052)
1 parent 6317a82 commit eed0992

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

modules/rds/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ Example - I want a new instance `rds-example-new` to be provisioned from a snaps
231231
| Name | Description |
232232
|------|-------------|
233233
| <a name="output_exports"></a> [exports](#output\_exports) | Map of exports for use in deployment configuration templates |
234+
| <a name="output_kms_key_alias"></a> [kms\_key\_alias](#output\_kms\_key\_alias) | The KMS key alias |
234235
| <a name="output_psql_helper"></a> [psql\_helper](#output\_psql\_helper) | A helper output to use with psql for connecting to this RDS instance. |
235236
| <a name="output_rds_address"></a> [rds\_address](#output\_rds\_address) | Address of the instance |
236237
| <a name="output_rds_arn"></a> [rds\_arn](#output\_rds\_arn) | ARN of the instance |

modules/rds/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ output "psql_helper" {
8383
value = local.psql_access_enabled ? local.psql_message : ""
8484
description = "A helper output to use with psql for connecting to this RDS instance."
8585
}
86+
87+
output "kms_key_alias" {
88+
value = module.kms_key_rds.alias_name
89+
description = "The KMS key alias"
90+
}

modules/rds/systems-manager.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ variable "ssm_key_port" {
4949

5050
locals {
5151
ssm_enabled = local.enabled && var.ssm_enabled
52-
rds_database_password_path = format(var.ssm_key_format, var.ssm_key_prefix, var.name, var.ssm_key_password)
52+
ssm_name_path = join("-", compact(concat([var.name], var.attributes)))
53+
rds_database_password_path = format(var.ssm_key_format, var.ssm_key_prefix, local.ssm_name_path, var.ssm_key_password)
5354
}
5455

5556
resource "aws_ssm_parameter" "rds_database_user" {
5657
count = local.ssm_enabled ? 1 : 0
5758

58-
name = format(var.ssm_key_format, var.ssm_key_prefix, var.name, var.ssm_key_user)
59+
name = format(var.ssm_key_format, var.ssm_key_prefix, local.ssm_name_path, var.ssm_key_user)
5960
value = local.database_user
6061
description = "RDS DB user"
6162
type = "String"
@@ -76,7 +77,7 @@ resource "aws_ssm_parameter" "rds_database_password" {
7677
resource "aws_ssm_parameter" "rds_database_hostname" {
7778
count = local.ssm_enabled ? 1 : 0
7879

79-
name = format(var.ssm_key_format, var.ssm_key_prefix, var.name, var.ssm_key_hostname)
80+
name = format(var.ssm_key_format, var.ssm_key_prefix, local.ssm_name_path, var.ssm_key_hostname)
8081
value = module.rds_instance.hostname == "" ? module.rds_instance.instance_address : module.rds_instance.hostname
8182
description = "RDS DB hostname"
8283
type = "String"
@@ -86,14 +87,14 @@ resource "aws_ssm_parameter" "rds_database_hostname" {
8687
resource "aws_ssm_parameter" "rds_database_port" {
8788
count = local.ssm_enabled ? 1 : 0
8889

89-
name = format(var.ssm_key_format, var.ssm_key_prefix, var.name, var.ssm_key_port)
90+
name = format(var.ssm_key_format, var.ssm_key_prefix, local.ssm_name_path, var.ssm_key_port)
9091
value = var.database_port
9192
description = "RDS DB port"
9293
type = "String"
9394
overwrite = true
9495
}
9596

9697
output "rds_database_ssm_key_prefix" {
97-
value = local.ssm_enabled ? format(var.ssm_key_format, var.ssm_key_prefix, var.name, "") : null
98+
value = local.ssm_enabled ? format(var.ssm_key_format, var.ssm_key_prefix, local.ssm_name_path, "") : null
9899
description = "SSM prefix"
99100
}

0 commit comments

Comments
 (0)