forked from flowingis/terraform-tfe-workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
115 lines (102 loc) · 3.78 KB
/
main.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
locals {
terraform_variables = { for k, v in var.terraform_variables : k =>
{
value = v
category = "terraform"
description = lookup(var.variables_descriptions, k, null)
}
}
terraform_hcl_variables = { for k, v in var.terraform_hcl_variables : k =>
{
#NOTE: using @osterman trick https://github.com/hashicorp/terraform-provider-tfe/issues/188#issuecomment-700212045
value = replace(jsonencode(v), "/(\".*?\"):/", "$1 = ")
category = "terraform"
hcl = true
description = lookup(var.variables_descriptions, k, null)
}
}
terraform_sensitive_variables = { for k, v in var.terraform_sensitive_variables : k =>
{
value = v
category = "terraform"
description = lookup(var.variables_descriptions, k, null)
sensitive = true
}
}
terraform_hcl_sensitive_variables = { for k, v in var.terraform_hcl_sensitive_variables : k =>
{
#NOTE: using @osterman trick https://github.com/hashicorp/terraform-provider-tfe/issues/188#issuecomment-700212045
value = replace(jsonencode(v), "/(\".*?\"):/", "$1 = ")
category = "terraform"
description = lookup(var.variables_descriptions, k, null)
hcl = true
sensitive = true
}
}
environment_variables = { for k, v in var.environment_variables : k =>
{
value = v
category = "env"
description = lookup(var.variables_descriptions, k, null)
}
}
environment_sensitive_variables = { for k, v in var.environment_sensitive_variables : k =>
{
value = v
category = "env"
description = lookup(var.variables_descriptions, k, null)
sensitive = true
}
}
all_variables = merge(
local.terraform_variables,
local.terraform_hcl_variables,
local.terraform_sensitive_variables,
local.terraform_hcl_sensitive_variables,
local.environment_variables,
local.environment_sensitive_variables
)
}
resource "tfe_workspace" "this" {
name = var.name
organization = var.organization
description = var.description
allow_destroy_plan = var.allow_destroy_plan
auto_apply = var.auto_apply
execution_mode = var.execution_mode
file_triggers_enabled = var.file_triggers_enabled
global_remote_state = var.global_remote_state
remote_state_consumer_ids = var.remote_state_consumer_ids
queue_all_runs = var.queue_all_runs
speculative_enabled = var.speculative_enabled
structured_run_output_enabled = var.structured_run_output_enabled
ssh_key_id = var.ssh_key_id
terraform_version = var.terraform_version
trigger_prefixes = var.trigger_prefixes
tag_names = var.tag_names
working_directory = var.working_directory
dynamic "vcs_repo" {
for_each = length(var.vcs_repository_identifier) > 0 && length(var.oauth_token_id) > 0 ? [1] : []
content {
identifier = var.vcs_repository_identifier
branch = var.vcs_repository_branch
ingress_submodules = var.vcs_repository_ingress_submodules
oauth_token_id = var.oauth_token_id
}
}
}
resource "tfe_variable" "this" {
for_each = local.all_variables
key = each.key
value = each.value.value
hcl = try(each.value.hcl, null)
category = each.value.category
description = try(each.value.description, null)
sensitive = try(each.value.sensitive, false)
workspace_id = tfe_workspace.this.id
}
resource "tfe_run_trigger" "this" {
count = length(var.run_triggers)
workspace_id = tfe_workspace.this.id
sourceable_id = var.run_triggers[count.index]
}