forked from ausmartway/tfc-config-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanagement-workspaces.tf
197 lines (174 loc) · 6.58 KB
/
management-workspaces.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
##test123
terraform {
required_version = ">= 1.0"
required_providers {
tfe = ">= 0.26.1"
github = {
source = "integrations/github"
version = "~> 4.0"
}
}
}
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 "github" {
token = var.github_personal_token
}
//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_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
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
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
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."
execution_mode = "remote"
file_triggers_enabled = false
global_remote_state = false
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
}