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

Add tools_upgrade_policy argument to the vsphere_virtual_machine resource #1506

Merged
merged 2 commits into from
Feb 25, 2022
Merged

Add tools_upgrade_policy argument to the vsphere_virtual_machine resource #1506

merged 2 commits into from
Feb 25, 2022

Conversation

tenthirtyam
Copy link
Collaborator

@tenthirtyam tenthirtyam commented Oct 31, 2021

Description

  • Add tools_upgrade_policy argument to the vsphere_virtual_machine resource to set the upgrade policy for VMware Tools. One of manual or upgradeAtPowerCycle. Default: manual
  • Updates the vsphere_virtual_machine resource docs to include the tools_upgrade_policy` argument.

Testing

Performed unit tests which included both positive and negative tests. All passed successfully.

Example:

terraform {
  required_providers {
    vsphere = {
      source  = "hashicorp/vsphere"
      version = "x.y.z"
    }
  }
  required_version = ">= x.y.z"
}

provider "vsphere" {
  vsphere_server       = "m01-vc01.rainpole.io"
  user                 = "[email protected]"
  password             = "VMware1!"
  allow_unverified_ssl = true
}

data "vsphere_datacenter" "datacenter" {
  name = "m01-dc01"
}

data "vsphere_network" "network" {
  name          = "M - 172.16.11.0"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_compute_cluster" "cluster" {
  name          = "m01-cl01"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_resource_pool" "pool" {
  name          = format("%s%s", data.vsphere_compute_cluster.cluster.name, "/Resources")
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_datastore" "datastore" {
  name          = "local-ssd-01"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_folder" "folder" {
  path = "/${data.vsphere_datacenter.datacenter.name}/vm/"
}

data "vsphere_virtual_machine" "template" {
  name          = "ubuntu-server-20-04-lts"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

resource "vsphere_virtual_machine" "vm" {
  name                    = "gh-1297"
  folder                  = trimprefix(data.vsphere_folder.folder.path, "/${data.vsphere_datacenter.datacenter.name}/vm") 
  datastore_id            = data.vsphere_datastore.datastore.id
  resource_pool_id        = data.vsphere_resource_pool.pool.id
  num_cpus                = 2
  memory                  = 4096
  firmware                = "efi"
  efi_secure_boot_enabled = true
  guest_id                = data.vsphere_virtual_machine.template.guest_id
  tools_upgrade_policy    = "upgradeAtPowerCycle" // <----- Set upgrade policy for VMware Tools.
  network_interface {
    network_id = data.vsphere_network.network.id
  }
  disk {
    label = "disk0"
    size  = 60
    thin_provisioned = true
  }
  clone {
    template_uuid = data.vsphere_virtual_machine.template.id
    customize {
      linux_options {
        host_name = "gh-1292"
        domain    = "rainpole.io"
      }
      network_interface {
        ipv4_address = "172.16.11.100"
        ipv4_netmask = "24"
      }

      ipv4_gateway    = "172.16.11.1"
      dns_suffix_list = ["rainpole.io"]
      dns_server_list = ["172.16.11.11", "172.16.11.12"]
    }
  }
}

Release Note

resource/virtual_machine: Adds the tools_upgrade_policy argument to to set the upgrade policy for VMware Tools. One of manual or upgradeAtPowerCycle. Default: manual. Will force a reboot. GH-1506

References

Closes: #1297

@github-actions github-actions bot added documentation Type: Documentation size/xs Relative Sizing: Extra-Small labels Oct 31, 2021
@tenthirtyam tenthirtyam requested a review from appilon February 3, 2022 20:48
@appilon
Copy link
Contributor

appilon commented Feb 3, 2022

@tenthirtyam Looks Good to me, there aren't any acceptance tests around the other similar attributes so fine with the PR as is, can you do another quick ad hoc test verifying it works, can you update from manual to upgradeAtPowerCycle just want to make sure a change to this attribute is allowed and we don't need to use ForceNew? Can you also rebase the branch to fix the conflicts in the doc file (if you need me to rebase just lemme know)

@tenthirtyam
Copy link
Collaborator Author

@appilon, can you rebase and I'll make the changes and retest? :)

Addresses #1297
- Add `tools_upgrade_policy` argument to the `vsphere_virtual_machine` resource to set the upgrade policy for VMware Tools. One of `manual` or `upgradeAtPowerCycle`. Default: `manual`
- Updates the `vsphere_virtual_machine` resource docs to include the tools_upgrade_policy` argument.

Signed-off-by: Ryan Johnson <[email protected]>
@github-actions github-actions bot added the provider Type: Provider label Feb 4, 2022
@appilon
Copy link
Contributor

appilon commented Feb 4, 2022

rebased!

@tenthirtyam
Copy link
Collaborator Author

First apply:

 + tools_upgrade_policy                    = "manual"

State:

            "swap_placement_policy": "inherit",
            "sync_time_with_host": true,
            "sync_time_with_host_periodically": false,
            "tools_upgrade_policy": "manual",
            "uuid": "4202649b-1490-3806-e126-766d5d028350",
            "vapp": null,
            "vapp_transport": [],
            "vbs_enabled": false,
            "vvtd_enabled": false

image


Second Apply with tools_upgrade_policy = "upgradeAtPowerCycle"

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # vsphere_virtual_machine.vm[0] will be updated in-place
  ~ resource "vsphere_virtual_machine" "vm" {
        id                                      = "42023007-224d-8ef9-1a84-5bfcd4013c3e"
        name                                    = "test-vm-1"
        tags                                    = []
      ~ tools_upgrade_policy                    = "manual" -> "upgradeAtPowerCycle"
        # (66 unchanged attributes hidden)



        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
vsphere_virtual_machine.vm[0]: Modifying... [id=42023007-224d-8ef9-1a84-5bfcd4013c3e]
vsphere_virtual_machine.vm[0]: Still modifying... [id=42023007-224d-8ef9-1a84-5bfcd4013c3e, 10s elapsed]
vsphere_virtual_machine.vm[0]: Still modifying... [id=42023007-224d-8ef9-1a84-5bfcd4013c3e, 20s elapsed]
vsphere_virtual_machine.vm[0]: Still modifying... [id=42023007-224d-8ef9-1a84-5bfcd4013c3e, 30s elapsed]
vsphere_virtual_machine.vm[0]: Still modifying... [id=42023007-224d-8ef9-1a84-5bfcd4013c3e, 40s elapsed]
vsphere_virtual_machine.vm[0]: Still modifying... [id=42023007-224d-8ef9-1a84-5bfcd4013c3e, 50s elapsed]
vsphere_virtual_machine.vm[0]: Still modifying... [id=42023007-224d-8ef9-1a84-5bfcd4013c3e, 1m0s elapsed]
vsphere_virtual_machine.vm[0]: Modifications complete after 1m4s [id=42023007-224d-8ef9-1a84-5bfcd4013c3e]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

image

"tools_upgrade_policy": "manual",

ISSUES:

  • The state is not updated when toggled from manual to upgradeAtPowerCycle🤔
  • The state shows as manual when upgradeAtPowerCycle is used, but does not impact reapply. 🤔
  • The change via the provider forces a reboot; however, when done via UI this is not the case. I think we should resolve this. ⚠️

@tenthirtyam tenthirtyam added the needs-review Status: Pull Request Needs Review label Feb 4, 2022
@tenthirtyam tenthirtyam changed the title Add tools_upgrade_policy argument to the vsphere_virtual_machine resource (WIP) Add tools_upgrade_policy argument to the vsphere_virtual_machine resource Feb 4, 2022
@appilon
Copy link
Contributor

appilon commented Feb 7, 2022

@tenthirtyam I will try and take a look at the resource code to see if I can deduce why the state is stale

@tenthirtyam
Copy link
Collaborator Author

Thanks, @appilon - let me know if you want to sync up on this one early next week. 🚀

@tenthirtyam tenthirtyam added this to the v2.1.0 milestone Feb 14, 2022
@tenthirtyam tenthirtyam added the area/vm Area: Virtual Machines label Feb 22, 2022
@tenthirtyam
Copy link
Collaborator Author

I dug into this a bit more and it's working as expected.

  • The state is not updated when toggled from manual to upgradeAtPowerCycle - same pattern as hv_mode
  • The state shows as manual when upgradeAtPowerCycle is used, but does not impact reapply - same pattern as hv_mode
  • The change via the provider forces a reboot; however, when done via UI this is not the case. - same pattern as hv_mode: ToolsUpgradePolicy: getWithRestart(d, "tools_upgrade_policy").(string),

@tenthirtyam tenthirtyam changed the title (WIP) Add tools_upgrade_policy argument to the vsphere_virtual_machine resource Add tools_upgrade_policy argument to the vsphere_virtual_machine resource Feb 23, 2022
@tenthirtyam
Copy link
Collaborator Author

Would need to add to the list under Virtual Machine Reboot added in the recent update to r/virtual_machine docs.

Updates to `tools_upgrade_policy` description to include "Can be one of `manual` or `upgradeAtPowerCycle`"
@appilon
Copy link
Contributor

appilon commented Feb 25, 2022

Given that the behavior has precedent in hv_mode and likely other attributes, let's merge as is and file a new issue to investigate state sync problems for this resource/block

@appilon appilon merged commit de94b45 into hashicorp:master Feb 25, 2022
@tenthirtyam tenthirtyam deleted the gh-1297 branch February 25, 2022 20:09
@github-actions
Copy link

github-actions bot commented Mar 2, 2022

This functionality has been released in v2.1.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/vm Area: Virtual Machines documentation Type: Documentation provider Type: Provider size/xs Relative Sizing: Extra-Small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add VMware Tools Upgrades boolean parameter in ToolsConfigInfo
2 participants