-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmanagement-settings.tf
410 lines (356 loc) · 13.4 KB
/
management-settings.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
locals {
##this can be changed to switch between A/B github connection.
tfc_oauth_token = tfe_oauth_client.github-b.oauth_token_id
}
provider "tfe" {
token = var.tfe_token
}
provider "vault" {
}
provider "github" {
token = var.github_personal_token
}
resource "tfe_organization_default_settings" "org_default" {
organization = var.organization
default_execution_mode = "remote"
}
//create an agent pool that has to be run locally
resource "tfe_agent_pool" "local-agent-pool" {
name = "local-agent-pool"
organization = var.organization
}
resource "tfe_agent_token" "local-agent-pool-token" {
agent_pool_id = tfe_agent_pool.local-agent-pool.id
description = "docker-agent-token"
}
resource "tfe_agent_pool" "agent-pools" {
for_each = local.inputteammap
name = "agent-pool-for-${each.value.name}"
organization = "yulei"
}
resource "tfe_agent_token" "agent-tokens" {
for_each = local.inputteammap
agent_pool_id = tfe_agent_pool.agent-pools[each.value.name].id
description = "agent-token-for-${each.value.name}"
}
resource "tfe_workspace" "tfc-config-as-code" {
description = "Workspace for managing my own TFC orgnisation's configuration as code, using terraform."
allow_destroy_plan = true
auto_apply = true
# execution_mode = "remote"
file_triggers_enabled = true
# global_remote_state = false
project_id = tfe_project.projects["Management"].id
name = "tfc-config-as-code"
organization = var.organization
queue_all_runs = false
# remote_state_consumer_ids = []
speculative_enabled = true
structured_run_output_enabled = true
tag_names = ["tfc", "internal", "management"]
terraform_version = var.v1latest
trigger_prefixes = []
vcs_repo {
identifier = "ausmartway/tfc-config-as-code"
ingress_submodules = false
oauth_token_id = local.tfc_oauth_token
}
}
resource "tfe_oauth_client" "github-a" {
organization = var.organization
api_url = "https://api.github.com"
http_url = "https://github.com"
oauth_token = var.github_personal_token
service_provider = "github"
}
resource "tfe_oauth_client" "github-b" {
organization = var.organization
api_url = "https://api.github.com"
http_url = "https://github.com"
oauth_token = var.github_personal_token
service_provider = "github"
}
resource "tfe_oauth_client" "gitlab-a" {
organization = var.organization
api_url = "https://gitlab.com/api/v4"
http_url = "https://gitlab.com"
oauth_token = var.gitlab_personal_token
service_provider = "gitlab_hosted"
}
resource "tfe_oauth_client" "gitlab-b" {
organization = var.organization
api_url = "https://gitlab.com/api/v4"
http_url = "https://gitlab.com"
oauth_token = var.gitlab_personal_token
service_provider = "gitlab_hosted"
}
resource "tfe_workspace" "tfc-credential-injector" {
allow_destroy_plan = true
auto_apply = true
description = "A workspace that will inject aws and azure credentials to other workspaces automaticly."
# execution_mode = "remote"
file_triggers_enabled = false
# global_remote_state = false
project_id = tfe_project.projects["Management"].id
name = "tfc-credential-injector"
organization = var.organization
queue_all_runs = true
# remote_state_consumer_ids = []
speculative_enabled = true
structured_run_output_enabled = true
tag_names = ["internal", "tfc", "management"]
terraform_version = var.v1latest
trigger_prefixes = []
vcs_repo {
identifier = "ausmartway/tfc-credential-injector"
ingress_submodules = false
oauth_token_id = local.tfc_oauth_token
}
}
resource "tfe_workspace" "tfc-notification-configurator" {
allow_destroy_plan = true
auto_apply = true
description = "A workspace that will configure TFC/E notifications based on tag automaticly."
# execution_mode = "remote"
file_triggers_enabled = false
# global_remote_state = false
project_id = tfe_project.projects["Management"].id
name = "tfc-notification-configurator"
organization = var.organization
queue_all_runs = true
# remote_state_consumer_ids = []
speculative_enabled = true
structured_run_output_enabled = true
tag_names = ["internal", "tfc", "management"]
terraform_version = var.v1latest
trigger_prefixes = []
vcs_repo {
identifier = "ausmartway/tfc-notification-configurator"
ingress_submodules = false
oauth_token_id = local.tfc_oauth_token
}
}
resource "tfe_workspace" "tfc-policyset-attacher" {
allow_destroy_plan = true
auto_apply = true
description = "A workspace that will configure TFC/E notifications based on tag automaticly."
file_triggers_enabled = false
# global_remote_state = false
project_id = tfe_project.projects["Management"].id
name = "tfc-policyset-attacher"
organization = var.organization
queue_all_runs = true
# remote_state_consumer_ids = []
speculative_enabled = true
structured_run_output_enabled = true
tag_names = ["internal", "tfc", "management"]
terraform_version = var.v1latest
trigger_prefixes = []
vcs_repo {
identifier = "ausmartway/tfc-policyset-attacher"
ingress_submodules = false
oauth_token_id = local.tfc_oauth_token
}
}
resource "tfe_variable" "tfc-policyset-attacher-orgnization" {
key = "organization"
value = var.organization
category = "terraform"
workspace_id = tfe_workspace.tfc-policyset-attacher.id
description = "TFC/E organization"
}
resource "tfe_variable" "tfc-policyset-attacher-tfc_oauth_token_id" {
key = "tfc_oauth_token_id"
value = local.tfc_oauth_token
category = "terraform"
workspace_id = tfe_workspace.tfc-policyset-attacher.id
description = "VCS connection oauth token id"
}
## triggers credential-injector, notification-configurator and policy-attacher after successful apply of config-as-code
## Those three should only be triggered after config-as-code so that they can get full list of workspaces that have certain tags.
resource "tfe_run_trigger" "auto_trigger_tfc-credential-injector" {
workspace_id = tfe_workspace.tfc-credential-injector.id
sourceable_id = tfe_workspace.tfc-config-as-code.id
}
resource "tfe_run_trigger" "auto_trigger_tfc-notification-configurator" {
workspace_id = tfe_workspace.tfc-notification-configurator.id
sourceable_id = tfe_workspace.tfc-config-as-code.id
}
resource "tfe_run_trigger" "auto_trigger_tfc-policy-attacher" {
workspace_id = tfe_workspace.tfc-policyset-attacher.id
sourceable_id = tfe_workspace.tfc-config-as-code.id
}
resource "tfe_variable_set" "azure" {
name = "Global Varset for Azure"
description = "Variable set applied to all workspaces with tag azure and autoinjection."
global = false
organization = var.organization
}
## Add HCP Vault admin token to global variable set
resource "tfe_variable_set" "hcp_admin_token" {
name = "hcp_admin_token"
description = "Variable set applied to all workspaces with tag azure and autoinjection."
global = false
organization = var.organization
}
## Add HCP Vault admin token ENV variables
resource "tfe_variable" "hcp_client_id" {
key = "HCP_CLIENT_ID"
value = ""
category = "env"
variable_set_id = tfe_variable_set.hcp_admin_token.id
sensitive = true
description = "hcp_admin_token"
}
## Add workload identity required variables into global variable set
resource "tfe_variable_set" "enable_workload_identity_auth_to_hcp_vault" {
name = "enable_workload_identity_auth_to_vault_hcp"
description = "Variable set that enables TFC workload identity login into hcp Vault."
global = false
organization = var.organization
}
resource "tfe_variable" "hcp_vault_addr" {
key = "TFC_VAULT_ADDR"
value = "https://vault-cluster-public-vault-bb7b95a8.c950b5f7.z1.hashicorp.cloud:8200"
category = "env"
variable_set_id = tfe_variable_set.enable_workload_identity_auth_to_hcp_vault.id
description = "hcp vault address"
}
resource "tfe_variable" "hcp_vault_namespace" {
key = "TFC_VAULT_NAMESPACE"
value = "admin"
category = "env"
variable_set_id = tfe_variable_set.enable_workload_identity_auth_to_hcp_vault.id
description = "hcp vault namespace"
}
resource "tfe_variable" "hcp_vault_role" {
key = "TFC_VAULT_RUN_ROLE"
value = "tfc_default"
category = "env"
variable_set_id = tfe_variable_set.enable_workload_identity_auth_to_hcp_vault.id
description = "hcp vault role"
}
resource "tfe_variable" "hcp_vault_auth_path" {
key = "TFC_VAULT_AUTH_PATH"
value = "terraform_cloud"
category = "env"
variable_set_id = tfe_variable_set.enable_workload_identity_auth_to_hcp_vault.id
description = "hcp vault auth path"
}
resource "tfe_variable" "tfc_vault_provider_auth" {
key = "TFC_VAULT_PROVIDER_AUTH"
value = true
category = "env"
variable_set_id = tfe_variable_set.enable_workload_identity_auth_to_hcp_vault.id
description = "hcp vault provider auth"
}
resource "tfe_variable" "tfc_vault_workload_identity_audience" {
key = "TFC_VAULT_WORKLOAD_IDENTITY_AUDIENCE"
value = "eXVsZWkncyBWYXVsdAo="
category = "env"
variable_set_id = tfe_variable_set.enable_workload_identity_auth_to_hcp_vault.id
description = "hcp vault workload identity audience"
}
resource "tfe_variable" "hcp_client_secret" {
key = "HCP_CLIENT_SECRET"
value = ""
category = "env"
variable_set_id = tfe_variable_set.hcp_admin_token.id
sensitive = true
description = "hcp_admin_token"
}
resource "tfe_variable" "boundary_admin_username" {
key = "admin_username"
value = ""
category = "terraform"
variable_set_id = tfe_variable_set.hcp_admin_token.id
sensitive = true
description = "boundary initial admin username"
}
resource "tfe_variable" "boundary_admin_password" {
key = "admin_password"
value = ""
category = "terraform"
variable_set_id = tfe_variable_set.hcp_admin_token.id
sensitive = true
description = "boundary initial admin password"
}
data "hcp_vault_secrets_secret" "azure_client_id" {
app_name = "azure"
secret_name = "ARM_CLIENT_ID"
}
data "hcp_vault_secrets_secret" "azure_client_secret" {
app_name = "azure"
secret_name = "ARM_CLIENT_SECRET"
}
data "hcp_vault_secrets_secret" "azure_subscription_id" {
app_name = "azure"
secret_name = "ARM_SUBSCRIPTION_ID"
}
data "hcp_vault_secrets_secret" "azure_tenant_id" {
app_name = "azure"
secret_name = "ARM_TENANT_ID"
}
# data "vault_generic_secret" "azure" {
# path = "kv/azure"
# }
## Add Azure credentials ENV variables
resource "tfe_variable" "azure_subscription_id" {
key = "ARM_SUBSCRIPTION_ID"
value = data.hcp_vault_secrets_secret.azure_subscription_id.secret_value
category = "env"
variable_set_id = tfe_variable_set.azure.id
description = "Azure Subscription Id"
}
resource "tfe_variable" "azure_tenant_id" {
key = "ARM_TENANT_ID"
value = data.hcp_vault_secrets_secret.azure_tenant_id.secret_value
category = "env"
variable_set_id = tfe_variable_set.azure.id
description = "Azure Tenant Id"
}
resource "tfe_variable" "azure_client_id" {
key = "ARM_CLIENT_ID"
value = data.hcp_vault_secrets_secret.azure_client_id.secret_value
category = "env"
variable_set_id = tfe_variable_set.azure.id
description = "Azure Client Id"
}
resource "tfe_variable" "azure_client_secret" {
key = "ARM_CLIENT_SECRET"
value = data.hcp_vault_secrets_secret.azure_client_secret.secret_value
category = "env"
variable_set_id = tfe_variable_set.azure.id
sensitive = true
description = "Azure Client Secret"
}
resource "tfe_organization_run_task" "snyk" {
organization = var.organization
url = "https://api.snyk.io/v1/terraform-cloud/2df223b0-f339-4303-99ce-955159121971"
hmac_key = var.snyk_hmac_key
name = "snyk"
enabled = true
}
resource "tfe_organization_run_task" "infracost" {
organization = var.organization
url = "https://dashboard.api.infracost.io/hooks/9fef9204-96e8-466b-8e84-731a04552ec3"
hmac_key = var.infracost_hmac_key
name = "infracost"
enabled = true
}
data "tfe_workspace_ids" "customerfacing" {
tag_names = ["customerfacing"]
organization = var.organization
}
resource "tfe_workspace_run_task" "snyk" {
for_each = data.tfe_workspace_ids.customerfacing.ids
workspace_id = each.value
task_id = resource.tfe_organization_run_task.snyk.id
enforcement_level = "advisory"
}
resource "tfe_workspace_run_task" "infracost" {
for_each = data.tfe_workspace_ids.customerfacing.ids
workspace_id = each.value
task_id = resource.tfe_organization_run_task.infracost.id
enforcement_level = "advisory"
}