Skip to content

Instantly share code, notes, and snippets.

@arehmandev
Last active August 11, 2021 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arehmandev/5a850b6a17c7b82fb3782608f70b0a06 to your computer and use it in GitHub Desktop.
Save arehmandev/5a850b6a17c7b82fb3782608f70b0a06 to your computer and use it in GitHub Desktop.
variable "subnets" {
type = list(any)
default = ["subnet-a", "subnet-b", "subnet-c"]
}
variable "instances" {
default = {
TEST1 = {
sg = ["example1"]
}
TEST2 = {
sg = ["example2"]
}
TEST3 = {
sg = ["example3"]
}
}
}
resource "random_integer" "subnet_picker" {
for_each = var.instances
keepers = {
uuid = uuid()
}
min = 0
max = length(var.subnets) - 1
}
resource "null_resource" "echo" {
for_each = var.instances
triggers = {
random_int = random_integer.subnet_picker[each.key].result
}
provisioner "local-exec" {
command = "echo 'Instance - ${each.key} - subnet ${var.subnets[random_integer.subnet_picker[each.key].result]}'"
}
}
variable "subnets" {
type = list(any)
default = ["subnet-a", "subnet-b", "subnet-c"]
}
resource "random_integer" "subnet_picker" {
keepers = {
uuid = uuid()
}
min = 0
max = length(var.subnets) - 1
}
resource "null_resource" "echo" {
triggers = {
random_int = random_integer.subnet_picker.result
}
provisioner "local-exec" {
command = "echo ${var.subnets[random_integer.subnet_picker.result]}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment