HewlettPackard / terraform-provider-oneview

Automates the provisioning of physical infrastructure from a private cloud using templates from HPE OneView with Terraform
Apache License 2.0
49 stars 30 forks source link

The terraform show "No changes. Infrastructure is up-to-date." in Power Off/On server hardware update operation after "terraform import". #408

Closed ghost closed 3 years ago

ghost commented 3 years ago

terraform plan show "No changes/Destroy" in Power Off server hardware update operation after "terraform import" command.

Here are steps I have followed

  1. Create a TF configuration file provider "oneview" { ov_username = var.username ov_password = var.password ov_endpoint = var.endpoint ov_sslverify = var.ssl_enabled ov_apiversion = var.api_version ov_ifmatch = "*" ov_domain = var.ov_domain }

resource "oneview_server_hardware" "DTAG" { }

  1. Import existing 2 DL server hardware information into terraform as list using following cli command

terraform import oneview_server_hardware.DTAG[0] ILOxxxx.v1000.cce01 terraform import oneview_server_hardware.DTAG[1] ILOyyyy.v1000.cce01

  1. Update TF config file to power on DL server

provider "oneview" { ov_username = var.username ov_password = var.password ov_endpoint = var.endpoint ov_sslverify = var.ssl_enabled ov_apiversion = var.api_version ov_ifmatch = "*" ov_domain = var.ov_domain }

resource "oneview_server_hardware" "DTAG" {

server_power_state { power_state = var.server_hardware_attr["power_state"] power_control = var.server_hardware_attr["power_control"] } }

  1. terraform state list

root@terraform-virtual-machine:# terraform state list oneview_server_hardware.DTAG[0] oneview_server_hardware.DTAG[1]

  1. terraform show

root@terraform-virtual-machine# terraform show

oneview_server_hardware.DTAG[0]:

resource "oneview_server_hardware" "DTAG" { force = false id = "xxxxx" licensing_intent = "OneViewNoiLO" location_uri = "null" mp_firmware_version = "xxxx" name = "xxxxx" one_time_boot = "Normal" power_state = "Off" server_group_uri = "null" server_hardware_type_uri = "/rest/server-hardware-types/7B626E13-7F48-4B8C-B208-98F15AB324EB" server_profile_uri = "/rest/server-profiles/4d0056f5-771d-4300-b2de-1abd39f0126c" type = "server-hardware-12" uid_state = "Off" uri = "/rest/server-hardware/39373638-3835-584D-5131-323730473342" uuid = "39373638-3835-584D-5131-323730473342" virtual_serial_number = "null" }

oneview_server_hardware.DTAG[1]:

resource "oneview_server_hardware" "DTAG" { force = false id = "39373638-3835-584D-5131-323730473347" licensing_intent = "OneView" location_uri = "null" mp_firmware_version = "xxxx" name = "xxxxx" one_time_boot = "Normal" power_state = "Off" server_group_uri = "null" server_hardware_type_uri = "/rest/server-hardware-types/7B626E13-7F48-4B8C-B208-98F15AB324EB" server_profile_uri = "/rest/server-profiles/7f458d00-342d-46b5-bd2a-1d2ad318f03f" type = "server-hardware-12" uid_state = "Off" uri = "/rest/server-hardware/39373638-3835-584D-5131-323730473347" uuid = "39373638-3835-584D-5131-323730473347" virtual_serial_number = "null" }

  1. Run terraform plan command

terraform plan -target= oneview_server_hardware.DTAG[0]

Output:

root@terraform-virtual-machine:~/latest_terraform/AutomationUseCases-DTAG-Aug2021/DTAG/Power Settings# terraform plan -target=oneview_server_hardware.DTAG[0] var.ov_domain Oneview domain

Enter a value:

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.


No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your configuration and real physical resources that exist. As a result, no actions need to be performed.

  1. terraform plan -target=oneview_server_hardware.DTAG[1]

Output: Terraform will perform the following actions:

oneview_server_hardware.DTAG[1] will be destroyed

Plan: 0 to add, 0 to change, 1 to destroy.

We are expecting Dl server to be power On/Off without deleting resources.

Environment used: Oneview 6.3 Pull codes from master branches and build locally DL360 Gen 10 1

Regards Soibam

nabhajit-ray commented 3 years ago

We are looking into this and will get back to you.

yuvirani commented 3 years ago

@SoibamRepo, I understand that you would like to import multiple resources and update their power states. Terraform doesn't encourage to use "-target" to apply changes where as it can be useful only for troubleshooting errors. Hence, we suggest you to define different instance names for import and provide both resources in the config for update. So that, terraform updates the power states without deleting the resources.

Below is the configuration for importing and updating power states of the DL's:

1.Create a TF configuration file

resource "oneview_server_hardware" "DTAG_0" {
}
resource "oneview_server_hardware" "DTAG_1" {
}
  1. Import existing hardwares
terraform import oneview_server_hardware.DTAG_0 ILOxxxx.v1000.cce01
terraform import oneview_server_hardware.DTAG_1 ILOyyyy.v1000.cce01
  1. Update TF config file to power on DL server
    
    resource "oneview_server_hardware" "DTAG_0" {
         server_power_state {
                  power_state = var.server_hardware_attr["power_state"]
                  power_control = var.server_hardware_attr["power_control"]
         }
    }

resource "oneview_server_hardware" "DTAG_1" { server_power_state { power_state = var.server_hardware_attr["power_state"] power_control = var.server_hardware_attr["power_control"] } }


Please try this configuration and let us know if you have any issues.
nabhajit-ray commented 3 years ago

As we have not heard back on the issue, we assume that it is resolved. Feel free to reopen if you need further help/clarification.