0

I have this main.tf below. It creates the VMs fine with all the correct stuff. But for some reason it doesn't run the provisioner file and remote-exec section. I copied the code from here.

I'm trying to setup a VM in Proxmox with 2 disks, and create an LVM. This will eventually be for adding ceph cluster.

terraform {
  required_providers {
    proxmox = {
      source = "telmate/proxmox"
      version = "2.9.11"
    }
  }
}

provider "proxmox" {
  pm_api_url = "https://xxx:8006/api2/json"
  pm_api_token_id = "terraform_token"
  pm_api_token_secret = "xxx"
  pm_tls_insecure = true
}

resource "proxmox_vm_qemu" "node_server" {
  count = 3
  # just want 1 for now, set to 0 and apply to destroy VM
  name = "node-${count.index + 1}"
  target_node = var.proxmox_host
  clone = var.template_name
  agent = 1
  os_type = "cloud-init"
  cores = 2
  sockets = 1
  cpu = "host"
  memory = 4096
  scsihw = "virtio-scsi-pci"
  bootdisk = "scsi0"
  disk {
    slot = 0
    size = "20G"
    type = "scsi"
    storage = "local-lvm"
    iothread = 1
  }
  disk {
    slot = 1
    size = "250G"
    type = "scsi"
    storage = "local-lvm"
    iothread = 1
  }

  provisioner "file" {
    source      = "/home/xxx/terraform-proxmox/setup-disks.sh"
    destination = "/tmp/setup-disks.sh"
  }
  provisioner "remote-exec" {
    inline = [
      "chmod +x /tmp/setup-disks.sh",
      "sudo /tmp/setup-disk.sh",
    ]
  }

  network {
    model = "virtio"
    bridge = "vmbr0"
  }
  lifecycle {
    ignore_changes = [
      network,
    ]
  }

  ipconfig0 = "ip=xxx.5${count.index + 1}/24,gw=xxx"

  sshkeys = <<EOF
  ${var.ssh_key}
  EOF
}
GodAtum
  • 171
  • 2
  • 3
  • 11

0 Answers0