lxc / terraform-provider-incus

Incus provider for Terraform/OpenTofu
https://linuxcontainers.org/incus
Mozilla Public License 2.0
51 stars 11 forks source link

Can't use `file` block on newly created virtual-machine #142

Open austinried opened 3 days ago

austinried commented 3 days ago

Trying to create a new virtual machine that includes a file block but it keeps failed and saying the instance is not running:

│ Error: Failed to upload file to instance "wg-home"
│ 
│   with module.wg-home.incus_instance.cloud_instance,
│   on modules/cloud_instance/main.tf line 44, in resource "incus_instance" "cloud_instance":
│   44: resource "incus_instance" "cloud_instance" {
│ 
│ Could not create directories for file "/root/.ssh/authorized_keys": Instance is not running

This file block works fine with container type instances, only fails like this for a virtual-machine type. When I check the incus host, I find that the instance is indeed not running. However, after a manual incus start wg-home it appears to be running without issue (but without my authorized_keys that I wanted to copy over during creation).

Here's a snippet from my instance module, where I am setting what I think should cause the instance to automatically start when created:

  type             = var.type
  running          = true
  wait_for_network = true

  config = merge(
    {
      "boot.autostart" = true
    },
    var.type == "container" ? {
      "security.nesting" = true
    } : {},
    var.type == "virtual-machine" ? {
      "security.secureboot" = false
    } : {},
  )

Is this my issue or a bug? I don't know why for virtual machines it's not auto-starting for VMs but it is for containers.

trunet commented 3 hours ago

running and wait_for_network defaults to true already.

I had this problem with old versions a couple of weeks/months ago.

Could you check if you're using an up2date incus server, incus client and terraform provider?