-
Notifications
You must be signed in to change notification settings - Fork 1
/
workspace.tf
83 lines (72 loc) · 2.35 KB
/
workspace.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
locals {
// Get workspace configuration data
workspace_config = lookup(local.current_config, "workspace", {})
// Format for workspace prefix
workspace_prefix_format = lookup(
local.workspace_config,
"prefix_format",
coalesce(var.workspace_prefix_format, "[a-zA-Z0-9-]+"),
)
// Format for environment name
workspace_env_format = lookup(
local.workspace_config,
"environment_format",
coalesce(var.workspace_env_format, "[a-zA-Z0-9]+"),
)
// Format for build name
workspace_build_format = lookup(
local.workspace_config,
"build_format",
coalesce(var.workspace_build_format, "[a-zA-Z0-9-]+"),
)
// Format for deployment name
workspace_deployment_format = lookup(
local.workspace_config,
"deployment_format",
coalesce(var.workspace_deployment_format, "[a-zA-Z0-9]+"),
)
// Character used to separate workspace
workspace_prefix_separator = lookup(
local.workspace_config,
"prefix_separator",
coalesce(var.workspace_prefix_separator, "-"),
)
// Character used to separate build
workspace_build_separator = lookup(
local.workspace_config,
"build_separator",
coalesce(var.workspace_build_separator, "_"),
)
// Character used to separate deployment
workspace_deployment_separator = lookup(
local.workspace_config,
"deployment_separator",
coalesce(var.workspace_deployment_separator, ":"),
)
// Construct workspace regex from above formats
workspace_regex = format(
"^(?:(?P<prefix>%s)%s)?(?P<environment>%s)(?:%s(?P<build>%s))?(?:%s(?P<deployment>%s))?$",
local.workspace_prefix_format,
local.workspace_prefix_separator,
local.workspace_env_format,
local.workspace_build_separator,
local.workspace_build_format,
local.workspace_deployment_separator,
local.workspace_deployment_format,
)
// Create a map from the workspace regex results
workspace_map = regex(local.workspace_regex, terraform.workspace)
// List of keys not to use in the workspace prefix
reserved_prefix_keys = concat([
"prefix",
], [
for k in keys(local.standard_tags) : lower(k)
])
// Workspace prefix can have named capture groups so we
// want to store those separte so that we can create
// tags from them.
workspace_prefix_map = {
for k, v in local.workspace_map :
k => v if !contains(local.reserved_prefix_keys, lower(k))
}
}