Hi,
I am trying to create a bunch of containers with unique names, Though I keep getting the error: Error: Cycle: lxd_container.create_container["grafana"], lxd_container.create_container["unifi"]
Does anyone know to happen what I’m doing wrong? Thank you in advance!
terraform {
required_providers {
lxd = {
source = "sl1pm4t/lxd"
}
}
}
locals {
images = {
"ubuntu_focal" = { alias = [ "ubuntu_focal" ], source_remote = "ubuntu", source_image = "ubuntu/focal/amd64" }
"debian_buster" = { alias = [ "debian_buster" ], source_remote = "images", source_image = "debian/10/amd64"}
}
containers = {
"unifi" = { image = local.images.ubuntu_focal.alias },
"grafana" = { image = local.images.debian_buster.alias }
}
}
resource "lxd_cached_image" "image" {
for_each = local.images
aliases = each.value.alias
source_remote = each.value.source_remote
source_image = each.value.source_image
}
resource "lxd_container" "create_container" {
for_each = local.containers
name = each.key
image = each.value.image
ephemeral = false
config = {
"boot.autostart" = true
}
provisioner "local-exec" {
command = <<EOT
sudo lxc exec ${lxd_container.create_container[each.key]} -- apt update
sudo lxc exec ${lxd_container.create_container[each.key]} -- apt install -y curl
sudo lxc exec ${lxd_container.create_container[each.key]} -- curl -o /tmp/bootstrap-salt.sh -L https://bootstrap.saltstack.com
sudo lxc exec ${lxd_container.create_container[each.key]} -- sh /tmp/bootstrap-salt.sh -x python3 stable
sudo lxc exec ${lxd_container.create_container[each.key]} -- systemctl enable --now salt-minion
EOT
}
}
resource "null_resource" "delete_minion_key" {
provisioner "local-exec" {
when = destroy
on_failure = continue
command = <<EOT
sudo salt-key -y -d ${self.triggers.host}
EOT
}
}