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
|
# main.tf — ORG compliance fixture
# Produces zero ORG policy violations
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "ap-south-1"
default_tags {
tags = {
Owner = "platform-team"
CostCenter = "CC-1234"
Environment = "prod"
}
}
}
# ORG-001 + ORG-002 + ORG-003 — All features, all policy types, all trusted services
resource "aws_organizations_organization" "good_org" {
feature_set = "ALL"
aws_service_access_principals = [
"cloudtrail.amazonaws.com",
"config.amazonaws.com",
"securityhub.amazonaws.com",
"guardduty.amazonaws.com",
"access-analyzer.amazonaws.com",
"ram.amazonaws.com",
]
enabled_policy_types = [
"TAG_POLICY",
"BACKUP_POLICY",
"AISERVICES_OPT_OUT_POLICY",
]
}
# ORG-004 — Delegated admins for all required services
resource "aws_organizations_delegated_administrator" "securityhub" {
account_id = "123456789012"
service_principal = "securityhub.amazonaws.com"
}
resource "aws_organizations_delegated_administrator" "guardduty" {
account_id = "123456789012"
service_principal = "guardduty.amazonaws.com"
}
resource "aws_organizations_delegated_administrator" "config" {
account_id = "123456789012"
service_principal = "config.amazonaws.com"
}
resource "aws_organizations_delegated_administrator" "access_analyzer" {
account_id = "123456789012"
service_principal = "access-analyzer.amazonaws.com"
}
# ORG-005 — All three alternate contacts
resource "aws_account_alternate_contact" "security" {
alternate_contact_type = "SECURITY"
name = "Security Team"
title = "Security"
email_address = "[email protected]"
phone_number = "+1-555-0100"
}
resource "aws_account_alternate_contact" "billing" {
alternate_contact_type = "BILLING"
name = "Billing Team"
title = "Billing"
email_address = "[email protected]"
phone_number = "+1-555-0200"
}
resource "aws_account_alternate_contact" "operations" {
alternate_contact_type = "OPERATIONS"
name = "Operations Team"
title = "Operations"
email_address = "[email protected]"
phone_number = "+1-555-0300"
}
# ORG-006 — Tag Policy defined and attached
resource "aws_organizations_policy" "good_tag_policy" {
name = "good-tag-policy"
type = "TAG_POLICY"
content = jsonencode({
tags = {
Environment = { tag_value = { "@@assign" = ["prod", "dev", "staging"] } }
Owner = { tag_value = { "@@assign" = ["*"] } }
CostCenter = { tag_value = { "@@assign" = ["*"] } }
}
})
}
resource "aws_organizations_policy_attachment" "tag_policy_attachment" {
policy_id = aws_organizations_policy.good_tag_policy.id
target_id = aws_organizations_organization.good_org.roots[0].id
}
# ORG-007 — Backup Policy defined and attached
resource "aws_organizations_policy" "good_backup_policy" {
name = "good-backup-policy"
type = "BACKUP_POLICY"
content = jsonencode({
plans = {
daily_backup = {
regions = { "@@assign" = ["ap-south-1"] }
rules = {
daily_rule = {
schedule_expression = { "@@assign" = "cron(0 3 * * ? *)" }
target_backup_vault_name = { "@@assign" = "Default" }
lifecycle = {
delete_after_days = { "@@assign" = 35 }
}
}
}
selections = {
all_resources = {
iam_role_arn = { "@@assign" = "arn:aws:iam::$account:role/AWSBackupDefaultServiceRole" }
resources = { "@@assign" = ["*"] }
}
}
}
}
})
}
resource "aws_organizations_policy_attachment" "backup_policy_attachment" {
policy_id = aws_organizations_policy.good_backup_policy.id
target_id = aws_organizations_organization.good_org.roots[0].id
}
# ORG-008 — OUs defined
resource "aws_organizations_organizational_unit" "security" {
name = "Security"
parent_id = aws_organizations_organization.good_org.roots[0].id
}
resource "aws_organizations_organizational_unit" "workloads" {
name = "Workloads"
parent_id = aws_organizations_organization.good_org.roots[0].id
}
resource "aws_organizations_organizational_unit" "sandbox" {
name = "Sandbox"
parent_id = aws_organizations_organization.good_org.roots[0].id
}
|