Skip to content

Instantly share code, notes, and snippets.

@jfhbrook
Created April 4, 2025 17:41
Show Gist options
  • Save jfhbrook/4cc9458c8f6c755bac65988f1d6c6032 to your computer and use it in GitHub Desktop.
Save jfhbrook/4cc9458c8f6c755bac65988f1d6c6032 to your computer and use it in GitHub Desktop.
Fizzbuzz in Terraform
locals {
numbers = range(1, 101)
keys = [for n in local.numbers : tostring(n)]
}
module "fizzbuzz" {
source = "./modules/fizzbuzz"
for_each = toset(local.keys)
number = tonumber(each.key)
}
output "fizzbuzz" {
value = [for key, fb in module.fizzbuzz : fb.fizzbuzz]
}
variable "number" {
type = number
description = "a number"
}
locals {
fizzbuzz = var.number % 15 == 0 ? "fizzbuzz" : (
var.number % 3 == 0 ? "fizz" : (
var.number % 5 == 0 ? "buzz" : "${var.number}")
)
}
output "fizzbuzz" {
value = local.fizzbuzz
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment