-
Notifications
You must be signed in to change notification settings - Fork 0
/
policy.tf
41 lines (32 loc) · 948 Bytes
/
policy.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
# IAM policy document that that allows for reading and possibly
# writing the specified objects from the specified S3 bucket.
data "aws_iam_policy_document" "s3_access" {
statement {
actions = var.read_only ? local.object_actions_read : local.object_actions_read_write
effect = "Allow"
# Create list of ARNs with all combinations of bucket and objects
resources = [for t in setproduct([var.s3_bucket], var.s3_objects) : format("arn:aws:s3:::${t[0]}/${t[1]}")]
}
statement {
actions = [
"s3:HeadBucket",
]
effect = "Allow"
resources = ["*"]
}
statement {
actions = [
"s3:ListBucket",
]
effect = "Allow"
resources = [
"arn:aws:s3:::${var.s3_bucket}"
]
}
}
# The IAM policy for our role
resource "aws_iam_policy" "s3_access" {
description = local.role_description
name = local.role_name
policy = data.aws_iam_policy_document.s3_access.json
}