Created
April 4, 2025 17:41
-
-
Save jfhbrook/4cc9458c8f6c755bac65988f1d6c6032 to your computer and use it in GitHub Desktop.
Fizzbuzz in Terraform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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