-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathmain.tf
204 lines (169 loc) · 6.45 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
terraform {
backend "remote" {
hostname = "app.terraform.io"
organization = "hashicorp-v2"
workspaces {
name = "tfe-policies-example"
}
}
}
variable "tfe_token" {}
variable "tfe_hostname" {
description = "The domain where your TFE is hosted."
default = "app.terraform.io"
}
variable "tfe_organization" {
description = "The TFE organization to apply your changes to."
default = "example_corp"
}
provider "tfe" {
hostname = "${var.tfe_hostname}"
token = "${var.tfe_token}"
version = "~> 0.6"
}
data "tfe_workspace_ids" "all" {
names = ["*"]
organization = "${var.tfe_organization}"
}
locals {
workspaces = "${data.tfe_workspace_ids.all.external_ids}" # map of names to IDs
}
resource "tfe_policy_set" "global" {
name = "global"
description = "Policies that should be enforced on ALL infrastructure."
organization = "${var.tfe_organization}"
global = true
policy_ids = [
"${tfe_sentinel_policy.passthrough.id}",
"${tfe_sentinel_policy.aws-block-allow-all-cidr.id}",
"${tfe_sentinel_policy.azurerm-block-allow-all-cidr.id}",
"${tfe_sentinel_policy.gcp-block-allow-all-cidr.id}",
"${tfe_sentinel_policy.aws-restrict-instance-type-default.id}",
"${tfe_sentinel_policy.azurerm-restrict-vm-size.id}",
"${tfe_sentinel_policy.gcp-restrict-machine-type.id}",
"${tfe_sentinel_policy.require-modules-from-pmr.id}",
]
}
resource "tfe_policy_set" "production" {
name = "production"
description = "Policies that should be enforced on production infrastructure."
organization = "${var.tfe_organization}"
policy_ids = [
"${tfe_sentinel_policy.aws-restrict-instance-type-prod.id}",
]
workspace_external_ids = [
"${local.workspaces["app-prod"]}",
]
}
resource "tfe_policy_set" "development" {
name = "development"
description = "Policies that should be enforced on development or scratch infrastructure."
organization = "${var.tfe_organization}"
policy_ids = [
"${tfe_sentinel_policy.aws-restrict-instance-type-dev.id}",
]
workspace_external_ids = [
"${local.workspaces["app-dev"]}",
"${local.workspaces["app-dev-sandbox-bennett"]}",
]
}
resource "tfe_policy_set" "sentinel" {
name = "sentinel"
description = "Policies that watch the watchman. Enforced only on the workspace that manages policies."
organization = "${var.tfe_organization}"
policy_ids = [
"${tfe_sentinel_policy.tfe_policies_only.id}",
]
workspace_external_ids = [
"${local.workspaces["tfe-policies"]}",
]
}
# Test/experimental policies:
resource "tfe_sentinel_policy" "passthrough" {
name = "passthrough"
description = "Just passing through! Always returns 'true'."
organization = "${var.tfe_organization}"
policy = "${file("./passthrough.sentinel")}"
enforce_mode = "advisory"
}
# Sentinel management policies:
resource "tfe_sentinel_policy" "tfe_policies_only" {
name = "tfe_policies_only"
description = "The Terraform config that manages Sentinel policies must not use the authenticated tfe provider to manage non-Sentinel resources."
organization = "${var.tfe_organization}"
policy = "${file("./tfe_policies_only.sentinel")}"
enforce_mode = "hard-mandatory"
}
# Networking policies:
resource "tfe_sentinel_policy" "aws-block-allow-all-cidr" {
name = "aws-block-allow-all-cidr"
description = "Avoid nasty firewall mistakes (AWS version)"
organization = "${var.tfe_organization}"
policy = "${file("./aws-block-allow-all-cidr.sentinel")}"
enforce_mode = "hard-mandatory"
}
resource "tfe_sentinel_policy" "azurerm-block-allow-all-cidr" {
name = "azurerm-block-allow-all-cidr"
description = "Avoid nasty firewall mistakes (Azure version)"
organization = "${var.tfe_organization}"
policy = "${file("./azurerm-block-allow-all-cidr.sentinel")}"
enforce_mode = "hard-mandatory"
}
resource "tfe_sentinel_policy" "gcp-block-allow-all-cidr" {
name = "gcp-block-allow-all-cidr"
description = "Avoid nasty firewall mistakes (GCP version)"
organization = "${var.tfe_organization}"
policy = "${file("./gcp-block-allow-all-cidr.sentinel")}"
enforce_mode = "hard-mandatory"
}
# Compute instance policies:
resource "tfe_sentinel_policy" "aws-restrict-instance-type-dev" {
name = "aws-restrict-instance-type-dev"
description = "Limit AWS instances to approved list (for dev infrastructure)"
organization = "${var.tfe_organization}"
policy = "${file("./aws-restrict-instance-type-dev.sentinel")}"
enforce_mode = "soft-mandatory"
}
resource "tfe_sentinel_policy" "aws-restrict-instance-type-prod" {
name = "aws-restrict-instance-type-prod"
description = "Limit AWS instances to approved list (for prod infrastructure)"
organization = "${var.tfe_organization}"
policy = "${file("./aws-restrict-instance-type-prod.sentinel")}"
enforce_mode = "soft-mandatory"
}
resource "tfe_sentinel_policy" "aws-restrict-instance-type-default" {
name = "aws-restrict-instance-type-default"
description = "Limit AWS instances to approved list"
organization = "${var.tfe_organization}"
policy = "${file("./aws-restrict-instance-type-default.sentinel")}"
enforce_mode = "soft-mandatory"
}
resource "tfe_sentinel_policy" "azurerm-restrict-vm-size" {
name = "azurerm-restrict-vm-size"
description = "Limit Azure instances to approved list"
organization = "${var.tfe_organization}"
policy = "${file("./azurerm-restrict-vm-size.sentinel")}"
enforce_mode = "soft-mandatory"
}
resource "tfe_sentinel_policy" "gcp-restrict-machine-type" {
name = "gcp-restrict-machine-type"
description = "Limit GCP instances to approved list"
organization = "${var.tfe_organization}"
policy = "${file("./gcp-restrict-machine-type.sentinel")}"
enforce_mode = "soft-mandatory"
}
# Policy that requires modules to come from Private Module Registry
data "template_file" "require-modules-from-pmr" {
template = "${file("./require-modules-from-pmr.sentinel")}"
vars {
hostname = "${var.tfe_hostname}"
organization = "${var.tfe_organization}"
}
}
resource "tfe_sentinel_policy" "require-modules-from-pmr" {
name = "require-modules-from-pmr"
description = "Require all modules to come from the Private Module Registy of the current org"
organization = "${var.tfe_organization}"
policy = "${data.template_file.require-modules-from-pmr.rendered}"
enforce_mode = "hard-mandatory"
}