forked from zoitech/terraform-aws-s3-with-iam-access
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_template_bucket_policy.tf
51 lines (43 loc) · 1.38 KB
/
data_template_bucket_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
42
43
44
45
46
47
48
49
50
# template file for policy section: denying the unencrypted uploads
data "template_file" "bucket_policy_for_deny_unencrypted" {
template = file(
"${path.module}/templates/bucket_policies/bucket_policy_deny_unencrypted.json.tpl",
)
vars = {
bucket-arn = aws_s3_bucket.s3_bucket.arn
}
}
# template file for policy section: standard users
data "template_file" "bucket_policy_for_a_standard_user" {
count = length(var.iam_user_s3_standard_names)
template = file(
"${path.module}/templates/bucket_policies/bucket_policy_user_template.json.tpl",
)
vars = {
bucket-arn = aws_s3_bucket.s3_bucket.arn
user-name = element(aws_iam_user.standard_user.*.name, count.index)
kms-key = element(aws_kms_key.kmskey.*.key_id, count.index)
}
}
# combine policy sections into one
data "template_file" "bucket_policy" {
template = <<JSON
$${policy_start}
$${deny_unencrypted_object_uploads}
$${user_policies}
$${policy_end}
JSON
vars = {
policy_start = file(
"${path.module}/templates/bucket_policies/bucket_policy_start.json.tpl",
)
deny_unencrypted_object_uploads = data.template_file.bucket_policy_for_deny_unencrypted.rendered
user_policies = join(
",\n",
data.template_file.bucket_policy_for_a_standard_user.*.rendered,
)
policy_end = file(
"${path.module}/templates/bucket_policies/bucket_policy_end.json.tpl",
)
}
}