|
| 1 | +terraform { |
| 2 | + required_providers { |
| 3 | + coder = { |
| 4 | + source = "coder/coder" |
| 5 | + version = "2.4.0-pre0" |
| 6 | + } |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +locals { |
| 11 | + # solution_list = [for _, words in local.solutions : words] |
| 12 | + word_bank = flatten([for _, words in local.solutions : words]) |
| 13 | + |
| 14 | + |
| 15 | + used_words = setunion( |
| 16 | + [], |
| 17 | + jsondecode(data.coder_parameter.rows["yellow"].value), |
| 18 | + jsondecode(data.coder_parameter.rows["green"].value), |
| 19 | + jsondecode(data.coder_parameter.rows["blue"].value), |
| 20 | + jsondecode(data.coder_parameter.rows["purple"].value), |
| 21 | + ) |
| 22 | + |
| 23 | + available_words = setsubtract(toset(local.word_bank), toset(local.used_words)) |
| 24 | + |
| 25 | + |
| 26 | + colors = toset(["yellow", "green", "blue", "purple"]) |
| 27 | + |
| 28 | + solved = length([for color in local.colors : module.checker[color].solved if module.checker[color].solved]) == 4 |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +locals { |
| 33 | + unpadded_items = tolist(local.available_words) |
| 34 | + target_width = 3 |
| 35 | + remainder = length(local.unpadded_items) % local.target_width |
| 36 | + padding_needed = local.remainder == 0 ? 0 : local.target_width - local.remainder |
| 37 | + items = concat(local.unpadded_items, slice(["", "", ""], 0, local.padding_needed)) |
| 38 | + |
| 39 | + # Split into rows of 3 items each |
| 40 | + rows = [ |
| 41 | + for i in range(0, length(local.items), local.target_width) : slice(local.items, i, i + local.target_width) |
| 42 | + ] |
| 43 | + |
| 44 | + # Generate Markdown rows |
| 45 | + markdown_rows = [ |
| 46 | + for row in local.rows : "| ${join(" | ", concat(row, slice(["", "", ""], 0, local.target_width - length(row))))} |" |
| 47 | + ] |
| 48 | + markdown = join("\n", concat( |
| 49 | + ["| | | |", "|--------|--------|--------|"], |
| 50 | + local.markdown_rows |
| 51 | + )) |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | +module "checker" { |
| 56 | + for_each = local.colors |
| 57 | + source = "./checker" |
| 58 | + solutions = local.solutions |
| 59 | + guess = jsondecode(coalesce(data.coder_parameter.rows[each.value].value, "[]")) |
| 60 | +} |
| 61 | + |
| 62 | +data "coder_parameter" display { |
| 63 | + name = "display" |
| 64 | + display_name = local.solved ? "Congrats, you won! You may now hit the switch!" : <<EOM |
| 65 | + Remaining words are below, you cannot use this switch until you solve the puzzle! |
| 66 | +
|
| 67 | + EOM |
| 68 | + |
| 69 | + description = local.solved ? "Hitting the switch enables workspace creation." : <<EOM |
| 70 | +
|
| 71 | + | | | | |
| 72 | + |--|--|--| |
| 73 | +
|
| 74 | +
|
| 75 | + ${local.markdown} |
| 76 | +
|
| 77 | + EOM |
| 78 | + type = "bool" |
| 79 | + form_type = "switch" |
| 80 | + default = local.solved ? false : true |
| 81 | + # default = local.solved ? "" : "Keep guessing!" |
| 82 | + |
| 83 | + styling = jsonencode({ |
| 84 | + disabled = !local.solved |
| 85 | + }) |
| 86 | +} |
| 87 | + |
| 88 | +output "solved" { |
| 89 | + value = local.solved |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | +data "coder_parameter" "rows" { |
| 94 | + for_each = local.colors |
| 95 | + name = each.value |
| 96 | + display_name = module.checker[each.value].title |
| 97 | + description = module.checker[each.value].description |
| 98 | + # name = "rows" |
| 99 | + type = "list(string)" |
| 100 | + form_type = "multi-select" |
| 101 | + styling = jsonencode({ |
| 102 | + disabled = module.checker[each.value].solved |
| 103 | + }) |
| 104 | + default = "[]" |
| 105 | + order = 11 |
| 106 | + |
| 107 | + dynamic "option" { |
| 108 | + # for_each = toset(local.word_bank) |
| 109 | + // Must include the options that are selected, otherwise they are not in |
| 110 | + // the option set. |
| 111 | + for_each = toset(concat(tolist(local.available_words), jsondecode(data.coder_parameter.rows[each.value].value))) |
| 112 | + content { |
| 113 | + name = option.value |
| 114 | + value = option.value |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + # validation { |
| 119 | + # error = "Hey! ${length(data.coder_parameter.rows[each.value].value)}" |
| 120 | + # invalid = true |
| 121 | + # } |
| 122 | +} |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +locals { |
| 128 | + solutions = tomap ({ |
| 129 | + // Yellow |
| 130 | + // head, main, |
| 131 | + "Different Types of Agents": ["Real Estate", "Secret", "AI", "Free"], |
| 132 | + // Green |
| 133 | + // java Swift Go Python |
| 134 | + "Synoynms for Programming Languages": ["Coffee", "Fast", "Move", "Snake"], |
| 135 | + // Blue |
| 136 | + "Ending in Pool": ["Thread", "Talent", "Dead", "Whirl"], |
| 137 | + // Purple |
| 138 | + "Git Version Control": ["Remote", "Main", "Clone", "Checkout"], |
| 139 | + }) |
| 140 | +} |
0 commit comments