nutanix / terraform-provider-nutanix

Terraform Nutanix Provider
https://www.terraform.io/docs/providers/nutanix/
Mozilla Public License 2.0
100 stars 112 forks source link

Terraform provider crashes when using guest_customization_sysprep_custom_key_values #441

Closed d4vydm closed 2 years ago

d4vydm commented 2 years ago

Nutanix Cluster Information

Nutanix cluster: fraser-6.1-stable Nutanix Prism central: 6.1

Terraform Version

Terraform v1.1.9 on darwin_arm64

provider registry.terraform.io/nutanix/nutanix v1.4.1

Affected Resource(s)

/

Terraform Configuration Files

This part of the TF config file is relevant:

...
resource "nutanix_virtual_machine" "vm" {
    name                 = "${var.machine["vm_name"]}"
    num_vcpus_per_socket = var.machine["vm_num_vcpus_per_socket"]
    num_sockets          = var.machine["vm_cpu"]
    memory_size_mib      = var.machine["vm_ram_mb"]
    cluster_uuid         = var.nutanix_cluster.id

    guest_customization_sysprep = {
      install_type = "PREPARED"
      unattend_xml = base64encode(file("${path.module}/files/unattend.xml"))
    }
    guest_customization_sysprep_custom_key_values = {
      vm_hostname = "TEST123"
    }
...

Debug Output

/

Panic Output

│ Error: Plugin did not respond

...

Stack trace from the terraform-provider-nutanix_v1.4.1 plugin:

panic: interface conversion: interface {} is map[string]interface {}, not map[string]string

goroutine 66 [running]:
github.com/terraform-providers/terraform-provider-nutanix/nutanix.getVMResources(0x14000124600, 0x140002c8000)
        github.com/terraform-providers/terraform-provider-nutanix/nutanix/resource_nutanix_virtual_machine.go:1565 +0x1740
github.com/terraform-providers/terraform-provider-nutanix/nutanix.resourceNutanixVirtualMachineCreate({0x100e0ff88, 0x1400092ab40}, 0x14000124600, {0x100cba460, 0x140003f28a0})
        github.com/terraform-providers/terraform-provider-nutanix/nutanix/resource_nutanix_virtual_machine.go:670 +0x4a8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x14000223340, {0x100e0ff18, 0x140005989c0}, 0x14000124600, {0x100cba460, 0x140003f28a0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/resource.go:341 +0x118
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x14000223340, {0x100e0ff18, 0x140005989c0}, 0x140007c0340, 0x14000302600, {0x100cba460, 0x140003f28a0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/resource.go:467 +0x8d8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x140000b2018, {0x100e0ff18, 0x140005989c0}, 0x1400091ab90)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/grpc_provider.go:977 +0xe38
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x14000592800, {0x100e0ffc0, 0x140005dcc30}, 0x140008084d0)
        github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/tf5server/server.go:603 +0x338
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x100dc5700, 0x14000592800}, {0x100e0ffc0, 0x140005dcc30}, 0x140006c4600, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x140001bce00, {0x100e1c590, 0x14000414300}, 0x140007dc200, 0x140003ed080, 0x10130ff80, 0x0)
        google.golang.org/grpc@v1.32.0/server.go:1194 +0xc38
google.golang.org/grpc.(*Server).handleStream(0x140001bce00, {0x100e1c590, 0x14000414300}, 0x140007dc200, 0x0)
        google.golang.org/grpc@v1.32.0/server.go:1517 +0xa34
google.golang.org/grpc.(*Server).serveStreams.func1.2(0x140000a0d60, 0x140001bce00, {0x100e1c590, 0x14000414300}, 0x140007dc200)
        google.golang.org/grpc@v1.32.0/server.go:859 +0x94
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.32.0/server.go:857 +0x1f0

Error: The terraform-provider-nutanix_v1.4.1 plugin crashed!

Expected Behavior

/

Actual Behavior

/

Steps to Reproduce

  1. terraform apply

References

/

d4vydm commented 2 years ago

Initial analysis

I believe the crash seems to be related to type assertion from interface{} to map[string]string while underlaying type is map[string]interface{}.

Error line: https://github.com/nutanix/terraform-provider-nutanix/blob/e9691c624b90c1ab030d4c8cb62bc14e0d4ac9a9/nutanix/resource_nutanix_virtual_machine.go#L1565

v is of type interface{} but has an underlaying value of type map[string]interface{}. The type assertion assumes it is map[string]string.

abhimutant commented 2 years ago

Tracking #478

DevTown commented 1 year ago

How is the correct way to use the example?

` guest_customization_sysprep = { install_type = "PREPARED" unattend_xml = base64encode(file("unattend.xml")) } guest_customization_sysprep_custom_key_values = {

            VMNAME = "${format("vdi-%03d", count.index + 1)}"
        }`

I am trying but when i use it like this i get the error when i hit apply:

Error: error: { │ "api_version": "3.1", │ "code": 422, │ "message_list": [ │ { │ "details": { │ "spec.resources.guest_customization.sysprep": [ │ "{u'install_type': u'PREPARED', u'unattend_xml': u'BASE64STRING_OF_unattend.xml', u'custom_key_values': {u'VMNAME': u'vdi-tc10f-T-001'}} is valid under each of {'required': ['custom_key_values']}, {'required': ['unattend_xml']}" │ ] │ }, │ "message": "Request could not be processed.", │ "reason": "INVALID_REQUEST" │ } │ ], │ "state": "ERROR" │ }