Skip to content

Commit ce9d29f

Browse files
committed
add wordle demo
1 parent 9cc59a9 commit ce9d29f

File tree

3 files changed

+159
-1
lines changed

3 files changed

+159
-1
lines changed

parameter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func RichParameters(modules terraform.Modules) ([]types.Parameter, hcl.Diagnosti
5151
Detail: detail.String(),
5252
})
5353
}
54-
5554
}
5655

56+
types.SortParameters(params)
5757
return params, diags
5858
}

testdata/wordle/checker/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
variable "input" {
2+
type = string
3+
}
4+
5+
variable "correct" {
6+
type = string
7+
}
8+
9+
output "result" {
10+
value = join("", [
11+
for i in range(0, length(var.correct)) : (
12+
substr(var.input, i, 1) == substr(var.correct, i, 1) ? "#" : "_"
13+
)
14+
])
15+
}

testdata/wordle/main.tf

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
locals {
10+
correct = "lasso" // March 17, 2025
11+
validation = {
12+
regex = "^[a-zA-Z]{5}$"
13+
error = "You must enter a 5 letter word."
14+
}
15+
}
16+
17+
module "word_one" {
18+
source = "./checker"
19+
input = data.coder_parameter.first.value
20+
correct = local.correct
21+
}
22+
23+
data "coder_parameter" "first" {
24+
name = "first"
25+
display_name = "First word"
26+
description = "Enter a 5 letter word"
27+
type = "string"
28+
order = 1
29+
30+
validation {
31+
regex = local.validation.regex
32+
error = local.validation.error
33+
}
34+
}
35+
36+
// ---
37+
module "word_two" {
38+
source = "./checker"
39+
input = data.coder_parameter.second[0].value
40+
correct = local.correct
41+
}
42+
43+
data "coder_parameter" "second" {
44+
count = 1
45+
# count = length(data.coder_parameter.first.value) == 5 ? 1 : 0
46+
47+
name = "second"
48+
display_name = "Second word"
49+
description = "Previous word matches: ${module.word_one.result}"
50+
type = "string"
51+
order = 2
52+
53+
validation {
54+
regex = local.validation.regex
55+
error = local.validation.error
56+
}
57+
}
58+
59+
// ---
60+
module "word_three" {
61+
source = "./checker"
62+
input = data.coder_parameter.third[0].value
63+
correct = local.correct
64+
}
65+
66+
data "coder_parameter" "third" {
67+
count = 1
68+
# count = try(length(data.coder_parameter.second[0].value) == 5, false) ? 1 : 0
69+
70+
name = "third"
71+
display_name = "Third word"
72+
description = "Previous word matches: ${module.word_two.result}"
73+
type = "string"
74+
order = 3
75+
76+
validation {
77+
regex = local.validation.regex
78+
error = local.validation.error
79+
}
80+
}
81+
82+
// ---
83+
module "word_four" {
84+
source = "./checker"
85+
input = data.coder_parameter.fourth[0].value
86+
correct = local.correct
87+
}
88+
89+
data "coder_parameter" "fourth" {
90+
count = 1
91+
name = "fourth"
92+
display_name = "Fourth word"
93+
description = "Previous word matches: ${module.word_three.result}"
94+
type = "string"
95+
order = 4
96+
97+
validation {
98+
regex = local.validation.regex
99+
error = local.validation.error
100+
}
101+
}
102+
103+
// ---
104+
module "word_five" {
105+
source = "./checker"
106+
input = data.coder_parameter.fifth[0].value
107+
correct = local.correct
108+
}
109+
110+
data "coder_parameter" "fifth" {
111+
count = 1
112+
name = "fifth"
113+
display_name = "Fifth word"
114+
description = "Previous word matches: ${module.word_four.result}"
115+
type = "string"
116+
order = 5
117+
118+
validation {
119+
regex = local.validation.regex
120+
error = local.validation.error
121+
}
122+
}
123+
124+
// ---
125+
# module "word_six" {
126+
# source = "./checker"
127+
# input = data.coder_parameter.fifth.value
128+
# correct = local.correct
129+
# }
130+
131+
data "coder_parameter" "six" {
132+
count = 1
133+
name = "sixth"
134+
display_name = "Sixth word"
135+
description = "Previous word matches: ${module.word_five.result}"
136+
type = "string"
137+
order = 6
138+
139+
validation {
140+
regex = local.validation.regex
141+
error = local.validation.error
142+
}
143+
}

0 commit comments

Comments
 (0)