Hi @apparentlymart,
So someone was able to help me out and I got it working just how I want it. And this is the code. Hopefully this also explains a bit what I was trying to achieve.
terraform {
required_providers {
lxd = {
source = "arren-ru/lxd"
version = "1.4.0"
}
}
}
provider "lxd" {
generate_client_certificates = true
accept_remote_certificate = true
lxd_remote {
name = "lxd-01"
scheme = "https"
address = "X"
password = "X"
default = true
}
}
locals {
images = [
{ alias = [ "ubuntu_focal" ], source_remote = "ubuntu", source_image = "focal/amd64" },
{ alias = [ "debian_buster" ], source_remote = "images", source_image = "debian/10/amd64" }
]
image_fingerprints = {
for image in lxd_cached_image.image:
image.aliases[0] => image.fingerprint
}
containers = [
{ name = "unifi", image = "ubuntu_focal" },
{ name = "grafana", image = "debian_buster" },
{ name = "test1", image = "debian_buster" }
]
}
resource "lxd_cached_image" "image" {
count = length(local.images)
aliases = lookup(local.images[count.index], "alias")
source_remote = lookup(local.images[count.index], "source_remote")
source_image = lookup(local.images[count.index], "source_image")
}
resource "lxd_container" "create_container" {
count = length(local.containers)
name = lookup(local.containers[count.index], "name")
image = lookup(local.image_fingerprints, lookup(local.containers[count.index], "image"))
ephemeral = false
config = {
"boot.autostart" = true
}
}