IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
336 stars 645 forks source link

Segementation violation in 1.65.1 ibm_database #5397

Open shemau opened 1 month ago

shemau commented 1 month ago

Community Note

Terraform CLI and Terraform IBM Provider Version

terraform v1.5.7 ibm provider 1.65.1

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

https://github.com/terraform-ibm-modules/terraform-ibm-icd-elasticsearch/

resource "ibm_database" "elasticsearch" {
  depends_on                = [time_sleep.wait_for_authorization_policy]
  name                      = var.name
  plan                      = var.plan
  location                  = var.region
  service                   = "databases-for-elasticsearch"
  version                   = var.elasticsearch_version
  resource_group_id         = var.resource_group_id
  service_endpoints         = var.service_endpoints
  tags                      = var.tags
  adminpassword             = var.admin_pass
  key_protect_key           = var.kms_key_crn
  backup_encryption_key_crn = local.backup_encryption_key_crn
  backup_id                 = var.backup_crn

  dynamic "users" {
    for_each = nonsensitive(var.users != null ? var.users : [])
    content {
      name     = users.value.name
      password = users.value.password
      type     = users.value.type
      role     = (users.value.role != "" ? users.value.role : null)
    }
  }

  group {
    group_id = "member"

    memory {
      allocation_mb = var.member_memory_mb
    }

    disk {
      allocation_mb = var.member_disk_mb
    }

    cpu {
      allocation_count = var.member_cpu_count
    }

    members {
      allocation_count = var.members
    }
  }

  ## This for_each block is NOT a loop to attach to multiple auto_scaling blocks.
  ## This block is only used to conditionally add auto_scaling block depending on var.auto_scaling
  dynamic "auto_scaling" {
    for_each = local.auto_scaling_enabled
    content {
      disk {
        capacity_enabled             = var.auto_scaling.disk.capacity_enabled
        free_space_less_than_percent = var.auto_scaling.disk.free_space_less_than_percent
        io_above_percent             = var.auto_scaling.disk.io_above_percent
        io_enabled                   = var.auto_scaling.disk.io_enabled
        io_over_period               = var.auto_scaling.disk.io_over_period
        rate_increase_percent        = var.auto_scaling.disk.rate_increase_percent
        rate_limit_mb_per_member     = var.auto_scaling.disk.rate_limit_mb_per_member
        rate_period_seconds          = var.auto_scaling.disk.rate_period_seconds
        rate_units                   = var.auto_scaling.disk.rate_units
      }
      memory {
        io_above_percent         = var.auto_scaling.memory.io_above_percent
        io_enabled               = var.auto_scaling.memory.io_enabled
        io_over_period           = var.auto_scaling.memory.io_over_period
        rate_increase_percent    = var.auto_scaling.memory.rate_increase_percent
        rate_limit_mb_per_member = var.auto_scaling.memory.rate_limit_mb_per_member
        rate_period_seconds      = var.auto_scaling.memory.rate_period_seconds
        rate_units               = var.auto_scaling.memory.rate_units
      }
    }
  }

  lifecycle {
    ignore_changes = [
      # Ignore changes to these because a change will destroy and recreate the instance
      version,
      key_protect_key,
      backup_encryption_key_crn
    ]
  }

  timeouts {
    create = "120m" #Extending provisioning time to 120 minutes
  }
}

Debug Output

Panic Output

│ Error: Plugin did not respond
│ 
│   with module.elasticsearch.module.elasticsearch.ibm_database.elasticsearch,
│   on ../../main.tf line 45, in resource "ibm_database" "elasticsearch":
│   45: resource "ibm_database" "elasticsearch" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may contain
│ more details.
╵

Stack trace from the terraform-provider-ibm_v1.65.1 plugin:

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

goroutine 60 [running]:
[github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5.(*CloudDatabasesV5).GetEnableGzipCompression(...)](http://github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5.(*CloudDatabasesV5).GetEnableGzipCompression(...))
    [github.com/IBM/cloud-databases-go-sdk@v0.7.0/clouddatabasesv5/cloud_databases_v5.go:179](http://github.com/IBM/cloud-databases-go-sdk@v0.7.0/clouddatabasesv5/cloud_databases_v5.go:179)
[github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5.(*CloudDatabasesV5).GetDefaultScalingGroupsWithContext](http://github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5.(*CloudDatabasesV5).GetDefaultScalingGroupsWithContext)(0x0, {0x520fd60?, 0xc000060048}, 0xc0019515f0)
    [github.com/IBM/cloud-databases-go-sdk@v0.7.0/clouddatabasesv5/cloud_databases_v5.go:1595](http://github.com/IBM/cloud-databases-go-sdk@v0.7.0/clouddatabasesv5/cloud_databases_v5.go:1595) +0x26c
[github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5.(*CloudDatabasesV5).GetDefaultScalingGroups](http://github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5.(*CloudDatabasesV5).GetDefaultScalingGroups)(0xc000779c20?, 0xc00234b940?)
    [github.com/IBM/cloud-databases-go-sdk@v0.7.0/clouddatabasesv5/cloud_databases_v5.go:1571](http://github.com/IBM/cloud-databases-go-sdk@v0.7.0/clouddatabasesv5/cloud_databases_v5.go:1571) +0x2a
[github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database.getDefaultScalingGroups](http://github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database.getDefaultScalingGroups)({0xc00234b940, 0x1b}, {0xc00155de70, 0xa}, {0x0, 0x0}, {0x4885ea0?, 0xc00066ca80})
    [github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database/resource_ibm_database.go:1065](http://github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database/resource_ibm_database.go:1065) +0x36c
[github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database.validateGroupsDiff](http://github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database.validateGroupsDiff)({0x0?, 0x0?}, 0xc001bd4e80, {0x4885ea0, 0xc00066ca80})
    [github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database/resource_ibm_database.go:2928](http://github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database/resource_ibm_database.go:2928) +0x1fb
[github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff.All.func1](http://github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff.All.func1)({0x520fdd0, 0xc0016f5680}, 0x0?, {0x4885ea0, 0xc00066ca80})
    [github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/customdiff/compose.go:53](http://github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/customdiff/compose.go:53) +0xb1
[github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider.wrapCustomizeDiff.func1](http://github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider.wrapCustomizeDiff.func1)({0x520fdd0?, 0xc0016f5680?}, 0x48b9a66?, {0x4885ea0?, 0xc00066ca80?})
    [github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider/provider.go:1582](http://github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider/provider.go:1582) +0x44
[github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.Diff](http://github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.Diff)(0xc000a30780, {0x520fdd0, 0xc0016f5680}, 0xc0016b76c0, 0xc001753800, 0xc000910200, {0x4885ea0, 0xc00066ca80}, 0x0)
    [github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/schema.go:698](http://github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/schema.go:698) +0x4d4
[github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).SimpleDiff](http://github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).SimpleDiff)(0x5210bd0?, {0x520fdd0?, 0xc0016f5680?}, 0xc0016b76c0, 0x4129fe0?, {0x4885ea0?, 0xc00066ca80?})
    [github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:962](http://github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:962) +0xe5
[github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange](http://github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange)(0xc000abd530, {0x520fdd0?, 0xc0016f5560?}, 0xc001656050)
    [github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:780](http://github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:780) +0xa09
[github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).PlanResourceChange](http://github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).PlanResourceChange)(0xc000a1c3c0, {0x520fdd0?, 0xc0016f4390?}, 0xc0015bf490)
    [github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:824](http://github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:824) +0x574
[github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_PlanResourceChange_Handler](http://github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_PlanResourceChange_Handler)({0x46fe9e0?, 0xc000a1c3c0}, {0x520fdd0, 0xc0016f4390}, 0xc0015bf420, 0x0)
    [github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:449](http://github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:449) +0x170
[google.golang.org/grpc.(*Server).processUnaryRPC](http://google.golang.org/grpc.(*Server).processUnaryRPC)(0xc0009961e0, {0x521abe0, 0xc0014dc820}, 0xc0016a9d40, 0xc0014b76e0, 0x726d080, 0x0)
    [google.golang.org/grpc@v1.57.1/server.go:1358](http://google.golang.org/grpc@v1.57.1/server.go:1358) +0xe23
[google.golang.org/grpc.(*Server).handleStream](http://google.golang.org/grpc.(*Server).handleStream)(0xc0009961e0, {0x521abe0, 0xc0014dc820}, 0xc0016a9d40, 0x0)
    [google.golang.org/grpc@v1.57.1/server.go:1735](http://google.golang.org/grpc@v1.57.1/server.go:1735) +0xa2f
[google.golang.org/grpc.(*Server).serveStreams.func1.1()](http://google.golang.org/grpc.(*Server).serveStreams.func1.1())
    [google.golang.org/grpc@v1.57.1/server.go:970](http://google.golang.org/grpc@v1.57.1/server.go:970) +0xca
created by [google.golang.org/grpc.(*Server).serveStreams.func1](http://google.golang.org/grpc.(*Server).serveStreams.func1)
    [google.golang.org/grpc@v1.57.1/server.go:981](http://google.golang.org/grpc@v1.57.1/server.go:981) +0x15c

Error: The terraform-provider-ibm_v1.65.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.
}

Expected Behavior

This is running off our main branch, where before merging it passed and created an elastic search ICD instance.

Actual Behavior

Steps to Reproduce

  1. terraform apply

Important Factoids

References

alexhemard commented 1 month ago

@shemau Can you provide values for the variables you are using?

shemau commented 1 month ago

I will try and narrow it down and gather those values @alexhemard

shemau commented 1 month ago

It has something to do with the group block. When commented out, it passes, otherwise it fails:

  + resource "ibm_database" "elasticsearch" {
      + adminuser                 = (known after apply)
      + backup_encryption_key_crn = (known after apply)
      + configuration_schema      = (known after apply)
      + connectionstrings         = (known after apply)
      + groups                    = (known after apply)
      + guid                      = (known after apply)
      + id                        = (known after apply)
      + key_protect_key           = (known after apply)
      + location                  = "us-south"
      + name                      = "steve-es"
      + plan                      = "enterprise"
      + resource_controller_url   = (known after apply)
      + resource_crn              = (known after apply)
      + resource_group_id         = (known after apply)
      + resource_group_name       = (known after apply)
      + resource_name             = (known after apply)
      + resource_status           = (known after apply)
      + service                   = "databases-for-elasticsearch"
      + service_endpoints         = "private"
      + status                    = (known after apply)
      + tags                      = (known after apply)
      + version                   = "8.12"

      + timeouts {
          + create = "120m"
        }
    }

gives the base values.

the group block values are:

   group {
    group_id = "member"

    memory {
      allocation_mb = 4096 # also tried 1024
    }

    disk {
      allocation_mb = 5120
    }

    cpu {
      allocation_count = 0
    }

    members {
      allocation_count = 3
    }
  }
shemau commented 4 weeks ago

@alexhemard any news on this? This is a total blocker, we are pushing up provider levels to get necessary fixes (and features) and this is blocking progress.

I have recreate on 1.66.0 to demonstrate that the problem still exists in the latest version.

│ Error: Plugin did not respond
│ 
│   with module.elasticsearch.module.elasticsearch.ibm_database.elasticsearch,
│   on ../../main.tf line 45, in resource "ibm_database" "elasticsearch":
│   45: resource "ibm_database" "elasticsearch" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).PlanResourceChange call. The plugin logs may
│ contain more details.
╵

Stack trace from the terraform-provider-ibm_v1.66.0 plugin:

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

goroutine 87 [running]:
github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5.(*CloudDatabasesV5).GetEnableGzipCompression(...)
        github.com/IBM/cloud-databases-go-sdk@v0.7.0/clouddatabasesv5/cloud_databases_v5.go:179
github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5.(*CloudDatabasesV5).GetDefaultScalingGroupsWithContext(0x0, {0xae78580, 0xd1089c0}, 0xc0019b82a0)
        github.com/IBM/cloud-databases-go-sdk@v0.7.0/clouddatabasesv5/cloud_databases_v5.go:1595 +0x267
github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5.(*CloudDatabasesV5).GetDefaultScalingGroups(0xc00290b0e0?, 0xc0004da4e0?)
        github.com/IBM/cloud-databases-go-sdk@v0.7.0/clouddatabasesv5/cloud_databases_v5.go:1571 +0x25
github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database.getDefaultScalingGroups({0xc0004da4e0, 0x1b}, {0xc0029feda4, 0xa}, {0x0, 0x0}, {0xae1c660?, 0xc0017a2008?})
        github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database/resource_ibm_database.go:1065 +0x3c5
github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database.validateGroupsDiff({0x0?, 0x0?}, 0xc00221ca00, {0xae1c660, 0xc0017a2008})
        github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database/resource_ibm_database.go:2949 +0x1dc
github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database.ResourceIBMDatabaseInstance.All.func3({0xae784a0, 0xc002a85830}, 0xc00221ca00, {0xae1c660, 0xc0017a2008})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/customdiff/compose.go:53 +0xab
github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider.wrapResource.wrapCustomizeDiff.func17({0xae784a0?, 0xc002a85830?}, 0x9669be8?, {0xae1c660?, 0xc0017a2008?})
        github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider/provider.go:1636 +0x3e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.Diff(0xc0012020f0, {0xae784a0, 0xc002a85830}, 0xc002a8b930, 0xc0022b2b10, 0xc00085ab40, {0xae1c660, 0xc0017a2008}, 0x0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/schema.go:698 +0x4b4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).SimpleDiff(0xae78708?, {0xae784a0?, 0xc002a85830?}, 0xc002a8b930, 0xc002a85860?, {0xae1c660?, 0xc0017a2008?})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:962 +0xdb
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange(0xc000a76e70, {0xae784a0?, 0xc002a85770?}, 0xc0029a4460)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/grpc_provider.go:780 +0x996
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).PlanResourceChange(0xc00079ad20, {0xae784a0?, 0xc002a84420?}, 0xc002a83110)
        github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/tf5server/server.go:824 +0x56f
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_PlanResourceChange_Handler({0xac8ece0, 0xc00079ad20}, {0xae784a0, 0xc002a84420}, 0xc002a830a0, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:449 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000a80000, {0xae84460, 0xc0013dc000}, 0xc002a9c000, 0xc001706720, 0xd06e7c0, 0x0)
        google.golang.org/grpc@v1.57.1/server.go:1358 +0xde3
google.golang.org/grpc.(*Server).handleStream(0xc000a80000, {0xae84460, 0xc0013dc000}, 0xc002a9c000, 0x0)
        google.golang.org/grpc@v1.57.1/server.go:1735 +0x9da
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/grpc@v1.57.1/server.go:970 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 86
        google.golang.org/grpc@v1.57.1/server.go:981 +0x136

Error: The terraform-provider-ibm_v1.66.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.
omaraibrahim commented 4 weeks ago

Hi @shemau! Unfortunately, I cannot replicate the issue on the latest provider.

The following configuration

resource "ibm_database" "elasticsearch" {
  name                      = "test-icd-elasticsearch"
  plan                      = "enterprise"
  location                  = "us-south"
  service                   = "databases-for-elasticsearch"
  version                   = "8.12"
  resource_group_id         = "default"
  service_endpoints         = "private"

  group {
    group_id = "member"

    memory {
      allocation_mb = 4096
    }

    disk {
      allocation_mb = 5120
    }

    cpu {
      allocation_count = 0
    }

    members {
      allocation_count = 3
    }
  }
}

Works fine for me. Can you please provide the debug logs (export TF_LOG=DEBUG) so I can best help you?

Thanks!