1+ /*
2+
3+ go run ../../cmd/preview/main.go \
4+ -v "\"yellow=[\"\"bay\"\",\"\"sound\"\",\"\"strait\"\", \"\"channel\"\"]\"" \
5+ -v "\"green=[\"\"bungee\"\",\"\"extension\"\",\"\"spinal\"\", \"\"umbilical\"\"]\"" \
6+ -v "\"blue=[\"\"direct\"\",\"\"loud\"\",\"\"vocal\"\", \"\"frank\"\"]\"" \
7+ -v "\"purple=[\"\"ship\"\",\"\"genie\"\",\"\"lighting\"\", \"\"message\"\"]\""
8+ */
9+
110terraform {
211 required_providers {
312 coder = {
@@ -7,16 +16,19 @@ terraform {
716}
817
918locals {
10- word_bank = [
19+ solutions = tomap ({
1120 // Outspoken -- Yellow
12- " direct" , " frank" , " loud" , " vocal" ,
21+ " Outspoken " : [ " direct" , " frank" , " loud" , " vocal" ] ,
1322 // Bodies of water -- Green
14- " bay" , " channel" , " sound" , " strait" ,
23+ " Bodies of water " : [ " bay" , " channel" , " sound" , " strait" ] ,
1524 // Kinds of cords -- Blue
16- " bungee" , " extension" , " spinal" , " umbilical" ,
25+ " Kinds of cords " : [ " bungee" , " extension" , " spinal" , " umbilical" ] ,
1726 // Things in bottles -- Purple
18- " genie" , " lighting" , " message" , " ship"
19- ]
27+ " Things in a bottle" : [" genie" , " lighting" , " message" , " ship" ],
28+ })
29+ # solution_list = [for _, words in local.solutions : words]
30+ word_bank = flatten ([for _, words in local . solutions : words ])
31+
2032
2133 used_words = setunion (
2234 [],
@@ -27,36 +39,68 @@ locals {
2739 )
2840
2941 available_words = setsubtract (toset (local. word_bank ), toset (local. used_words ))
42+
43+ colors = toset ([" yellow" , " green" , " blue" , " purple" ])
44+
45+ solved = length ([for color in local . colors : module . checker [color ]. solved if module . checker [color ]. solved ]) == 4
3046}
3147
48+
49+
50+ module "checker" {
51+ for_each = local. colors
52+ source = " ./checker"
53+ solutions = local. solutions
54+ guess = jsondecode (coalesce (data. coder_parameter . rows [each . value ]. value , " []" ))
55+ }
56+
57+ data "coder_parameter" display {
58+ name = " display"
59+ display_name = local. solved ? " Workspace name" : join (" , " , local. available_words )
60+ description = local. solved ? " Congrats, you won! What is your workspace name?" : " Remaining words"
61+ type = " string"
62+ default = local. solved ? " " : " Keep guessing!"
63+
64+ form_type_metadata = jsonencode ({
65+ disabled = ! local.solved
66+ })
67+ }
68+
69+ output "solved" {
70+ value = local. solved
71+ }
72+
73+
3274data "coder_parameter" "rows" {
33- for_each = toset ([ " yellow " , " green " , " blue " , " purple " ])
75+ for_each = local . colors
3476 name = each. value
77+ display_name = module. checker [each . value ]. title
78+ description = module. checker [each . value ]. description
3579 # name = "rows"
36- display_name = " Row"
3780 type = " list(string)"
3881 form_type = " multi-select"
82+ form_type_metadata = jsonencode ({
83+ disabled = module.checker[each.value].solved
84+ })
3985 default = " []"
86+ order = 11
4087
4188 dynamic "option" {
42- # for_each = tolist(setsubtract(toset(local.word_bank), toset(local.used_words)))
43- for_each = local. available_words
89+ # for_each = toset(local.word_bank)
90+ // Must include the options that are selected, otherwise they are not in
91+ // the option set.
92+ for_each = toset (concat (tolist (local. available_words ), jsondecode (data. coder_parameter . rows [each . value ]. value )))
4493 content {
4594 name = option. value
4695 value = option. value
4796 }
4897 }
49- }
5098
51- output "remaining" {
52- value = local. available_words
99+ validation {
100+ error = " Hey!"
101+ invalid = length (data. coder_parameter . rows [each . value ]. value ) > 4
102+ }
53103}
54104
55- output "used" {
56- value = local. used_words
57- }
58105
59- output "yellow" {
60- value = data. coder_parameter . rows [" yellow" ]. value
61- }
62106
0 commit comments