dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.54k stars 457 forks source link

Not able to lifecycle ignore nvram.file attribute changes #1009

Open rgl opened 1 year ago

rgl commented 1 year ago

System Information

Linux distribution

Ubuntu 22.04

Terraform version

$ terraform -v
Terraform v1.4.2
on linux_amd64
+ provider registry.terraform.io/dmacvicar/libvirt v0.7.1
+ provider registry.terraform.io/hashicorp/random v3.4.3
+ provider registry.terraform.io/hashicorp/template v2.2.0

Provider and libvirt versions

$ .terraform/providers/registry.terraform.io/dmacvicar/libvirt/0.7.1/linux_amd64/terraform-provider-libvirt_v0.7.1 -version
.terraform/providers/registry.terraform.io/dmacvicar/libvirt/0.7.1/linux_amd64/terraform-provider-libvirt_v0.7.1 0.7.1

$ libvirtd --version
libvirtd (libvirt) 8.0.0

Description of Issue/Question

Setup

resource "libvirt_domain" "example" {
  machine = "q35"
  firmware = "/usr/share/OVMF/OVMF_CODE.fd"
  ...
  lifecycle {
    ignore_changes = [
      nvram[0].file,
      ...
    ]
  }
}

NB The full tf file is at https://github.com/rgl/terraform-libvirt-windows-example/blob/wip-uefi/main.tf#L195-L253.

Steps to Reproduce Issue

  1. terraform apply a first time to create everything.
  2. terraform apply a second time, and notice, that for some reason, its not ignoring the lifecycle changes, and wants to force a replacement of the libvirt_domain due to nvram.file changes:
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # libvirt_domain.example must be replaced
-/+ resource "libvirt_domain" "example" {
      ...

      - nvram { # forces replacement
          - file = "/var/lib/libvirt/qemu/nvram/terraform_example_VARS.fd" -> null # forces replacement
        }

        # (3 unchanged blocks hidden)
    }

Plan: 1 to add, 0 to change, 1 to destroy.
karelvanhecke commented 6 months ago

I am able to resolve this by ignoring the nvram option completely (this is fully managed by libvirt anyway):

lifecycle {
      ignore_changes = [ nvram ]
}

version: Terraform v1.6.6 on linux_amd64 provider registry.terraform.io/dmacvicar/libvirt v0.7.6