4
4
auth_service_enabled = local. enabled && var. auth_service_config . enabled
5
5
urlrewrite_service_enabled = local. enabled && var. urlrewrite_service_config . enabled
6
6
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 )
9
10
10
11
service_config = {
11
12
rewrite_url = {
@@ -74,6 +75,10 @@ locals {
74
75
result := []
75
76
EOF
76
77
)
78
+
79
+ iam_role_attachments = toset (module. this . enabled ? [
80
+ " arn:${ local . aws_partition } :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
81
+ ] : [])
77
82
}
78
83
79
84
data "aws_caller_identity" "current" {
@@ -84,6 +89,10 @@ data "aws_region" "current" {
84
89
count = module. this . enabled && var. aws_region_name == " " ? 1 : 0
85
90
}
86
91
92
+ data "aws_partition" "current" {
93
+ count = module. this . enabled ? 1 : 0
94
+ }
95
+
87
96
# ====================================================== middleware-services ===
88
97
89
98
module "mw_service_label" {
@@ -134,17 +143,20 @@ resource "aws_iam_role" "this" {
134
143
}]
135
144
})
136
145
137
- managed_policy_arns = [
138
- " arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
139
- ]
140
-
141
146
tags = module. mw_service_label . tags
142
147
143
148
lifecycle {
144
149
create_before_destroy = true
145
150
}
146
151
}
147
152
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
+
148
160
# ============================================================ auth-services ===
149
161
150
162
module "mw_auth_service_label" {
0 commit comments