@@ -172,58 +172,60 @@ resource "aws_cloudwatch_event_target" "reindex" {
172172# IAM #
173173# ##########
174174
175- data "aws_iam_policy_document" "assume_role" {
176- statement {
177- actions = [" sts:AssumeRole" ]
178-
179- principals {
180- type = " Service"
181- identifiers = [" lambda.amazonaws.com" ]
182- }
183- }
175+ resource "aws_iam_role" "role" {
176+ description = local. iam_role . description
177+ name = local. iam_role . name
178+ tags = local. iam_role . tags
179+
180+ assume_role_policy = jsonencode ({
181+ Version = " 2012-10-17"
182+ Statement = [{
183+ Sid = " AssumeRole"
184+ Effect = " Allow"
185+ Action = " sts:AssumeRole"
186+ Principal = { Service = " lambda.amazonaws.com" }
187+ }]
188+ })
184189}
185190
186- data "aws_iam_policy_document" "policy" {
187- statement {
188- sid = " ListBucket"
189- actions = [" s3:ListBucket" ]
190- resources = [aws_s3_bucket . pypi . arn ]
191- }
192-
193- statement {
194- sid = " GetObjects"
195- actions = [" s3:GetObject" ]
196- resources = [" ${ aws_s3_bucket . pypi . arn } /*" ]
197- }
198-
199- statement {
200- sid = " PutIndex"
201- actions = [" s3:PutObject" ]
202- resources = [" ${ aws_s3_bucket . pypi . arn } /index.html" ]
203- }
204-
205- statement {
206- sid = " WriteLambdaLogs"
207- resources = [" *" ]
208-
209- actions = [
210- " logs:CreateLogGroup" ,
211- " logs:CreateLogStream" ,
212- " logs:PutLogEvents" ,
191+ resource "aws_iam_role_policy" "policy" {
192+ role = aws_iam_role. role . id
193+ name = local. iam_role . policy_name
194+
195+ policy = jsonencode ({
196+ Version = " 2012-10-17"
197+ Statement = [
198+ {
199+ Sid = " ListBucket"
200+ Effect = " Allow"
201+ Action = " s3:ListBucket"
202+ Resource = aws_s3_bucket.pypi.arn
203+ },
204+ {
205+ Sid = " GetObjects"
206+ Effect = " Allow"
207+ Action = " s3:GetObject"
208+ Resource = " ${ aws_s3_bucket . pypi . arn } /*"
209+ },
210+ {
211+ Sid = " PutIndex"
212+ Effect = " Allow"
213+ Action = " s3:PutObject"
214+ Resource = " ${ aws_s3_bucket . pypi . arn } /index.html"
215+ },
216+ {
217+ Sid = " WriteLambdaLogs"
218+ Effect = " Allow"
219+ Resource = " *"
220+
221+ Action = [
222+ " logs:CreateLogGroup" ,
223+ " logs:CreateLogStream" ,
224+ " logs:PutLogEvents" ,
225+ ]
226+ }
213227 ]
214- }
215- }
216-
217- resource "aws_iam_role" "role" {
218- assume_role_policy = data. aws_iam_policy_document . assume_role . json
219- description = local. iam_role . description
220- name = local. iam_role . name
221- tags = local. iam_role . tags
222-
223- inline_policy {
224- name = local. iam_role . policy_name
225- policy = data. aws_iam_policy_document . policy . json
226- }
228+ })
227229}
228230
229231# ########################
0 commit comments