vmware / terraform-provider-vcd

Terraform VMware Cloud Director provider
https://www.terraform.io/docs/providers/vcd/
Mozilla Public License 2.0
148 stars 112 forks source link

Upgrade path from 3.11.0 or below to 3.12 or above not smooth due to force replacement by consolidate_disks_on_create #1328

Open jpbuecken opened 3 weeks ago

jpbuecken commented 3 weeks ago

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

Terraform v1.9.6
on linux_amd64
+ provider registry.terraform.io/vmware/vcd v3.11.0

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

terraform {
  required_providers {
    vcd = {
      source  = "vmware/vcd"
      version = "3.11.0"
    }
  }
  required_version = "1.9.6"
}

resource "vcd_vm" "instance" {
  name             = "upgrade-test"
  computer_name    = "upgrade-test"
  vapp_template_id = "urn:vcloud:vapptemplate:d9d38664-be73-4f4c-8da6-42ef78472fb9"
  cpus             = 2
  cpu_cores        = 1
  memory           = 2084

  network {
    type               = "org"
    name               = "xxxxxxx"
    adapter_type       = "vmxnet3"
    ip_allocation_mode = "POOL"
    is_primary         = true
  }
}

Expected Behavior

A provider update from 3.11.0 to 3.12.1 should not forces replacement of vcd_vm or vcd_vapp_vm.

Actual Behavior

After update of the provider AND you try to change a value of the vcd_vm (e.g. increase the number of cpus), this forces a replacement of the VM.

  # vcd_vm.instance must be replaced
-/+ resource "vcd_vm" "instance" {
      + consolidate_disks_on_create    = false # forces replacement

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Start with above HCL. Put the code above in a file main.tf
  2. terraform init
  3. terraform apply
  4. Bump provider version in main.tf, e.g. sed -i s/3.11.0/3.12.1/g main.tf
  5. terraform init -upgrade
  6. Check: terraform -v
Terraform v1.9.6
on linux_amd64
+ provider registry.terraform.io/vmware/vcd v3.12.1
  1. Increase cpus. E.g. sed -i s/"cpus = 2"/"cpus = 3"/g main.tf
  2. terraform apply You will see the replacement
    
    vcd_vm.instance: Refreshing state... [id=urn:vcloud:vm:b1762165-5d94-4b26-9536-5bb0fa7da624]

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:

vcd_vm.instance must be replaced

-/+ resource "vcd_vm" "instance" {

Important Factoids

VCD Version 10.6.0.1

carmine73 commented 2 weeks ago

hi @jpbuecken, as workaround you can use:

resource "vcd_vm" "instance" {
  name             = "upgrade-test"
  computer_name    = "upgrade-test"
  vapp_template_id = "urn:vcloud:vapptemplate:d9d38664-be73-4f4c-8da6-42ef78472fb9"
  cpus             = 2
  cpu_cores        = 1
  memory           = 2084

  network {
    type               = "org"
    name               = "xxxxxxx"
    adapter_type       = "vmxnet3"
    ip_allocation_mode = "POOL"
    is_primary         = true
  }

  lifecycle {
    ignore_changes = [
      # if you don't want VMs to be updated when consolidate_disks_on_create changes (parameter added in 3.12.0)
      consolidate_disks_on_create
    ]
  }
}