-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
71 lines (59 loc) · 1.82 KB
/
main.tf
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
data "aws_caller_identity" "current" {}
data "aws_iam_policy_document" "assume_role_policy" {
statement {
effect = "Allow"
principals {
type = "Federated"
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${var.oidc_provider_id}"]
}
actions = ["sts:AssumeRoleWithWebIdentity"]
condition {
test = "StringLike"
variable = "${var.oidc_provider_id}:sub"
values = ["system:serviceaccount:*"]
}
}
}
resource "aws_iam_role" "s3_access_role" {
name = var.role_name
description = "IAM role to assume in order to use S3"
assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json
force_detach_policies = true
permissions_boundary = var.iam_permissions_boundary_policy_arn
tags = merge(var.tags, tomap({ "Name" = var.role_name }))
}
# Use data instead of resource here
data "aws_iam_policy_document" "s3_policy" {
statement {
sid = "S3Access"
effect = "Allow"
actions = [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListBucket",
"s3:GetLifecycleConfiguration",
"s3:PutLifecycleConfiguration",
"s3:PutObjectTagging",
"s3:GetObjectTagging",
"s3:DeleteObjectTagging",
"s3:GetBucketPolicy",
"s3:DeleteBucket",
"s3:CreateBucket",
"s3:GetBucketAcl"
]
resources = [
"arn:aws:s3:::${var.bucket_name}",
"arn:aws:s3:::${var.bucket_name}/*"
]
}
}
resource "aws_iam_policy" "s3_policy" {
name = "S3Policy"
description = "Policy for S3 Store access"
policy = data.aws_iam_policy_document.s3_policy.json
}
resource "aws_iam_role_policy_attachment" "s3_attach" {
role = aws_iam_role.s3_access_role.name
policy_arn = aws_iam_policy.s3_policy.arn
}