Skip to content

Commit 43c6e68

Browse files
authored
Merge pull request #9 from cruxstack/development
feat: refactor various areas
2 parents 23efeba + a9f7f6a commit 43c6e68

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

main.tf

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ locals {
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

1722
data "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

2737
module "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+
7693
data "aws_iam_policy_document" "this" {
7794
count = local.enabled ? 1 : 0
7895

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ variable "email_sender_providers" {
5353

5454
validation {
5555
condition = length(var.email_sender_providers) == 1
56-
error_message = "Must define exactly one email provider. Support for more than one coming the future."
56+
error_message = "Must define exactly one email provider. Support for more than one coming in the future."
5757
}
5858

5959
validation {

versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0.0, < 6.0.0"
7+
version = ">= 5.0.0"
88
}
99
docker = {
1010
source = "kreuzwerker/docker"
11-
version = ">= 3.0.0, < 4.0.0"
11+
version = ">= 3.0.0"
1212
}
1313
}
1414
}

0 commit comments

Comments
 (0)