hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.64k forks source link

The terraform-provider-azurerm_v3.91.0_x5 plugin crashed due to infinite message retention eventhub resource imported #27418

Open yueshao37 opened 1 month ago

yueshao37 commented 1 month ago

Is there an existing issue for this?

Community Note

Terraform Version

1.7.5

AzureRM Provider Version

3.91.0

Affected Resource(s)/Data Source(s)

terraform-provider-azurerm_v3.91.0_x5, azurerm_eventhub

Terraform Configuration Files

resource "azurerm_eventhub" "event_hubs" {
  for_each = { for eh in flatten([for namespace, eventhubs_list in var.eventhubs : [
    for eh in eventhubs_list : {
      name                = eh.name
      namespace_name      = eh.namespace_name
      resource_group_name = eh.resource_group_name
      partition_count     = eh.partition_count
      message_retention   = eh.message_retention
      status              = eh.status
    }
  ]]) : "${eh.namespace_name}-${eh.name}" => eh }

  name                = each.value.name
  namespace_name      = each.value.namespace_name
  resource_group_name = each.value.resource_group_name
  partition_count     = each.value.partition_count
  message_retention   = each.value.message_retention
  status              = each.value.status
}

Debug Output/Panic Output

We got the following error in terraform plan.
Stack trace from the terraform-provider-azurerm_v3.91.0_x5 plugin:

panic: Error reading level state: strconv.ParseInt: parsing "9223372036854776000": value out of range

goroutine 146 [running]:
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*ResourceData).get(0xc00369aa00, {0xc002cc3aa0, 0x1, 0x1}, 0x8?)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource_data.go:556 +0x333
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*ResourceData).State(0xc00369aa00)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource_data.go:354 +0x473
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ShimInstanceStateFromValue(0xc0010ce1c0, {{{0x94e3278?, 0xc001bca438?}}, {0x7d6a4c0?, 0xc002cda210?}})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:670 +0x1d8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc000b826d8, {0x94e07d0?, 0xc002cb98f0?}, 0xc00366c940)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:623 +0x1f3
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc0013972c0, {0x94e07d0?, 0xc002cb8f30?}, 0xc00012d7a0)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:789 +0x48b
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x888f940?, 0xc0013972c0}, {0x94e07d0, 0xc002cb8f30}, 0xc0006de070, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:431 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002ae1e0, {0x9507500, 0xc001b00680}, 0xc002ccc000, 0xc001a86c30, 0xf038e68, 0x0)
    google.golang.org/grpc@v1.58.3/server.go:1374 +0xde7
google.golang.org/grpc.(*Server).handleStream(0xc0002ae1e0, {0x9507500, 0xc001b00680}, 0xc002ccc000, 0x0)
    google.golang.org/grpc@v1.58.3/server.go:1751 +0x9e7
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.58.3/server.go:986 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 55
    google.golang.org/grpc@v1.58.3/server.go:997 +0x145

Error: The terraform-provider-azurerm_v3.91.0_x5 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.

2024-09-18T04:01:06.988Z [DEBUG] provider: plugin exited

We found 9223372036854776000 is from one imported eventhub resource, which is created from azure portal with infinite retention time enabled. Here is the state file details.
        {
          "index_key": "<index_key>",
          "schema_version": 0,
          "attributes": {
            "capture_description": [],
            "id": "<id>",
            "message_retention": 9223372036854776000,
            "name": "<name>",
            "namespace_name": "<namespace_name>",
            "partition_count": 1,
            "partition_ids": [
              "0"
            ],
            "resource_group_name": "<resource_group_name>",
            "status": "Active",
            "timeouts": null
          },
          "sensitive_attributes": [],
          "private": "<private>"
        }

Also from provider document, maximum value of message_retention is 7 days, could be related to the error.
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub#message_retention

Expected Behaviour

After imported the infinite retention time eventhub resource, no error should occur during terraform plan.

Actual Behaviour

provider plugin crashed.

Steps to Reproduce

  1. create an eventhub with Infinite retention time enabled from azure portal Screenshot 2024-09-18 at 16 16 29

  2. terraform import the resource

  3. terrafrom plan

Important Factoids

No response

References

No response

sinbai commented 1 month ago

Hi @yueshao37 thanks for opening this issue. I would like to explain that Terraform performs CRUD management on Azure resources based on Azure Rest API. According to the API definition, the type of messageRetentionInDays is int64, and the maximum value of int64 should usually be 9223372036854775807. However, the 9223372036854776000 returned by the API is greater than 9223372036854775807. This is the root cause of the crash. Therefore, it is recommended to contact Microsoft Support to solve the problem of inconsistency between the API definition and the actual situation.

In addition, the crash occurred in terraform-plugin-sdk instead of terraform-provider-azurerm.