cloudamqp / terraform-provider-cloudamqp

Terraform Provider for CloudAMQP
https://registry.terraform.io/providers/cloudamqp/cloudamqp
Mozilla Public License 2.0
35 stars 39 forks source link

terraform-provider-cloudamqp_v1.32.0 plugin: panic: interface conversion: interface {} is nil, not int #299

Open setv-n13 opened 2 days ago

setv-n13 commented 2 days ago

I prepared a custom cloudamqp module which includes the following templates:

variable "plugins" {
  type        = list(any)
  default     = []
}
variable "community_plugins" {
  type        = list(any)
  default     = []
}

## plugins
resource "cloudamqp_plugin" "rabbitmq_plugin" {
  for_each = {
    for i, plugin in var.plugins :
      plugin.name => {
        name    = plugin.name
        enabled = try(plugin.enabled, true)
      }
  }
  instance_id = cloudamqp_instance.instance.id
  name        = each.value.name
  enabled     = each.value.enabled
}
resource "cloudamqp_plugin_community" "rabbitmq_community_plugin" {
  for_each = {
    for i, plugin in var.community_plugins :
      plugin.name => {
        name    = plugin.name
        enabled = try(plugin.enabled, true)
      }
  }
  instance_id = cloudamqp_instance.instance.id
  name        = each.value.name
  enabled     = each.value.enabled
}
data "cloudamqp_plugins" "plugins" {
  count       = length(var.plugins) > 0 ? 1 : 0
  instance_id = cloudamqp_instance.instance.id
}
data "cloudamqp_plugins_community" "community_plugins" {
  count       = length(var.community_plugins) > 0 ? 1 : 0
  instance_id = cloudamqp_instance.instance.id
}

Then I successfully used this module to create a cluster and other related resources (but without any plugins):

module "rabbitmq" {
  source = "git@bitbucket.org:americor/terraform-modules.git//cloudamqp/v1?ref=main"

  name   = local.common_name
  region = local.cloudamqp_region
  ##
  plan            = var.plan
  nodes           = var.nodes
  rmq_version     = var.rmq_version
  extra_disk_size = var.extra_disk_size
  ## configuration, plugins
  cloudamqp_rabbitmq_configuration = var.cloudamqp_rabbitmq_configuration
  plugins                          = var.plugins
  community_plugins                = var.community_plugins
  ##
  create_vpc = var.create_vpc
  vpc_cidr   = var.vpc_cidr
  ##
  create_vpc_peering = var.create_vpc_peering
  aws_vpc_id         = data.terraform_remote_state.common.outputs.vpc_id
  ##
  ####
  enable_cloudwatch_log_integration        = var.enable_cloudwatch_log_integration
  enable_cloudwatch_monitoring_integration = var.enable_cloudwatch_monitoring_integration
  aws_integration_region                   = var.aws_region
  aws_access_key_id                        = var.aws_access_key_id
  aws_secret_access_key                    = var.aws_secret_access_key
  ####
  enable_datadog_log_integration        = var.enable_datadog_log_integration
  enable_datadog_monitoring_integration = var.enable_datadog_monitoring_integration
  datadog_integration_region            = var.datadog_integration_region
  api_key                               = var.dd_api_key
  ##
  add_firewall_rules = var.add_firewall_rules
  firewall_rules     = local.firewall_rules
  ##
  tags     = local.tags_list
  aws_tags = merge(
    local.aws_tags,
    { Name = "${var.prefix}-${var.environment}-${var.basic_name}-common-vpc" }
  )
}

Later I tried to add a community plugin updating the related variable:

community_plugins = [
  {
    name    = "rabbitmq_delayed_message_exchange"
    enabled = true
  }
]

But this change causes a crash. terraform plan Output:

│ Error: Plugin did not respond
│ 
│   with data.cloudamqp_instance.instance_info,
│   on k8s-vpc-peering.tf line 31, in data "cloudamqp_instance" "instance_info":
│   31: data "cloudamqp_instance" "instance_info" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ValidateDataResourceConfig call. The plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with module.rabbitmq.data.cloudamqp_instance.instance_info,
│   on .terraform/modules/rabbitmq/cloudamqp/v1/instance.tf line 10, in data "cloudamqp_instance" "instance_info":
│   10: data "cloudamqp_instance" "instance_info" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The plugin logs may contain more details.
╵
╷
│ Error: Request cancelled
│ 
│   with module.rabbitmq.cloudamqp_rabbitmq_configuration.rabbitmq_config,
│   on .terraform/modules/rabbitmq/cloudamqp/v1/instance.tf line 28, in resource "cloudamqp_rabbitmq_configuration" "rabbitmq_config":
│   28: resource "cloudamqp_rabbitmq_configuration" "rabbitmq_config" {
│ 
│ The plugin.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Plugin did not respond
│ 
│   with module.rabbitmq.data.cloudamqp_nodes.list_nodes,
│   on .terraform/modules/rabbitmq/cloudamqp/v1/instance.tf line 41, in data "cloudamqp_nodes" "list_nodes":
│   41: data "cloudamqp_nodes" "list_nodes" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The plugin logs may contain more details.
╵
╷
│ Error: Request cancelled
│ 
│   with module.rabbitmq.cloudamqp_plugin_community.rabbitmq_community_plugin["rabbitmq_delayed_message_exchange"],
│   on .terraform/modules/rabbitmq/cloudamqp/v1/instance.tf line 94, in resource "cloudamqp_plugin_community" "rabbitmq_community_plugin":
│   94: resource "cloudamqp_plugin_community" "rabbitmq_community_plugin" {
│ 
│ The plugin.(*GRPCProvider).ValidateResourceConfig request was cancelled.
╵
╷
│ Error: Plugin did not respond
│ 
│   with module.rabbitmq.data.cloudamqp_plugins_community.community_plugins[0],
│   on .terraform/modules/rabbitmq/cloudamqp/v1/instance.tf line 111, in data "cloudamqp_plugins_community" "community_plugins":
│  111: data "cloudamqp_plugins_community" "community_plugins" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The plugin logs may contain more details.
╵
╷
│ Error: Request cancelled
│ 
│   with module.rabbitmq.cloudamqp_integration_log.cloudwatch[0],
│   on .terraform/modules/rabbitmq/cloudamqp/v1/logs-monitoring.tf line 3, in resource "cloudamqp_integration_log" "cloudwatch":
│    3: resource "cloudamqp_integration_log" "cloudwatch" {
│ 
│ The plugin.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Request cancelled
│ 
│   with module.rabbitmq.cloudamqp_integration_metric.datadog_v2[0],
│   on .terraform/modules/rabbitmq/cloudamqp/v1/logs-monitoring.tf line 31, in resource "cloudamqp_integration_metric" "datadog_v2":
│   31: resource "cloudamqp_integration_metric" "datadog_v2" {
│ 
│ The plugin.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Plugin did not respond
│ 
│   with module.rabbitmq.data.cloudamqp_vpc_info.vpc_info[0],
│   on .terraform/modules/rabbitmq/cloudamqp/v1/vpc.tf line 13, in data "cloudamqp_vpc_info" "vpc_info":
│   13: data "cloudamqp_vpc_info" "vpc_info" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-cloudamqp_v1.32.0 plugin:

panic: interface conversion: interface {} is nil, not int

goroutine 42 [running]:
github.com/cloudamqp/terraform-provider-cloudamqp/cloudamqp.dataSourcePluginsCommunityRead(0xc00006c600, {0x4668b40?, 0xc0004970f0})
        github.com/cloudamqp/terraform-provider-cloudamqp/cloudamqp/data_source_cloudamqp_plugins_community.go:61 +0x5a9
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x4676840?, {0x4676840?, 0xc000492cf0?}, 0xd?, {0x4668b40?, 0xc0004970f0?})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:783 +0x15f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0xc0000d8a80, {0x4676840, 0xc000492cf0}, 0xc00006c500, {0x4668b40, 0xc0004970f0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:1015 +0x13a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadDataSource(0xc000012288, {0x4676840?, 0xc000492c00?}, 0xc00054c040)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/grpc_provider.go:1291 +0x34e
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadDataSource(0xc0000f80a0, {0x4676840?, 0xc0004923c0?}, 0xc0001726e0)
        github.com/hashicorp/terraform-plugin-go@v0.22.0/tfprotov5/tf5server/server.go:686 +0x40c
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadDataSource_Handler({0x4645f20, 0xc0000f80a0}, {0x4676840, 0xc0004923c0}, 0xc00006c080, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.22.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:572 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000e4000, {0x4676840, 0xc000492330}, {0x467af40, 0xc0000df040}, 0xc000548000, 0xc0000cd7d0, 0x4bbd520, 0x0)
        google.golang.org/grpc@v1.61.1/server.go:1385 +0xdd1
google.golang.org/grpc.(*Server).handleStream(0xc0000e4000, {0x467af40, 0xc0000df040}, 0xc000548000)
        google.golang.org/grpc@v1.61.1/server.go:1796 +0xfb8
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.61.1/server.go:1029 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 12
        google.golang.org/grpc@v1.61.1/server.go:1040 +0x125

Error: The terraform-provider-cloudamqp_v1.32.0 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.

If I try to modify/create any other resources in the module besides cloudamqp_plugin and cloudamqp_plugin_community - everything works fine. Also if I try to create cloudamqp_plugin_community resource outside the module with:

resource "cloudamqp_plugin_community" "rabbitmq_community_plugin" {
  for_each = {
    for i, plugin in var.community_plugins :
      try(plugin.name, plugin) => {
        name    = plugin.name
        enabled = try(plugin.enabled, true)
      }
  }
  instance_id = module.rabbitmq.instance_id
  name        = each.value.name
  enabled     = each.value.enabled
}

this works fine:

...
Terraform will perform the following actions:

  # cloudamqp_plugin_community.rabbitmq_community_plugin["rabbitmq_delayed_message_exchange"] will be created
  + resource "cloudamqp_plugin_community" "rabbitmq_community_plugin" {
      + description = (known after apply)
      + enabled     = true
      + id          = (known after apply)
      + instance_id = 264927
      + name        = "rabbitmq_delayed_message_exchange"
      + require     = (known after apply)
      + sleep       = 10
      + timeout     = 1800
    }
...

Can you please advise if this is a problem with my code or the provider issue?

dentarg commented 2 days ago

this works fine

Did you try this after the above crash or did you try enabling the plugin on a cluster where you didn't have tried enabling it before?

dentarg commented 2 days ago

If you can post the code for a complete (but shorter) module with only cloudamqp_plugin and/or cloudamqp_plugin_community we can try it our end

setv-n13 commented 1 day ago

Did you try this after the above crash or did you try enabling the plugin on a cluster where you didn't have tried enabling it before? I tried to enable a plugin in a cluster where no modules were enabled before.

First, I tried doing it via module - It caused a crash, then I tried to enable a plugin in the same cluster but with cloudamqp_plugin_community resource outside the module - It worked.

If you can post the code for a complete (but shorter) module with only cloudamqp_plugin and/or cloudamqp_plugin_community we can try it our end

here is the complete module: https://github.com/setv-n13/terraform-cloudamqp-module