Skip to content

Commit 0bf5cb5

Browse files
committed
add form_type terraform example file
1 parent cb82b2e commit 0bf5cb5

File tree

1 file changed

+210
-0
lines changed

1 file changed

+210
-0
lines changed

testdata/formtypes/main.tf

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
locals {
10+
string_opts = [
11+
{
12+
name = "one"
13+
value = "one"
14+
description = "This is option one"
15+
icon = "/emojis/0031-fe0f-20e3.png"
16+
},
17+
{
18+
name = "two"
19+
value = "two"
20+
description = "This is option two"
21+
icon = "/emojis/0032-fe0f-20e3.png"
22+
},
23+
{
24+
name = "three"
25+
value = "three"
26+
description = "This is option three"
27+
icon = "/emojis/0033-fe0f-20e3.png"
28+
}
29+
]
30+
}
31+
32+
data "coder_parameter" "string_opts_default" {
33+
// should be 'radio'
34+
name = "string_opts"
35+
display_name = "String"
36+
description = "String with options"
37+
type = "string"
38+
order = 1
39+
icon = "/emojis/0031-fe0f-20e3.png"
40+
41+
dynamic "option" {
42+
for_each = local.string_opts
43+
content {
44+
name = option.value.name
45+
value = option.value.value
46+
description = option.value.description
47+
icon = option.value.icon
48+
}
49+
}
50+
}
51+
52+
data "coder_parameter" "string_opts_dropdown" {
53+
name = "string_opts_default"
54+
display_name = "String"
55+
description = "String with options and default"
56+
type = "string"
57+
form_type = "dropdown"
58+
order = 2
59+
icon = "/emojis/0031-fe0f-20e3.png"
60+
61+
dynamic "option" {
62+
for_each = local.string_opts
63+
content {
64+
name = option.value.name
65+
value = option.value.value
66+
description = option.value.description
67+
icon = option.value.icon
68+
}
69+
}
70+
}
71+
72+
data "coder_parameter" "string_without_opts" {
73+
// should be 'input'
74+
name = "string_without_opts"
75+
display_name = "String"
76+
description = "String without options"
77+
type = "string"
78+
order = 3
79+
icon = "/emojis/0031-fe0f-20e3.png"
80+
}
81+
82+
data "coder_parameter" "bool_with_opts" {
83+
// should be 'radio'
84+
name = "bool_with_opts"
85+
display_name = "Bool"
86+
description = "Bool with options"
87+
type = "bool"
88+
order = 4
89+
icon = "/emojis/0031-fe0f-20e3.png"
90+
default = false
91+
92+
option {
93+
name = "Yes"
94+
value = true
95+
description = "Yes, I agree to the terms."
96+
}
97+
98+
option {
99+
name = "No"
100+
value = false
101+
description = "No, I do not agree to the terms."
102+
}
103+
}
104+
105+
data "coder_parameter" "bool_without_opts" {
106+
// should be 'checkbox'
107+
name = "bool_without_opts"
108+
display_name = "Bool"
109+
description = "Bool without options"
110+
type = "bool"
111+
order = 5
112+
icon = "/emojis/0031-fe0f-20e3.png"
113+
default = false
114+
}
115+
116+
data "coder_parameter" "bool_without_opts_switch" {
117+
name = "bool_without_opts_switch"
118+
display_name = "Bool"
119+
description = "Bool without options, but it is a switch"
120+
type = "bool"
121+
form_type = "switch"
122+
order = 6
123+
icon = "/emojis/0031-fe0f-20e3.png"
124+
default = false
125+
}
126+
127+
data "coder_parameter" "list_string_options" {
128+
// should be radio
129+
name = "list_string_options"
130+
display_name = "List(String)"
131+
description = "list(string) with options"
132+
type = "list(string)"
133+
order = 7
134+
icon = "/emojis/0031-fe0f-20e3.png"
135+
default = jsonencode(["purple", "blue", "green", "red", "orange"])
136+
137+
option {
138+
name = "All"
139+
description = "All the colors"
140+
value = jsonencode(["purple", "blue", "green", "red", "orange"])
141+
}
142+
143+
option {
144+
name = "Bluish Colors"
145+
description = "Colors that are kinda blue"
146+
value = jsonencode(["purple", "blue"])
147+
}
148+
149+
option {
150+
name = "Redish Colors"
151+
description = "Colors that are kinda red"
152+
value = jsonencode(["red", "orange"])
153+
}
154+
}
155+
156+
data "coder_parameter" "list_string_without_options" {
157+
// should be tag-select
158+
name = "list_string_without_options"
159+
display_name = "List(String)"
160+
description = "list(string) with options"
161+
type = "list(string)"
162+
order = 8
163+
icon = "/emojis/0031-fe0f-20e3.png"
164+
default = jsonencode(["purple", "blue", "green", "red", "orange"])
165+
}
166+
167+
data "coder_parameter" "list_string_multi_select_options" {
168+
// should be multi-select
169+
name = "list_string_multi_select_options"
170+
display_name = "List(String)"
171+
description = "list(string) with options"
172+
type = "list(string)"
173+
form_type = "multi-select"
174+
order = 8
175+
icon = "/emojis/0031-fe0f-20e3.png"
176+
default = jsonencode(["blue", "green", "red"])
177+
178+
option {
179+
name = "Blue"
180+
value = "blue"
181+
description = "Like the sky."
182+
}
183+
184+
option {
185+
name = "Red"
186+
value = "red"
187+
description = "Like a rose."
188+
}
189+
190+
option {
191+
name = "Green"
192+
value = "green"
193+
description = "Like the grass."
194+
}
195+
196+
option {
197+
name = "Purple"
198+
value = "purple"
199+
description = "Like a grape."
200+
}
201+
202+
option {
203+
name = "Orange"
204+
value = "orange"
205+
description = "Like the fruit."
206+
}
207+
}
208+
209+
210+

0 commit comments

Comments
 (0)