This repository has been archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.website.tf
73 lines (56 loc) · 2.22 KB
/
iam.website.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
72
73
# --------------------------------
# IAM users for content maintenance
resource "aws_iam_user" "website-content-maintenance-cicd-users" {
count = "${length(var.envs)}"
name = "website-content-maintenance-cicd-user-${element(var.envs, count.index)}"
force_destroy = true
}
# --------------------------------
# IAM group
data "aws_iam_policy_document" "website-content-maintenance-cicd-group-policies" {
count = "${length(var.envs)}"
statement {
actions = [
"s3:*",
]
resources = [
"${element(aws_s3_bucket.website-content.*.arn, count.index)}/",
"${element(aws_s3_bucket.website-content.*.arn, count.index)}/*",
]
condition {
test = "IpAddress"
variable = "aws:SourceIp"
values = [
"192.0.2.0/24", # Office
"198.51.100.0/24", # VPN
"203.0.113.0/24", # IDC
]
}
}
statement {
actions = ["cloudfront:CreateInvalidation"]
resources = ["*"]
}
}
resource "aws_iam_policy" "website-content-maintenance-cicd-group-policies" {
count = "${length(var.envs)}"
name = "website-content-maintenance-cicd-group-policy-${element(var.envs, count.index)}"
policy = "${element(data.aws_iam_policy_document.website-content-maintenance-cicd-group-policies.*.json, count.index)}"
}
resource "aws_iam_group" "website-content-maintenance-cicd-groups" {
count = "${length(var.envs)}"
name = "website-content-maintenance-cicd-group-${element(var.envs, count.index)}"
}
resource "aws_iam_group_policy_attachment" "website-content-maintenance-cicd-group-attachments" {
count = "${length(var.envs)}"
group = "${element(aws_iam_group.website-content-maintenance-cicd-groups.*.name, count.index)}"
policy_arn = "${element(aws_iam_policy.website-content-maintenance-cicd-group-policies.*.arn, count.index)}"
}
resource "aws_iam_group_membership" "website-content-maintenance-cicd-group-memberships" {
count = "${length(var.envs)}"
name = "website-content-maintenance-cicd-group-membership-${element(var.envs, count.index)}"
group = "${element(aws_iam_group.website-content-maintenance-cicd-groups.*.name, count.index)}"
users = [
"${element(aws_iam_user.website-content-maintenance-cicd-users.*.name, count.index)}",
]
}