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

[Bug]: runtime error: invalid memory address or nil pointer dereference when create or destroy VM #808

Closed
o-presentini opened this issue Nov 4, 2024 · 0 comments · Fixed by #809
Labels
bug Something isn't working

Comments

@o-presentini
Copy link

Terraform Core Version

1.5.7

Cloud Avenue Provider Version

0.19.1

Affected Resource(s)

resource "cloudavenue_vm"

Expected Behavior

Create and destroy bulk VM with for_each vars.


Main:

module "build_vms" {
  source    = "../../modules/vms"

  providers = {
    cloudavenue.main = cloudavenue.main
  }

  vdc_name  = data.cloudavenue_vdc.this.name

  for_each    = { for vm in var.vms : lower(vm.name) => vm }
  
  vapp_name   = module.build_vapps.vapp_name
  replicat    = each.value.replicat
  name        = each.value.name
  description = each.value.description

  accept_all_eulas = each.value.accept_all_eulas
  boot_image       = each.value.boot_image
  vapp_template    = each.value.vapp_template

  cpu_hot_add_enabled    = each.value.cpu_hot_add_enabled
  cpus                   = each.value.cpus
  cpus_cores             = each.value.cpus_cores
  memory                 = each.value.memory # in Mb
  memory_hot_add_enabled = each.value.memory_hot_add_enabled
  networks               = each.value.networks

  affinity_rule_id = each.value.affinity_rule_id

  admin_password                      = each.value.admin_password
  allow_local_admin_password          = each.value.allow_local_admin_password
  change_sid                          = each.value.change_sid
  enabled                             = each.value.enabled
  force                               = each.value.force
  hostname                            = each.value.hostname
  init_script                         = each.value.init_script
  join_domain                         = each.value.join_domain
  join_domain_account_ou              = each.value.join_domain_account_ou
  join_domain_name                    = each.value.join_domain_name
  join_domain_password                = each.value.join_domain_password
  join_domain_user                    = each.value.join_domain_user
  join_org_domain                     = each.value.join_org_domain
  must_change_password_on_first_login = each.value.must_change_password_on_first_login
  number_of_auto_logons               = each.value.number_of_auto_logons

  guest_properties = each.value.guest_properties
  os_type          = each.value.os_type
  # storage_profile              => Force usage of vDC default storage
  power_on = each.value.power_on

  disks = each.value.disks

  depends_on = [
    module.build_vapps
  ]
}

Module:

resource "cloudavenue_vm" "main" {
  vdc       = var.vdc_name
  vapp_name = var.vapp_name

  count = var.replicat

  name        = var.replicat == 1 ? var.name : format("%s-%04d", var.name, (count.index + 1))
  description = var.description
  deploy_os = try(local.deploy_os, null)

  resource = {
    cpu_hot_add_enabled    = var.cpu_hot_add_enabled
    cpus                   = var.cpus
    cpus_cores             = var.cpus_cores
    memory                 = var.memory # in Mb
    memory_hot_add_enabled = var.memory_hot_add_enabled
    networks               = try(local.attach_networks, null)
  }
  settings = {
    affinity_rule_id = var.affinity_rule_id
    customization = {
      admin_password                      = var.admin_password
      allow_local_admin_password          = var.allow_local_admin_password
      auto_generate_password              = var.admin_password != null ? null : true
      change_sid                          = var.change_sid
      enabled                             = var.enabled
      force                               = var.force
      hostname                            = var.hostname
      init_script                         = var.init_script
      join_domain                         = var.join_domain
      join_domain_account_ou              = var.join_domain_account_ou
      join_domain_name                    = var.join_domain_name
      join_domain_password                = var.join_domain_password
      join_domain_user                    = var.join_domain_user
      join_org_domain                     = var.join_org_domain
      must_change_password_on_first_login = var.must_change_password_on_first_login
      number_of_auto_logons               = var.number_of_auto_logons
    }
    expose_hardware_virtualization = true
    guest_properties               = var.guest_properties
    os_type                        = var.os_type
    # storage_profile              => Force usage of vDC default storage
  }
  state = {
    power_on = var.power_on
  }
}

Actual Behavior

Failed to destroy VM, panic

Relevant Error/Panic Output Snippet

╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ReadResource call. The plugin logs may contain more
│ details.
╵

Stack trace from the terraform-provider-cloudavenue_v0.19.1 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x130f04d]

goroutine 84 [running]:
github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/vm.(*VM).CustomizationRead(0xc00010c688?, {0xc00010ce78?, 0xc000c4ec48?})
        github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/vm/settings_customization.go:100 +0x6d
github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/vm.VM.SettingsRead({0xc00010c688, {0xc00010ce78, {0xc000c4ec48, 0xc00007c438}}}, {0x1d5d588, 0xc000c655c0}, {0x1691fe0, 0xc000c9ee58})
        github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/vm/settings.go:87 +0x153
github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vm.(*vmResource).read(0xc00088ec60, {0x1d5d588, 0xc000c655c0}, 0xc0005ce4b0, 0xc0005ce4b0)
        github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vm/vm_resource.go:1272 +0x52c
github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vm.(*vmResource).Read(0xc00088ec60, {0x1d5d588, 0xc000c655c0}, {{{{0x1d69db0, 0xc000cab890}, {0x1500ea0, 0xc000caab70}}, {0x1d6cf78, 0xc00010be50}}, 0xc00010c480, ...}, ...)
        github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/vm/vm_resource.go:284 +0x432
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ReadResource(0xc000416960, {0x1d5d588, 0xc000c655c0}, 0xc000c65620, 0xc000d6b6c0)
        github.com/hashicorp/[email protected]/internal/fwserver/server_readresource.go:117 +0x84e
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ReadResource(0xc000416960, {0x1d5d588?, 0xc000c654d0?}, 0xc0007eb8c0)
        github.com/hashicorp/[email protected]/internal/proto6server/server_readresource.go:55 +0x38e
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadResource(0xc0004d95e0, {0x1d5d588?, 0xc000c64d50?}, 0xc0008b0000)
        github.com/hashicorp/[email protected]/tfprotov6/tf6server/server.go:784 +0x309
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadResource_Handler({0x16ac660, 0xc0004d95e0}, {0x1d5d588, 0xc000c64d50}, 0xc000924f80, 0x0)
        github.com/hashicorp/[email protected]/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:482 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001a1200, {0x1d5d588, 0xc000c64cc0}, {0x1d6b100, 0xc000420780}, 0xc000b490e0, 0xc0005bb560, 0x295ea08, 0x0)
        google.golang.org/[email protected]/server.go:1369 +0xdf8
google.golang.org/grpc.(*Server).handleStream(0xc0001a1200, {0x1d6b100, 0xc000420780}, 0xc000b490e0)
        google.golang.org/[email protected]/server.go:1780 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/[email protected]/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 32
        google.golang.org/[email protected]/server.go:1030 +0x125

Error: The terraform-provider-cloudavenue_v0.19.1 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Terraform Configuration Files

terraform {
  required_providers {
    cloudavenue = {
      source = "orange-cloudavenue/cloudavenue"
      version = "0.19.1"
    }
    vcd = {
      source = "vmware/vcd"
      version = "3.14.0"
    }
  }
  required_version = ">=1.0"
}

Steps to Reproduce

Create vDC + network and vApps

Use tfvars:

vms = [{
    name          = "Bastion"
    vapp_template = "Orange-Linux-Internal-old#ROCKY_9.3"
    cpus       = 4
    cpus_cores = 2
    memory     = 2048
    admin_password = "root"
    init_script = "loadkeys fr"
    power_on   = true
    networks = [
    {
      name               = "opr-public-network"
      type               = "org"
      ip                 = "192.168.0.2"
      ip_allocation_mode = "MANUAL"
      is_primary         = true
    }]
    guest_properties = {
      "provide" = "Terraform"
      "product" = "CEPH"
      "role"    = "monitoring"
    }
    storage_profile = "gold"
    disks = []
  },{
    name          = "Master"
    replicat      = 3
    vapp_template = "Orange-Linux-Internal-old#ROCKY_9.3"
    cpus       = 4
    cpus_cores = 2
    memory     = 8192
    admin_password = "root"
    init_script = "loadkeys fr"
    power_on   = true
    networks = [
    {
      name               = "opr-public-network"
      type               = "org"
      ip_allocation_mode = "DHCP"
      is_primary         = true
    },
    {
      name               = "opr-vapp-cluster-ceph"
      type               = "vapp"
      ip_allocation_mode = "POOL"
    }]
    guest_properties = {
      "provide" = "Terraform"
      "product" = "CEPH"
      "role"    = "monitoring"
    }
    storage_profile = "gold"
    disks = [{
      name            = "data"
      size_in_mb      = 20480
    }]
  },{
    name          = "Storage"
    replicat      = 4
    vapp_template = "Orange-Linux-Internal-old#ROCKY_9.3"
    cpus       = 8
    cpus_cores = 4
    memory     = 8192
    admin_password = "root"
    init_script = "loadkeys fr"
    power_on   = true
    networks = [
    {
      name               = "opr-public-network"
      type               = "org"
      ip_allocation_mode = "DHCP"
      is_primary         = true
    },
    {
      name               = "opr-vapp-cluster-ceph"
      type               = "vapp"
      ip_allocation_mode = "POOL"
    }]
    guest_properties = {
      "provide" = "Terraform"
      "product" = "CEPH"
      "role"    = "storage"
    }
    storage_profile = "gold"
    disks = [{
      name            = "data"
      size_in_mb      = 204800
    }]
  },
]

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

@o-presentini o-presentini added the bug Something isn't working label Nov 4, 2024
@azrod azrod linked a pull request Nov 4, 2024 that will close this issue
3 tasks
@azrod azrod closed this as completed in #809 Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant