Skip to content

Commit 45fcb80

Browse files
committed
feat: resolve deprecated warnings
1 parent 02e786f commit 45fcb80

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

main.tf

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ locals {
44
auth_service_enabled = local.enabled && var.auth_service_config.enabled
55
urlrewrite_service_enabled = local.enabled && var.urlrewrite_service_config.enabled
66

7-
aws_account_id = try(coalesce(var.aws_account_id, data.aws_caller_identity.current[0].account_id), "") # tflint-ignore: terraform_unused_declarations
8-
aws_region_name = try(coalesce(var.aws_region_name, data.aws_region.current[0].name), "")
7+
aws_account_id = one(data.aws_caller_identity.current.*.account_id)
8+
aws_region_name = one(data.aws_region.current.*.region)
9+
aws_partition = one(data.aws_partition.current.*.partition)
910

1011
service_config = {
1112
rewrite_url = {
@@ -74,6 +75,10 @@ locals {
7475
result := []
7576
EOF
7677
)
78+
79+
iam_role_attachments = toset(module.this.enabled ? [
80+
"arn:${local.aws_partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
81+
] : [])
7782
}
7883

7984
data "aws_caller_identity" "current" {
@@ -84,6 +89,10 @@ data "aws_region" "current" {
8489
count = module.this.enabled && var.aws_region_name == "" ? 1 : 0
8590
}
8691

92+
data "aws_partition" "current" {
93+
count = module.this.enabled ? 1 : 0
94+
}
95+
8796
# ====================================================== middleware-services ===
8897

8998
module "mw_service_label" {
@@ -134,17 +143,20 @@ resource "aws_iam_role" "this" {
134143
}]
135144
})
136145

137-
managed_policy_arns = [
138-
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
139-
]
140-
141146
tags = module.mw_service_label.tags
142147

143148
lifecycle {
144149
create_before_destroy = true
145150
}
146151
}
147152

153+
resource "aws_iam_role_policy_attachment" "this" {
154+
for_each = local.iam_role_attachments
155+
156+
role = resource.aws_iam_role.this[0].name
157+
policy_arn = each.key
158+
}
159+
148160
# ============================================================ auth-services ===
149161

150162
module "mw_auth_service_label" {

0 commit comments

Comments
 (0)