blob: ecc63b10736b0e431f9790d86546cf66e818e516 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# Description: This file contains the IAM roles and policies for the lambda functions
########################################################################
# IAM MULTI-ROLE SETUP
########################################################################
# DEFINE MULTI-SERVICE ROLE (lambda, s3, cloudwatch, events)
resource "aws_iam_role" "multi_service_role" {
name = "multi_service_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = [
"lambda.amazonaws.com",
"states.amazonaws.com",
"events.amazonaws.com",
"s3.amazonaws.com"
]
}
}
]
})
}
########################################################################
# S3 SETUP
# Description: allows allows retention/tagging/access control settings
# Lambda IAM Policy for S3 Write
########################################################################
# S3 DEFINE POLICY
resource "aws_iam_policy" "s3_access_policy" {
name = "s3_access_policy"
path = "/"
description = "IAM policy for S3 access"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket"
]
resources = [
"${aws_s3_bucket.extract_bucket.arn}/*",
"${aws_s3_bucket.transform_bucket.arn}/*",
"${aws_s3_bucket.lambda_bucket.arn}/*"
]
}
]
}
)
}
# S3 WRITE POLICY
resource "aws_iam_policy" "s3_write_policy" {
policy = data.aws_iam_policy_document.s3_data_policy_doc.json
}
# S3 ATTACH POLICY
resource "aws_iam_role_policy_attachment" "lambda_s3_policy_attachment" {
role = aws_iam_role.lambda_role.name
policy_arn = aws_iam_policy.s3_write_policy.arn
}
########################################################################
# LAMBDA SETUP
# Description: Allows Lambda permission to write to Cloudwatch logs
########################################################################
# Uses Iam policy document to assume role for lambda functions
resource "aws_iam_role" "lambda_role" {
assume_role_policy = data.aws_iam_policy_document.bentley_service_role.json
}
|