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 check for vsphere_virtual_machine power state #1407

Merged
merged 4 commits into from
Mar 3, 2022

Conversation

sumitmaggo
Copy link
Contributor

@sumitmaggo sumitmaggo commented May 15, 2021

Description

Added a computed parameter (power_state) for checking the power state of VM and to show the difference in case VM is not in running state.
Related to #916

When VM is not running and we run terraform plan, it will show the following diff:
This is tested with Terraform 0.13.3 version.

$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

local_file.meta-data[0]: Refreshing state... [id=221754ffcbea5c01e45fcf0cc40be37aeaa33fda]

vsphere_virtual_machine.example-vm[0]: Refreshing state... [id=564d7840-81a1-72c1-463b-0cc137eed6ea]

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

vsphere_virtual_machine.example-vm[0] will be updated in-place
  ~ resource "vsphere_virtual_machine" "example-vm" {
        boot_delay                              = 0
        boot_retry_delay                        = 10000
        boot_retry_enabled                      = false
        change_version                          = "2020-12-28T06:39:57.251199Z"
        cpu_hot_add_enabled                     = false
        cpu_hot_remove_enabled                  = false
        cpu_limit                               = -1
        cpu_performance_counters_enabled        = false
        cpu_reservation                         = 0
        cpu_share_count                         = 1000
        cpu_share_level                         = "normal"
        datastore_id                            = "5bd0b7d5-02d4a3bb-154a-ac162d77f63c"
        efi_secure_boot_enabled                 = false
        enable_disk_uuid                        = false
        enable_logging                          = false
        ept_rvi_mode                            = "automatic"
        extra_config                            = {}
        firmware                                = "bios"
        force_power_off                         = true
        guest_id                                = "centos8_64Guest"
        guest_ip_addresses                      = []
        hardware_version                        = 14
        host_system_id                          = "ha-host"
        hv_mode                                 = "hvAuto"
        id                                      = "564d7840-81a1-72c1-463b-0cc137eed6ea"
        ide_controller_count                    = 2
        latency_sensitivity                     = "normal"
        memory                                  = 1024
        memory_hot_add_enabled                  = false
        memory_limit                            = -1
        memory_reservation                      = 0
        memory_share_count                      = 10240
        memory_share_level                      = "normal"
        migrate_wait_timeout                    = 30
        moid                                    = "1635"
        name                                    = "example-vm"
        nested_hv_enabled                       = false
        num_cores_per_socket                    = 1
        num_cpus                                = 1
        pci_device_id                           = []
      ~ power_state                             = "shutdown" -> "running"
        poweron_timeout                         = 300
        reboot_required                         = false
        resource_pool_id                        = "ha-root-pool"
        run_tools_scripts_after_power_on        = true
        run_tools_scripts_after_resume          = true
        run_tools_scripts_before_guest_reboot   = false
        run_tools_scripts_before_guest_shutdown = true
        run_tools_scripts_before_guest_standby  = true
        sata_controller_count                   = 0
        scsi_bus_sharing                        = "noSharing"
        scsi_controller_count                   = 1
        scsi_type                               = "pvscsi"
        shutdown_wait_timeout                   = 3
        swap_placement_policy                   = "inherit"
        sync_time_with_host                     = false
        uuid                                    = "564d7840-81a1-72c1-463b-0cc137eed6ea"
        vapp_transport                          = []
        vmware_tools_status                     = "guestToolsNotRunning"
        vmx_path                                = "example-vm/example-vm.vmx"
        wait_for_guest_ip_timeout               = 0
        wait_for_guest_net_routable             = true
        wait_for_guest_net_timeout              = 0

Release Note

resource/virtual_machine : Adds support to check the power state of the resource. [GH-1407]

References

Closes #916

@sumitmaggo
Copy link
Contributor Author

@bill-rich @koikonom @aareet @sumitAgrawal007 Can you guys please look into this PR and provide your comments? Thanks in advance.

@tenthirtyam tenthirtyam changed the title Added check for power state for VM Added check for vsphere_virtual_machine power state Feb 4, 2022
@tenthirtyam tenthirtyam changed the title Added check for vsphere_virtual_machine power state Add check for vsphere_virtual_machine power state Feb 4, 2022
Copy link
Collaborator

@tenthirtyam tenthirtyam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes should also be included for the docs to reflect this capability.

@tenthirtyam tenthirtyam self-assigned this Feb 9, 2022
@tenthirtyam
Copy link
Collaborator

@appilon, I'll pick this one up for code/docs review and testing. I think there are some changes that could be made to address all three states and use the same states as seen in PowerCLI.

Ryan

@tenthirtyam tenthirtyam mentioned this pull request Feb 10, 2022
@appilon appilon self-assigned this Feb 10, 2022
@tenthirtyam tenthirtyam added this to the Research milestone Feb 15, 2022
@tenthirtyam tenthirtyam added the area/vm Area: Virtual Machines label Feb 22, 2022
@tenthirtyam tenthirtyam modified the milestones: Research, v2.2.0 Feb 24, 2022
@github-actions github-actions bot added provider Type: Provider size/s Relative Sizing: Small and removed size/xs Relative Sizing: Extra-Small labels Feb 25, 2022
@tenthirtyam
Copy link
Collaborator

Hi @sumitmaggo 👋🏻!

I've made some modifications to your contribution to account for each Runtime.PowerState and have performed several rounds of testing. After some internal discussions, I opted to keep it simple with on, off, and suspended being the states rather than those strictly from the API.

Could you rebase and update the Attribute Reference in r/virtual_machine docs to include the reference to the power_state attribute?

cc @appilon for milestone review.

Ryan Johnson
Staff II Solutions Architect | VMware, Inc.

@tenthirtyam tenthirtyam added the waiting-response Status: Waiting on a Response label Feb 25, 2022
@github-actions github-actions bot added size/xs Relative Sizing: Extra-Small and removed size/s Relative Sizing: Small labels Mar 2, 2022
@tenthirtyam tenthirtyam requested a review from appilon March 2, 2022 21:44
@appilon
Copy link
Contributor

appilon commented Mar 2, 2022

@tenthirtyam The PR just needs to add the new field to the docs. Could you take care of that and then I can solve the merge conflict.

@github-actions github-actions bot removed the waiting-response Status: Waiting on a Response label Mar 2, 2022
@tenthirtyam
Copy link
Collaborator

Sure thing. I'll update @sumitmaggo's fork any report back shortly.

@github-actions github-actions bot added the documentation Type: Documentation label Mar 2, 2022
@tenthirtyam
Copy link
Collaborator

Updated website/docs/r/virtual_machine.html.markdown but there will be conflicts.

sumitmaggo and others added 4 commits March 2, 2022 18:52
Adds support for each `vprops.Runtime.PowerState`
- `VirtualMachinePowerStatePoweredOn`
- `VirtualMachinePowerStatePoweredOff`
- `VirtualMachinePowerStateSuspended`

Keeps the terminology simple for the computed attribute.

Signed-off-by: Ryan Johnson <[email protected]>
Adds support for each `vprops.Runtime.PowerState`
- `VirtualMachinePowerStatePoweredOn`
- `VirtualMachinePowerStatePoweredOff`
- `VirtualMachinePowerStateSuspended`

Keeps the terminology simple for the computed attribute.

Signed-off-by: Ryan Johnson <[email protected]>
Add the `power_state` computed attribute to to `r/virtual_machine` docs.

Signed-off-by: Ryan Johnson <[email protected]>
@appilon appilon force-pushed the feature/vm-power-state branch from 5fe6797 to 09f7cf3 Compare March 2, 2022 23:58
@appilon appilon merged commit e56edec into hashicorp:main Mar 3, 2022
@tenthirtyam
Copy link
Collaborator

Thanks, Alex!

@tenthirtyam tenthirtyam modified the milestones: v2.2.0, v2.1.1 Mar 8, 2022
@github-actions
Copy link

This functionality has been released in v2.1.1 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

github-actions bot commented Apr 9, 2022

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 9, 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 enhancement Type: Enhancement provider Type: Provider size/xs Relative Sizing: Extra-Small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support to check the power state of r/virtual_machine
4 participants