-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.tf
156 lines (142 loc) · 3.65 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
data "aws_iam_policy_document" "scp_policy" {
# Root account access
dynamic "statement" {
for_each = local.deny_root_account_access_statement
content {
actions = ["*"]
resources = ["*"]
effect = "Deny"
condition {
test = "StringLike"
variable = "aws:PrincipalArn"
values = ["arn:aws:iam::*:root"]
}
}
}
# IAM password policy changes
dynamic "statement" {
for_each = local.deny_password_policy_changes_statement
content {
actions = [
"iam:DeleteAccountPasswordPolicy",
"iam:UpdateAccountPasswordPolicy"
]
resources = ["*"]
effect = "Deny"
condition {
test = "ForAnyValue:ArnNotLike"
variable = "aws:PrincipalArn"
values = [
"arn:aws:iam::*:role/Deploy"
]
}
}
}
# AMI
dynamic "statement" {
for_each = local.deny_vpn_gateway_changes_statement
content {
effect = "Deny"
actions = [
"ec2:DetachVpnGateway",
"ec2:AttachVpnGateway",
"ec2:DeleteVpnGateway",
"ec2:CreateVpnGateway"
]
resources = [
"arn:aws:ec2:*:*:vpn-gateway/*",
"arn:aws:ec2:*:*:vpc/*"
]
condition {
test = "ForAnyValue:ArnNotLike"
variable = "aws:PrincipalArn"
values = [
"arn:aws:iam::*:role/NetworkAdmin",
]
}
}
}
# Deny Network changes
#
dynamic "statement" {
for_each = local.deny_vpc_changes_statement
content {
effect = "Deny"
actions = [
"ec2:DeleteFlowLogs",
"ec2:ModifyVpc*",
"ec2:CreateVpc*",
"ec2:DeleteVpc*",
"ec2:AcceptVpcPeeringConnection",
"ec2:DisassociateVpcCidrBlock"
]
resources = [
"*"
]
condition {
test = "ForAnyValue:ArnNotLike"
variable = "aws:PrincipalArn"
values = [
"arn:aws:iam::*:role/NetworkAdmin",
]
}
}
}
# Config changes for core
dynamic "statement" {
for_each = local.deny_config_changes_statement
content {
effect = "Deny"
actions = [
"config:DeleteConfigurationRecorder",
"config:DeleteDeliveryChannel",
"config:DeleteRetentionConfiguration",
"config:PutConfigurationRecorder",
"config:PutDeliveryChannel",
"config:PutRetentionConfiguration",
"config:StopConfigurationRecorder"
]
resources = ["*"]
condition {
test = "ForAnyValue:ArnNotLike"
variable = "aws:PrincipalArn"
values = [
"arn:aws:iam::*:role/Deploy"
]
}
}
}
# Deny Cloud Trail changes
dynamic "statement" {
for_each = local.deny_cloudtrail_changes_statement
content {
effect = "Deny"
actions = [
"cloudtrail:DeleteTrail",
"cloudtrail:UpdateTrail",
"cloudtrail:PutEventSelectors",
"cloudtrail:StopLogging"
]
resources = ["arn:aws:cloudtrail:*:*:trail/*"]
condition {
test = "ForAnyValue:ArnNotLike"
variable = "aws:PrincipalArn"
values = [
"arn:aws:iam::*:role/aws-reserved/sso.amazonaws.com/Deploy"
]
}
}
}
}
# Generate the SCP Policy
resource "aws_organizations_policy" "scp_document" {
name = var.name
description = "${var.name} : SCP generated by org-scp module"
content = data.aws_iam_policy_document.scp_policy.json
}
# Create the attachment for the targets
resource "aws_organizations_policy_attachment" "scp_attachment" {
for_each = var.targets
policy_id = aws_organizations_policy.scp_document.id
target_id = each.value
}