-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.tf
70 lines (59 loc) · 1.81 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
provider "aws" {
region = "us-east-1"
}
module "aws_iam" {
source = "../../"
# Note: we're using the local here as input instead
roles = local.roles
}
locals {
# Roles in this list will have the custom policy added to its policy_arns list
roles_enriched = [
for role in var.roles : {
name = role.name
path = role.path
desc = role.desc
trust_policy_file = role.trust_policy_file
permissions_boundary = role.permissions_boundary
policies = role.policies
inline_policies = role.inline_policies
policy_arns = concat(role.policy_arns, [aws_iam_policy.s3.arn])
} if role["name"] == "ROLE-ADMIN"
]
# Roles in this list will be left as they were (condition reversed)
roles_default = [
for role in var.roles : {
name = role.name
path = role.path
desc = role.desc
trust_policy_file = role.trust_policy_file
permissions_boundary = role.permissions_boundary
policies = role.policies
inline_policies = role.inline_policies
policy_arns = role.policy_arns
} if role["name"] != "ROLE-ADMIN"
]
# Let's merge both created lists
roles = concat(local.roles_enriched, local.roles_default)
}
data "aws_caller_identity" "current" {}
data "aws_iam_policy_document" "s3" {
statement {
sid = "1"
actions = [
"s3:ListAllMyBuckets",
]
resources = [
"arn:aws:s3::${data.aws_caller_identity.current.account_id}:*"
]
}
}
resource "aws_iam_policy" "s3" {
name = "s3-policy"
path = "/custom/"
description = "Custom S3 policy"
policy = data.aws_iam_policy_document.s3.json
lifecycle {
create_before_destroy = false
}
}