22 name = coalesce (module. this . name , var. name , " cognito-custom-message-sender" )
33 enabled = module. this . enabled
44 aws_account_id = try (coalesce (var. aws_account_id , data. aws_caller_identity . current [0 ]. account_id ), " " )
5- aws_region_name = try (coalesce (var. aws_region_name , data. aws_region . current [0 ]. name ), " " )
5+ aws_region_name = try (coalesce (var. aws_region_name , data. aws_region . current [0 ]. region ), " " )
6+ aws_partition = one (data. aws_partition . current . * . partition )
67
78 email_sender_enabled = local. enabled && var. email_sender_enabled
89 email_sender_policy_path = " ./policy.rego"
@@ -12,6 +13,10 @@ locals {
1213 sms_sender_policy_path = " ./policy.wasm"
1314 sms_sender_policy_content = var. sms_sender_policy_content
1415 sms_sender_throttle_period_in_minutes = 15
16+
17+ iam_role_policies = {
18+ access = one (data. aws_iam_policy_document . this . * . json )
19+ }
1520}
1621
1722data "aws_caller_identity" "current" {
@@ -22,6 +27,11 @@ data "aws_region" "current" {
2227 count = local. enabled ? 1 : 0
2328}
2429
30+ data "aws_partition" "current" {
31+ count = module. this . enabled ? 1 : 0
32+ }
33+
34+
2535# ============================================================ message-sender ===
2636
2737module "message_sender_label" {
@@ -61,18 +71,25 @@ resource "aws_iam_role" "this" {
6171 }]
6272 })
6373
64- managed_policy_arns = [
65- " arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
66- ]
74+ tags = module. message_sender_label . tags
75+ }
6776
68- inline_policy {
69- name = " message-sender-access"
70- policy = data. aws_iam_policy_document . this [0 ]. json
71- }
77+ resource "aws_iam_role_policy_attachment" "ssm_managed_instance_core" {
78+ count = module. this . enabled ? 1 : 0
7279
73- tags = module. message_sender_label . tags
80+ role = aws_iam_role. this [0 ]. name
81+ policy_arn = " arn:${ local . aws_partition } :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
7482}
7583
84+ resource "aws_iam_role_policy" "this" {
85+ for_each = { for k , v in local . iam_role_policies : k => v if module . this . enabled }
86+
87+ name = each. key
88+ role = resource. aws_iam_role . this [0 ]. name
89+ policy = each. value
90+ }
91+
92+
7693data "aws_iam_policy_document" "this" {
7794 count = local. enabled ? 1 : 0
7895
0 commit comments