Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopped VM does not trigger dirty terraform plan #197

Open
ddelnano opened this issue May 20, 2022 · 1 comment
Open

Stopped VM does not trigger dirty terraform plan #197

ddelnano opened this issue May 20, 2022 · 1 comment

Comments

@ddelnano
Copy link
Collaborator

When investigating #196, I noticed that if a VM created with terrraform is stopped a subsequent terraform plan will not show that the VM will be started. This means the power_state property is not being refreshed properly.

@4censord
Copy link
Contributor

This means the power_state property is not being refreshed properly.

I have done some testing on this:
When changing the power_state property from Computed: true, to

Optional: true,
Default:  "Running",

Terraform detects that it has changed:

  # xenorchestra_vm.vm will be updated in-place
  ~ resource "xenorchestra_vm" "vm" {
        id                 = "1daf4d69-58e3-1976-b7c4-7e6edb0ee595"
      ~ power_state        = "Halted" -> "Running"
        tags               = [
            "dev",
        ]
        # (16 unchanged attributes hidden)


      ~ disk {
          ~ attached   = false -> true
            # (6 unchanged attributes hidden)
        }

      ~ network {
          ~ attached       = false -> true
            # (5 unchanged attributes hidden)
        }
        # (1 unchanged block hidden)
    }

applying this, terraform fails with:

╷
│ Error: jsonrpc2: code 13 message: VM state is halted but should be running: {"objectId":"1daf4d69-58e3-1976-b7c4-7e6edb0ee595","expected":"running","actual":"halted"}
│ 
│   with xenorchestra_vm.vm,
│   on main.tf line 1, in resource "xenorchestra_vm" "vm":
│    1: resource "xenorchestra_vm" "vm" {
│ 
╵
Terraform config

Using this config:

resource "xenorchestra_vm" "vm" {
  name_label = "${local.projekt}"
  template   = data.xenorchestra_template.template.id

  cpus       = 1
  memory_max = 1 * local.gib

  wait_for_ip = true

  cdrom {
    id = data.xenorchestra_vdi.iso.id
  }

  network {
    network_id = data.xenorchestra_network.network.id
  }

  disk {
    sr_id      = data.xenorchestra_sr.storage.id
    name_label = "Data disk for ${local.projekt}"
    size       = 1 * local.gib
  }

  tags = [
    "dev",
  ]
}
  • Running apply
  • wait till completion
  • stop vm via xoa (normal stop)
  • run plan, see changed powerstate
  • run apply see terraform crash.

Running terraform with debug logging seems to list all my vms, settings and the like, so i'd rather not post that publicly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants