-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
317 lines (245 loc) · 11 KB
/
main.tf
File metadata and controls
317 lines (245 loc) · 11 KB
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
#############################################
# Root Module - dbt Cloud Resources
#
# Orchestrates all dbt Cloud resources from a YAML file (version: 1; schemas/v1.json).
# Account-scoped resources are created first, then project-scoped resources.
#############################################
#############################################
# YAML Configuration Validation
# All validation logic lives in validation.tf.
# This resource fails at plan time if any errors are found,
# reporting all issues together in one message.
#############################################
resource "terraform_data" "validate_yaml_config" {
lifecycle {
precondition {
condition = length(local._all_validation_errors) == 0
error_message = "dbt Cloud YAML configuration has ${length(local._all_validation_errors)} error(s):\n\n${join("\n\n", [for i, e in local._all_validation_errors : " ${i + 1}. ${e}"])}"
}
}
}
#############################################
# Account-Level Features
#############################################
module "account_features" {
count = try(local.yaml_content.account_features, null) != null ? 1 : 0
source = "./modules/account_features"
features = try(local.yaml_content.account_features, null)
}
#############################################
# Account-Level: Global Connections
#############################################
module "global_connections" {
count = length(try(local.yaml_content.global_connections, [])) > 0 ? 1 : 0
source = "./modules/global_connections"
connections_data = try(local.yaml_content.global_connections, [])
connection_credentials = var.connection_credentials
privatelink_endpoints = try(local.yaml_content.privatelink_endpoints, [])
}
#############################################
# Account-Level: Data lookups (LOOKUP: + GitHub installations)
#############################################
module "data_lookups" {
count = length(local._lookup_connection_ref_strings) > 0 || var.dbt_pat != null ? 1 : 0
source = "./modules/data_lookups"
projects = local.projects
dbt_pat = var.dbt_pat
dbt_host_url = local.dbt_host_url_effective
}
#############################################
# Account-Level: Groups
#############################################
module "groups" {
count = length(try(local.yaml_content.groups, [])) > 0 ? 1 : 0
source = "./modules/groups"
groups_data = try(local.yaml_content.groups, [])
skip_global_project_permissions = var.skip_global_project_permissions
}
#############################################
# Account-Level: User Groups (user ↔ group assignment)
#############################################
module "user_groups" {
count = length(try(local.yaml_content.user_groups, [])) > 0 ? 1 : 0
source = "./modules/user_groups"
user_groups_data = try(local.yaml_content.user_groups, [])
group_ids = length(try(local.yaml_content.groups, [])) > 0 ? module.groups[0].group_ids : {}
}
#############################################
# Account-Level: Notifications
#############################################
module "notifications" {
count = length(try(local.yaml_content.notifications, [])) > 0 ? 1 : 0
source = "./modules/notifications"
notifications_data = try(local.yaml_content.notifications, [])
}
#############################################
# Account-Level: OAuth Configurations
#############################################
module "oauth_configurations" {
count = length(try(local.yaml_content.oauth_configurations, [])) > 0 ? 1 : 0
source = "./modules/oauth_configurations"
oauth_data = try(local.yaml_content.oauth_configurations, [])
oauth_client_secrets = var.oauth_client_secrets
}
#############################################
# Account-Level: IP Restrictions
#############################################
module "ip_restrictions" {
count = length(try(local.yaml_content.ip_restrictions, [])) > 0 ? 1 : 0
source = "./modules/ip_restrictions"
ip_rules_data = try(local.yaml_content.ip_restrictions, [])
}
#############################################
# Project Setup
#############################################
module "project" {
source = "./modules/project"
projects = local.projects
target_name = var.target_name
}
#############################################
# Account-Level: Service Tokens
# Declared after project so permissions[].project_key resolves via project_ids.
#############################################
module "service_tokens" {
count = length(try(local.yaml_content.service_tokens, [])) > 0 ? 1 : 0
source = "./modules/service_tokens"
service_tokens_data = try(local.yaml_content.service_tokens, [])
project_ids = module.project.project_ids
skip_global_project_permissions = var.skip_global_project_permissions
}
#############################################
# Repository Configuration
#############################################
module "repository" {
source = "./modules/repository"
providers = {
dbtcloud = dbtcloud.pat_provider
}
projects = local.projects
project_ids = module.project.project_ids
dbt_pat = var.dbt_pat
enable_gitlab_deploy_token = var.enable_gitlab_deploy_token
github_installation_by_owner = length(module.data_lookups) > 0 ? module.data_lookups[0].github_installation_by_owner : {}
github_installation_fallback_id = length(module.data_lookups) > 0 ? module.data_lookups[0].github_installation_fallback_id : null
privatelink_endpoints = try(local.yaml_content.privatelink_endpoints, [])
}
module "project_repository" {
source = "./modules/project_repository"
project_ids = module.project.project_ids
repository_ids = module.repository.repository_ids
protected_repository_keys = module.repository.protected_repository_keys
}
#############################################
# Extended Attributes (must precede environments)
#############################################
module "extended_attributes" {
count = length(flatten([for p in local.projects : try(p.extended_attributes, [])])) > 0 ? 1 : 0
source = "./modules/extended_attributes"
projects = local.projects
project_ids = module.project.project_ids
}
#############################################
# Credentials
#############################################
module "credentials" {
source = "./modules/credentials"
projects = local.projects
project_ids = module.project.project_ids
token_map = var.token_map
environment_credentials = var.environment_credentials
}
#############################################
# Profiles (before environments when environments use primary_profile_key)
#############################################
module "profiles" {
count = length(flatten([for p in local.projects : try(p.profiles, [])])) > 0 ? 1 : 0
source = "./modules/profiles"
projects = local.projects
project_ids = module.project.project_ids
global_connection_ids = local.global_connection_ids_effective
credential_ids = module.credentials.credential_ids
credential_ids_by_source_id = module.credentials.credential_ids_by_source_id
extended_attribute_ids = length(flatten([for p in local.projects : try(p.extended_attributes, [])])) > 0 ? module.extended_attributes[0].extended_attribute_ids : {}
extended_attribute_ids_by_source_id = length(flatten([for p in local.projects : try(p.extended_attributes, [])])) > 0 ? module.extended_attributes[0].extended_attribute_ids_by_source_id : {}
}
#############################################
# Environments
#############################################
module "environments" {
source = "./modules/environments"
projects = local.projects
project_ids = module.project.project_ids
credential_ids = module.credentials.credential_ids
global_connection_ids = local.global_connection_ids_effective
extended_attribute_ids = length(flatten([for p in local.projects : try(p.extended_attributes, [])])) > 0 ? module.extended_attributes[0].extended_attribute_ids : {}
extended_attribute_ids_by_source_id = length(flatten([for p in local.projects : try(p.extended_attributes, [])])) > 0 ? module.extended_attributes[0].extended_attribute_ids_by_source_id : {}
profile_ids = length(flatten([for p in local.projects : try(p.profiles, [])])) > 0 ? module.profiles[0].profile_ids : {}
}
#############################################
# Jobs
#############################################
module "jobs" {
source = "./modules/jobs"
projects = local.projects
project_ids = module.project.project_ids
environment_ids = module.environments.environment_ids
deployment_types = module.environments.deployment_types
depends_on = [module.environments, module.environment_variables]
}
#############################################
# Environment Variables
#############################################
module "environment_variables" {
source = "./modules/environment_variables"
projects = local.projects
project_ids = module.project.project_ids
token_map = var.token_map
depends_on = [module.environments]
}
#############################################
# Environment Variable Job Overrides
#############################################
module "environment_variable_job_overrides" {
source = "./modules/environment_variable_job_overrides"
projects = local.projects
project_ids = module.project.project_ids
job_ids = module.jobs.job_ids
token_map = var.token_map
depends_on = [module.environment_variables, module.jobs]
}
#############################################
# Lineage Integrations
#############################################
module "lineage_integrations" {
count = length(flatten([for p in local.projects : try(p.lineage_integrations, [])])) > 0 ? 1 : 0
source = "./modules/lineage_integrations"
projects = local.projects
project_ids = module.project.project_ids
lineage_tokens = var.lineage_tokens
}
#############################################
# Project Artefacts (docs job + freshness job links)
#############################################
module "project_artefacts" {
count = length([for p in local.projects : p if try(p.project_artefacts, null) != null]) > 0 ? 1 : 0
source = "./modules/project_artefacts"
projects = local.projects
project_ids = module.project.project_ids
job_ids = module.jobs.job_ids
depends_on = [module.jobs]
}
#############################################
# Semantic Layer
#############################################
module "semantic_layer" {
count = length([
for p in local.projects : p
if try(p.semantic_layer_config, null) != null
]) > 0 ? 1 : 0
source = "./modules/semantic_layer"
projects = local.projects
project_ids = module.project.project_ids
environment_ids = module.environments.environment_ids
depends_on = [module.environments]
}