Añadir main.tf
This commit is contained in:
40
main.tf
Normal file
40
main.tf
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
terraform {
|
||||||
|
required_version = ">= 1.6.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "null" {}
|
||||||
|
|
||||||
|
# Crear múltiples contenedores en Incus
|
||||||
|
resource "null_resource" "incus_containers" {
|
||||||
|
for_each = toset(var.containers)
|
||||||
|
|
||||||
|
provisioner "local-exec" {
|
||||||
|
command = <<EOT
|
||||||
|
echo "[INFO] Creando contenedor ${each.key}..."
|
||||||
|
incus launch images:ubuntu/24.04 ${each.key} --config=user.user-data="$(cat cloud-init.yaml)"
|
||||||
|
EOT
|
||||||
|
}
|
||||||
|
|
||||||
|
provisioner "local-exec" {
|
||||||
|
when = destroy
|
||||||
|
command = "incus delete ${each.key} --force || true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Actualiza cada contenedor
|
||||||
|
resource "null_resource" "update_containers" {
|
||||||
|
depends_on = [null_resource.incus_containers]
|
||||||
|
for_each = toset(var.containers)
|
||||||
|
|
||||||
|
provisioner "local-exec" {
|
||||||
|
command = <<EOT
|
||||||
|
echo "[INFO] Actualizando contenedor ${each.key}..."
|
||||||
|
sleep 10
|
||||||
|
incus exec ${each.key} -- bash -c "apt update -y && apt upgrade -y && apt autoremove -y"
|
||||||
|
EOT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output "containers" {
|
||||||
|
value = var.containers
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user