-
Notifications
You must be signed in to change notification settings - Fork 1
/
environments.tf
73 lines (63 loc) · 2.54 KB
/
environments.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
locals {
// Lookup environment name using workspace context unless explicitly overridden.
// This is useful for `default` workspace scenarios where we're not using the
// terraform workspaces features.
current_env_name = coalesce(var.environment_override, lookup(local.workspace_map, "environment"))
// Lookup build and deployment names from workspace context
current_build_name = lookup(local.workspace_map, "build")
current_deployment_name = lookup(local.workspace_map, "deployment")
// Get and normalize environment configuration
environments = {
for k, v in lookup(local.current_config, "environments", {}) : k => {
// Environment name
name = k
// Fully qualified domain for the environment
domain = lower(format("%s.%s", join(".", compact([
for part in split(".", local.domain_template) :
format(replace(part, format("/%s/", local.template_keys), "%s"), [
for value in flatten(regexall(local.template_keys, part)) :
lookup(merge(local.template_vars, {
environment = k
build = ""
deployment = ""
}), value)
]...)
])), local.root_domain))
// Network details for environment
network = merge(lookup(v, "regional", false) ? {
cidr_blocks = lookup(lookup(v, data.aws_region.this.name, {}), "cidr_blocks", [])
subnets = lookup(lookup(v, data.aws_region.this.name, {}), "subnets", {})
} : {
cidr_blocks = lookup(v, "cidr_blocks", [])
subnets = lookup(v, "subnets", {})
})
// Custom properties for the environment
custom = lookup(v, "custom", {})
}
}
// Load current environment from config based on workspace
current_environment = merge({
// Environment name
name = local.current_env_name
// Virtual build name
build = local.current_build_name
// Deployment name
deployment = local.current_deployment_name
// Fully qualified domain for the environment
domain = lower(format("%s.%s", join(".", compact([
for part in split(".", local.domain_template) :
format(replace(part, format("/%s/", local.template_keys), "%s"), [
for value in flatten(regexall(local.template_keys, part)) :
lookup(merge(local.template_vars, {
build = ""
deployment = ""
}), value)
]...)
])), local.root_domain))
// Empty network configuration
network = {
cidr_blocks = []
subnets = {}
}
}, lookup(local.environments, local.current_env_name, {}))
}