Skip to content

Commit

Permalink
fix: ensuring the account names are ordered (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
gambol99 authored Oct 27, 2024
1 parent a38c5b1 commit 63b3ebf
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 12 deletions.
16 changes: 7 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,23 @@ resource "aws_sns_topic_subscription" "subscribers" {
module "notify" {
source = "./modules/notify"

accounts_id_to_name = var.accounts_id_to_name
cloudwatch_log_group_kms_key_id = var.cloudwatch_log_group_kms_key_id
cloudwatch_log_group_retention_in_days = var.cloudwatch_log_group_retention
cloudwatch_log_group_tags = var.tags
create_sns_topic = false
delivery_channels = local.channels_config
enable_slack = var.enable_slack
enable_teams = var.enable_teams
iam_role_tags = var.tags
identity_center_role = var.identity_center_role
identity_center_start_url = var.identity_center_start_url
lambda_function_tags = var.tags
post_icons_url = var.post_icons_url
recreate_missing_package = false
enable_slack = var.enable_slack
enable_teams = var.enable_teams
delivery_channels = local.channels_config
sns_topic_name = var.sns_topic_name
sns_topic_tags = var.tags
tags = var.tags

accounts_id_to_name = var.accounts_id_to_name
post_icons_url = var.post_icons_url

identity_center_start_url = var.identity_center_start_url
identity_center_role = var.identity_center_role

depends_on = [module.sns]
}
85 changes: 85 additions & 0 deletions modules/notify/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion modules/notify/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,18 @@ locals {
}
}

## We need to ensure the account names are ordered
account_by_ids = [
for name in sort(keys(var.accounts_id_to_name)) : {
id = name
name = var.accounts_id_to_name[name]
}
]

accounts_id_to_name_python_dictonary = templatefile(
"${path.module}/mapAccountIdToName-python-dict.tftpl",
{
accounts_id_to_name = var.accounts_id_to_name
accounts_id_to_name = local.account_by_ids
}
)
notification_emblems_python = templatefile(
Expand Down
4 changes: 2 additions & 2 deletions modules/notify/mapAccountIdToName-python-dict.tftpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by terraform
ACCOUNT_ID_TO_NAME = {
%{~ for account_id, account_name in accounts_id_to_name}
"${account_id}": "${account_name}",
%{~ for account in accounts_id_to_name}
"${account.id}": "${account.name}",
%{~ endfor}
}
4 changes: 4 additions & 0 deletions modules/notify/versions.tf → modules/notify/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ terraform {
source = "hashicorp/aws"
version = ">= 4.8"
}
local = {
source = "hashicorp/local"
version = ">= 2.5.0"
}
}
}

0 comments on commit 63b3ebf

Please sign in to comment.