infobloxopen / terraform-provider-infoblox

Infoblox NIOS Terraform Provider
https://github.com/infobloxopen/terraform-provider-infoblox
Mozilla Public License 2.0
73 stars 81 forks source link

Panic in provider when trying to update an imported HOST record that does not have a MAC address #329

Closed mponton-cn closed 7 months ago

mponton-cn commented 9 months ago

Summary

If you import a HOST record (after setting the proper Terraform Internal ID EA) that has an IP with NO MAC address set and then later try to update the record with Terraform, the Infoblox provider will panic.

Steps to Reproduce

Given the follow sample main.tf:

terraform {
  required_version = ">= 1.0.0, < 2.0.0"
  required_providers {
    infoblox = {
      source  = "infobloxopen/infoblox"
      version = ">= 2.5.0, < 3.0.0"
    }
  }
}

resource "infoblox_ip_allocation" "host_record" {
  dns_view   = "internal"
  enable_dns = true
  fqdn       = "panic.sandbox.lab"
  ipv4_addr  = "10.1.52.111"
  #comment    = "Panic at the disco"
}
  1. Ensure the INFOBLOX_(SERVER|USERNAME|PASSWORD) environment variables are set properly or specify authentication info to the provider in some other way.
  2. Adjust the main.tf file for your environment (dns_view, fqdn, and ipv4_addr)
  3. Run terraform init.
  4. Create a new HOST record in Infoblox (using the web UI or another tool than Terraform) with an IP address but NO MAC address. Ensure you set a Terraform Internal ID extensible attribute with a unique value. e.g.:

image

  1. Import the resource, e.g.:
terraform import infoblox_ip_allocation.host_record 9b2ffdfd-aea2-4011-bf94-0c8f4ebc4e1e
  1. Update the main.tf and uncomment the comment input for the resource to trigger an update:
  ...
  comment    = "Panic at the disco"
  ...
  1. terraform apply, the provider will panic
infoblox_ip_allocation.host_record: Refreshing state... [id=d4697fdd-5f18-41e9-9d27-f4aad87fbff8]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # infoblox_ip_allocation.host_record will be updated in-place
  ~ resource "infoblox_ip_allocation" "host_record" {
      + comment             = "Panic at the disco"
        id                  = "d4697fdd-5f18-41e9-9d27-f4aad87fbff8"
        # (10 unchanged attributes hidden)
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

infoblox_ip_allocation.host_record: Modifying... [id=d4697fdd-5f18-41e9-9d27-f4aad87fbff8]
╷
│ Error: Plugin did not respond
│
│   with infoblox_ip_allocation.host_record,
│   on main.tf line 11, in resource "infoblox_ip_allocation" "host_record":
│   11: resource "infoblox_ip_allocation" "host_record" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-infoblox_v2.5.0.exe plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x95a415]

goroutine 27 [running]:
github.com/infobloxopen/terraform-provider-infoblox/infoblox.resourceAllocationUpdate(0xc0003f8280, {0xa65b00, 0xc000487ad0})
        github.com/infobloxopen/terraform-provider-infoblox/infoblox/resource_infoblox_ip_allocation.go:520 +0xd75
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xc25800, {0xc25800, 0xc0003d32f0}, 0xd, {0xa65b00, 0xc000487ad0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.19.0/helper/schema/resource.go:729 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000224b60, {0xc25800, 0xc0003d32f0}, 0xc000304ea0, 0xc0003f8100, {0xa65b00, 0xc000487ad0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.19.0/helper/schema/resource.go:847 +0x9e5
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00021d890, {0xc25800, 0xc0003d3170}, 0xc00038eeb0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.19.0/helper/schema/grpc_provider.go:1021 +0xe3c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000279220, {0xc25800, 0xc0003d2900}, 0xc000191c00)
        github.com/hashicorp/terraform-plugin-go@v0.12.0/tfprotov5/tf5server/server.go:813 +0x551
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xabf3e0, 0xc000279220}, {0xc25800, 0xc0003d2900}, 0xc000191b90, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.12.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000232700, {0xc339e8, 0xc00050e1a0}, 0xc00038b7a0, 0xc00047d3e0, 0x1129360, 0x0)
        google.golang.org/grpc@v1.48.0/server.go:1295 +0xb03
google.golang.org/grpc.(*Server).handleStream(0xc000232700, {0xc339e8, 0xc00050e1a0}, 0xc00038b7a0, 0x0)
        google.golang.org/grpc@v1.48.0/server.go:1636 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.48.0/server.go:932 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.48.0/server.go:930 +0x294

Error: The terraform-provider-infoblox_v2.5.0.exe 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.
  1. Go into the Infoblox web UI and add the MAC address "00:00:00:00:00:00" to the ipv4_addr, e.g.:

image

  1. terraform apply, the provider will succeed:
infoblox_ip_allocation.host_record: Refreshing state... [id=d4697fdd-5f18-41e9-9d27-f4aad87fbff8]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # infoblox_ip_allocation.host_record will be updated in-place
  ~ resource "infoblox_ip_allocation" "host_record" {
      + comment             = "Panic at the disco"
        id                  = "d4697fdd-5f18-41e9-9d27-f4aad87fbff8"
        # (10 unchanged attributes hidden)
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

infoblox_ip_allocation.host_record: Modifying... [id=d4697fdd-5f18-41e9-9d27-f4aad87fbff8]
infoblox_ip_allocation.host_record: Modifications complete after 2s [id=d4697fdd-5f18-41e9-9d27-f4aad87fbff8]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Extra Info

More Context

We are in the process of migrating Terraform code from a module using an non-native way of registering DNS names in Infoblox to the native Infoblox provider. Almost (if not all) HOST records to be imported have no MAC address. This means that without external intervention to update the records and add a dummy address, the resource imported cannot be update in the future. As you can imagine, we would really love to see this issue fixed.

Thanks!

SanjeevManurkar commented 8 months ago

We will add this to our backlog and consider this in future releases. Thank you for highlighting this.

mponton-cn commented 8 months ago

@SanjeevManurkar We opened ticket 00442189 on our end for this. As explained in the context of the original ticket, this will affect a Terraform code migration project very soon and will require us to work around the issue. Issue that is clearly a BUG in the provider and should be resolved. I expected better support from Infoblox considering the situation. This is not a feature request. I'm hoping you can review your position and address this quickly with a simple fix release.

SanjeevManurkar commented 8 months ago

We are considering to include fix for this in next release. I will update on timelines for this release in few days from now.

JkhatriInfobox commented 7 months ago

Hi @mponton-cn , we have fixed this issue with our new release v2.6.0 with PR #334

Hence closing this issue.