Last active
August 11, 2021 14:21
-
-
Save arehmandev/5a850b6a17c7b82fb3782608f70b0a06 to your computer and use it in GitHub Desktop.
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 "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]}'" | |
} | |
} |
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 "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