Skip to content

Instantly share code, notes, and snippets.

@straubt1
Created September 11, 2020 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save straubt1/500d9b64b4ff6c87fd570564201f8d02 to your computer and use it in GitHub Desktop.
Save straubt1/500d9b64b4ff6c87fd570564201f8d02 to your computer and use it in GitHub Desktop.
Python replacement
locals {
config = {
vm_name_prefix = "mdl"
vm_num_prefix = 1
vm_role = "asrv"
vm_pool_count = 2
vm_servers_per_pool = 2
vm_singleton = false
vm_reserve = true
}
roleLetter = ["a", "b", "c", "d", "e", "f", "g", "h"]
machine_names = [
# If singleton, pool is always 1 regardless (this is just a safeguard)
for pool in range(0, local.config.vm_singleton ? 1 : local.config.vm_pool_count) : [
for server in range(0, local.config.vm_servers_per_pool) : [
format("%s-%s%s%03d%s",
local.config.vm_name_prefix,
local.config.vm_role,
local.config.vm_num_prefix,
server + 1, # 1-based naming
local.config.vm_singleton ? "x" : local.roleLetter[pool])
]
]
]
reserved_names = [
# If reserved, add another set of server names, else add nothing
for server in range(0, ! local.config.vm_singleton && local.config.vm_reserve ? local.config.vm_servers_per_pool : 0) : [
format("%s-%s%s%03d%s",
local.config.vm_name_prefix,
local.config.vm_role,
local.config.vm_num_prefix,
server + 1, # 1-based naming
"r")
]
]
all_machine_names = concat(flatten(local.machine_names), flatten(local.reserved_names))
}
output "names-terraform" {
value = local.all_machine_names
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment