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

Creating Server Profile produces an Error 404 #343

Closed ClaireHayard closed 3 years ago

ClaireHayard commented 3 years ago

Scenario/Intent

Hello,

I am trying to create multiple server profiles in OneView with the command terraform apply -var-file=variables.tfvars but it finishes with a 404 error. However my server profiles are created.

Also when I try do run the command terraform destroy -var-file=variables.tfvars it just does a refresh and doesn't delete the ressources. Like the apply command it produces a 404 error.

Environment Details

Steps to Reproduce

You can fin below the Terraform files I used to create the servers Profile:

Variables.tf file

variable "oneview_username" {
  description = "OneView Username"
  type        = string
}

variable "oneview_password" {
  description = "OneView Password"
  type        = string
}

variable "oneview_uri" {
  description = "OneView IP address or FQDN (endpoint)."
  type        = string
}

variable "ssl_enabled" {
  description = "Is SSL enabled by default"
  type        = bool
}

variable "oneview_apiversion" {
  description = "Version number of the OneView API"
  type        = number
}

## Server Profile variable declaration

variable "server_profiles" {
  description = "Details server profiles configuration."
  type = list(object({
    server_profile_name = string
    server_profile_type = string
    affinity            = string
    template            = string
  }))
}

Variables.tfvars

oneview_username   = ""
oneview_password   = ""
oneview_uri        = ""
ssl_enabled        = false
oneview_apiversion = 2600

server_profiles = [
  {
    server_profile_name = "SP01"
    server_profile_type = "ServerProfileV12"
    affinity            = "BayAndServer"
    template            = "SPT"
  },
  {
    server_profile_name = "SP02"
    server_profile_type = "ServerProfileV12"
    affinity            = "BayAndServer"
    template            = "SPT"
  }
]

Main.tf

provider "oneview" {
  ov_username   = var.oneview_username
  ov_password   = var.oneview_password
  ov_endpoint   = var.oneview_uri
  ov_sslverify  = var.ssl_enabled
  ov_apiversion = var.oneview_apiversion
  ov_ifmatch    = "*"
}

resource "oneview_server_profile" "ServerProfiles" {
  for_each  = { for server_profile in var.server_profiles : server_profile.server_profile_name => server_profile }
  name      = each.value.server_profile_name
  type        = each.value.server_profile_type
  template = each.value.template
  affinity = each.value.affinity
}

Expected Result

The Server Profile is created and can be deleted without creating an error.

Actual Result

Error in response: Not Found Response status: 404 Not Found

2021/06/25 14:45:05 [ERROR] eval: *terraform.EvalRefresh, err: Error in response: Not Found
 Response Status: 404 Not Found
 Response Details: The requested resource could not be found.
2021/06/25 14:45:05 [ERROR] eval: *terraform.EvalSequence, err: Error in response: Not Found
 Response Status: 404 Not Found
 Response Details: The requested resource could not be found.
2021/06/25 14:45:05 [TRACE] [walkRefresh] Exiting eval tree: oneview_server_profile.ServerProfiles["SP01"]
2021/06/25 14:45:05 [TRACE] vertex "oneview_server_profile.ServerProfiles[\"SP01\"]": visit complete
2021/06/25 14:45:05 [TRACE] dag/walk: upstream of "root" errored, so skipping
2021/06/25 14:45:05 [TRACE] vertex "oneview_server_profile.ServerProfiles": dynamic subgraph encountered errors
2021/06/25 14:45:05 [TRACE] vertex "oneview_server_profile.ServerProfiles": visit complete
2021/06/25 14:45:05 [TRACE] vertex "oneview_server_profile.ServerProfiles (expand)": dynamic subgraph encountered errors
2021/06/25 14:45:05 [TRACE] vertex "oneview_server_profile.ServerProfiles (expand)": visit complete
2021/06/25 14:45:05 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/hewlettpackard/oneview\"] (close)" errored, so skipping
2021/06/25 14:45:05 [TRACE] dag/walk: upstream of "root" errored, so skipping
2021/06/25 14:45:05 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
Error: Error in response: Not Found
 Response Status: 404 Not Found
 Response Details: The requested resource could not be found.
nabhajit-ray commented 3 years ago

Hi Claire,

Thanks for raising this. We will check and get back to you. Meanwhile, can you try the master branch?

ClaireHayard commented 3 years ago

Hi,

I also tried the above Terraform files in the master branch.

I followed the README to install the SDK locally. Then I cloned the project and moved my files to test them at the root of the repo.

I get the same error when trying to apply the Terraform code.

nabhajit-ray commented 3 years ago

Hi , Have added some fix to master. Can you please check? You should not use the provider from the registry as the fix is not there in the registry yet.

Steps to use provider locally:

  1. Build the provider locally first $pwd /home/terraform-provider-oneview $ls CHANGELOG.md docs go.mod LICENSE oneview variables.tf CONTRIBUTING.md endpoints-support.md go.sum main.go README.md vendor Dockerfile examples HACKING.md 'Migration Support' versions.tf $ go build -o terraform-provider-oneview

  2. Create directory to place the provider $ mdkir -p .terraform/plugins/registry.terraform.io/hewlettpackard/oneview/6.1.0-13/linux_amd64/

  3. Copy the provider to the created location $ mv terraform-provider-oneview .terraform/plugins/registry.terraform.io/hewlettpackard/oneview/6.1.0-13/linux_amd64/terraform-provider-oneview_v6.1.0-13

ClaireHayard commented 3 years ago

Hello,

I cloned the repo again to pull the fixes you provided and moved my Terraform files to the root of the repo. Then I followed the instructions you provided but I still get the same 404 error.

ClaireHayard commented 3 years ago

Hello,

You can find my tfstate file below:

{
  "version": 4,
  "terraform_version": "1.0.1",
  "serial": 4,
  "lineage": "7fc267dd-af8e-51ab-9384-6ee299d9b389",
  "outputs": {},
  "resources": [
    {
      "mode": "managed",
      "type": "oneview_server_profile",
      "name": "ServerProfiles",
      "provider": "provider[\"registry.terraform.io/hewlettpackard/oneview\"]",
      "instances": [
        {
          "index_key": "SP01",
          "status": "tainted",
          "schema_version": 0,
          "attributes": {
            "affinity": "BayAndServer",
            "bios_option": [],
            "boot": [],
            "boot_mode": [],
            "connection_settings": [],
            "enclosure_group": null,
            "firmware": [],
            "hardware_name": null,
            "hardware_uri": null,
            "hide_unused_flex_nics": true,
            "hw_filter": null,
            "id": "SP01",
            "ilo_ip": null,
            "initial_scope_uris": null,
            "local_storage": [],
            "mac_type": "Virtual",
            "name": "SP01",
            "options": [],
            "os_deployment_settings": [],
            "power_state": null,
            "public_connection": null,
            "public_mac": null,
            "public_slot_id": null,
            "san_storage": [],
            "serial_number": null,
            "serial_number_type": "Virtual",
            "server_hardware_type": null,
            "template": "SPTESXTRD",
            "type": "ServerProfileV12",
            "update_type": null,
            "uri": null,
            "volume_attachments": [],
            "wwn_type": "Virtual"
          },
          "sensitive_attributes": [],
          "private": "bnVsbA=="
        },
        {
          "index_key": "SP02",
          "status": "tainted",
          "schema_version": 0,
          "attributes": {
            "affinity": "BayAndServer",
            "bios_option": [],
            "boot": [],
            "boot_mode": [],
            "connection_settings": [],
            "enclosure_group": null,
            "firmware": [],
            "hardware_name": null,
            "hardware_uri": null,
            "hide_unused_flex_nics": true,
            "hw_filter": null,
            "id": "SP02",
            "ilo_ip": null,
            "initial_scope_uris": null,
            "local_storage": [],
            "mac_type": "Virtual",
            "name": "SP02",
            "options": [],
            "os_deployment_settings": [],
            "power_state": null,
            "public_connection": null,
            "public_mac": null,
            "public_slot_id": null,
            "san_storage": [],
            "serial_number": null,
            "serial_number_type": "Virtual",
            "server_hardware_type": null,
            "template": "SPTESXTRD",
            "type": "ServerProfileV12",
            "update_type": null,
            "uri": null,
            "volume_attachments": [],
            "wwn_type": "Virtual"
          },
          "sensitive_attributes": [],
          "private": "bnVsbA=="
        }
      ]
    }
  ]
}
nabhajit-ray commented 3 years ago

The fix will be available with next SDK package release.( approx 14th July)

nabhajit-ray commented 3 years ago

Hi Claire, Can you try the same operation with the new released version?

ClaireHayard commented 3 years ago

Hello Nabhajit,

I tested the above code for the use case again and I don't have the 404 error anymore with the new released version (v6.2.0-13).

Thank you,

Claire

nabhajit-ray commented 3 years ago

Thanks for sharing this. Closing this now