27 lines
533 B
HCL
27 lines
533 B
HCL
locals {
|
|
inventory = {
|
|
all = {
|
|
vars = {
|
|
ansible_user = "cloud"
|
|
}
|
|
children = {
|
|
for svc in distinct([for k, v in var.instances : v.service_name]) :
|
|
svc => {
|
|
hosts = {
|
|
for k, v in var.instances :
|
|
v.vm_name => {
|
|
ansible_host = v.ipv4_address
|
|
}
|
|
if v.service_name == svc
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "local_file" "inventory" {
|
|
filename = var.filename
|
|
content = yamlencode(local.inventory)
|
|
}
|