ionos-cloud / terraform-provider-ionoscloud

The IonosCloud Terraform provider gives the ability to deploy and configure resources using the IonosCloud APIs.
Mozilla Public License 2.0
35 stars 24 forks source link

Crash when adjusting number of nodes in ionoscloud_k8s_node_pool #219

Closed djjudas21 closed 2 years ago

djjudas21 commented 2 years ago

Description

The ionoscloud provider crashes when I try to increase the node count in an existing node pool

Expected behavior

Environment

Terraform version:

[jgazeley@hephaestos ~]$ terraform -version
Terraform v1.1.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/kubernetes v2.8.0
+ provider registry.terraform.io/hashicorp/vault v3.3.0
+ provider registry.terraform.io/ionos-cloud/ionoscloud v6.1.3

Configuration Files

main.tf

resource "ionoscloud_k8s_cluster" "fragment" {
  for_each = var.clusters
  name        = "${each.key}-cluster"
  k8s_version = each.value.k8s_version
  maintenance_window {
    day_of_the_week = each.value.maintenance_day
    time            = each.value.maintenance_time
  }
}

resource "ionoscloud_k8s_node_pool" "worker" {
  for_each = var.clusters
  name        = "worker-${each.key}"
  k8s_version = each.value.k8s_version
  auto_scaling {
    min_node_count = var.auto_scale_min_node_count
    max_node_count = var.auto_scale_max_node_count
  }
  maintenance_window {
    day_of_the_week = each.value.maintenance_day
    time            = each.value.maintenance_time
  }
  datacenter_id     = ionoscloud_datacenter.datacenter[each.value.datacenter].id
  k8s_cluster_id    = ionoscloud_k8s_cluster.fragment[each.key].id
  cpu_family        = element(ionoscloud_datacenter.datacenter[each.value.datacenter].cpu_architecture, 0).cpu_family
  availability_zone = "AUTO"
  storage_type      = "SSD"
  node_count        = each.value.node_count
  cores_count       = each.value.cores_count
  ram_size          = each.value.ram_size
  storage_size      = each.value.storage_size
  labels = {
    "node-role.kubernetes.io/worker" = ""
  }
}

terraform.tfvars

clusters = {
    berlin-1 = {
        datacenter = "berlin"
        maintenance_day = "Monday"
        maintenance_time = "09:30:00Z"
        k8s_version = "1.21.4"
        cores_count = 1
        ram_size = 2048
        storage_size = 40
        node_count = 3
        auto_scale_min_node_count = 1
        auto_scale_max_node_count = 5
    },
    frankfurt-1 = {
        datacenter = "frankfurt"
        maintenance_day = "Monday"
        maintenance_time = "09:30:00Z"
        k8s_version = "1.21.4"
        cores_count = 1
        ram_size = 2048
        storage_size = 40
        node_count = 3
        auto_scale_min_node_count = 1
        auto_scale_max_node_count = 5
    },
}

How to Reproduce

  1. Set instances of node_count in terraform.tfvars to 1
  2. terraform apply
  3. Watch as this is provisioned successfully
  4. Set instances of node_count in terraform.tfvars to 3
  5. terraform apply
  6. Crash

Error and Debug Output

[jgazeley@hephaestos cr-terraform]$ terraform apply
ionoscloud_k8s_cluster.fragment["berlin-1"]: Refreshing state... [id=903772ad-0e68-4785-bfeb-94720501588f]
ionoscloud_k8s_cluster.fragment["frankfurt-1"]: Refreshing state... [id=b380034e-d656-4b44-96a6-3f319f997944]
ionoscloud_datacenter.datacenter["berlin"]: Refreshing state... [id=47c13bd9-3781-499f-9583-f8d0a4976f61]
ionoscloud_datacenter.datacenter["frankfurt"]: Refreshing state... [id=1ee4b375-34d1-4fad-b0b4-af22368fbfc0]
ionoscloud_datacenter.datacenter["london"]: Refreshing state... [id=91f2d8a6-f25b-4a2b-9784-cf6a4dab6592]
ionoscloud_datacenter.datacenter["logrono"]: Refreshing state... [id=7a91bf18-062a-44b5-95c3-89fd848e60db]
ionoscloud_datacenter.datacenter["newark"]: Refreshing state... [id=cf68c9b1-b4c2-4e89-a008-8c2e9dc7167e]
ionoscloud_datacenter.datacenter["lasvegas"]: Refreshing state... [id=811d532f-3c87-4352-a97d-a85ca76d20d7]
ionoscloud_k8s_node_pool.infra["berlin-1"]: Refreshing state... [id=6939d3f3-7f45-44fb-a6f3-05a8d63f748c]
ionoscloud_k8s_node_pool.infra["frankfurt-1"]: Refreshing state... [id=f3ddcf3c-5200-4174-a305-fd1c83d04c83]
ionoscloud_k8s_node_pool.worker["frankfurt-1"]: Refreshing state... [id=ecd92ce3-d945-43b6-9f6f-9e8378ad08ff]
ionoscloud_k8s_node_pool.worker["berlin-1"]: Refreshing state... [id=3401c71b-e012-445f-b52f-09e71e79d1c6]

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:

  # ionoscloud_k8s_node_pool.worker["berlin-1"] will be updated in-place
  ~ resource "ionoscloud_k8s_node_pool" "worker" {
        id                = "3401c71b-e012-445f-b52f-09e71e79d1c6"
        name              = "worker-berlin-1"
      ~ node_count        = 1 -> 3
        # (11 unchanged attributes hidden)

        # (2 unchanged blocks hidden)
    }

  # ionoscloud_k8s_node_pool.worker["frankfurt-1"] will be updated in-place
  ~ resource "ionoscloud_k8s_node_pool" "worker" {
        id                = "ecd92ce3-d945-43b6-9f6f-9e8378ad08ff"
        name              = "worker-frankfurt-1"
      ~ node_count        = 1 -> 3
        # (11 unchanged attributes hidden)

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 2 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

ionoscloud_k8s_node_pool.worker["berlin-1"]: Modifying... [id=3401c71b-e012-445f-b52f-09e71e79d1c6]
ionoscloud_k8s_node_pool.worker["frankfurt-1"]: Modifying... [id=ecd92ce3-d945-43b6-9f6f-9e8378ad08ff]
╷
│ Error: Plugin did not respond
│ 
│   with ionoscloud_k8s_node_pool.worker["frankfurt-1"],
│   on main.tf line 38, in resource "ionoscloud_k8s_node_pool" "worker":
│   38: resource "ionoscloud_k8s_node_pool" "worker" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more
│ details.
╵
╷
│ Error: Plugin did not respond
│ 
│   with ionoscloud_k8s_node_pool.worker["berlin-1"],
│   on main.tf line 38, in resource "ionoscloud_k8s_node_pool" "worker":
│   38: resource "ionoscloud_k8s_node_pool" "worker" {
│ 
│ 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-ionoscloud_v6.1.3 plugin:

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

goroutine 57 [running]:
github.com/ionos-cloud/terraform-provider-ionoscloud/v6/ionoscloud.resourcek8sNodePoolUpdate({0x11263c8, 0xc0005ea9c0}, 0xc000236f00, {0xeef2e0, 0xc00046dbb0})
        github.com/ionos-cloud/terraform-provider-ionoscloud/v6/ionoscloud/resource_k8s_node_pool.go:622 +0xf79
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xc00012dce0, {0x1126358, 0xc00028d2c0}, 0x24, {0xeef2e0, 0xc00046dbb0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/resource.go:375 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00012dce0, {0x1126358, 0xc00028d2c0}, 0xc000262a90, 0xc000236c80, {0xeef2e0, 0xc00046dbb0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/resource.go:475 +0x6ba
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00011ca80, {0x1126358, 0xc00028d2c0}, 0xc000233860)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.1/helper/schema/grpc_provider.go:977 +0xd8a
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000152e80, {0x1126400, 0xc00020c660}, 0xc00015a540)
        github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/tf5server/server.go:603 +0x30e
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xf771a0, 0xc000152e80}, {0x1126400, 0xc00020c660}, 0xc0002c9860, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00013ea80, {0x1135050, 0xc0003e0600}, 0xc000176500, 0xc00045f230, 0x17e9340, 0x0)
        google.golang.org/grpc@v1.32.0/server.go:1194 +0xc8f
google.golang.org/grpc.(*Server).handleStream(0xc00013ea80, {0x1135050, 0xc0003e0600}, 0xc000176500, 0x0)
        google.golang.org/grpc@v1.32.0/server.go:1517 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.32.0/server.go:859 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.32.0/server.go:857 +0x294

Error: The terraform-provider-ionoscloud_v6.1.3 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.

Additional Notes

I am a Fasthosts employee and I'm using IONOS cloud to develop an internal project.

iblindu commented 2 years ago

Hi @djjudas21,

I've notices that you are using v6.1.3 of our provider. This issue has been solved in v6.1.4. I would recommend upgrading to the latest version - v6.1.6.

Thanks a lot!

djjudas21 commented 2 years ago

Thanks @IuliaBlindu. I thought I was running the latest because that's what the Terraform registry said, but I force-refreshed and I see v6.1.6 now. I'll try this.

djjudas21 commented 2 years ago

This works now. Thanks for your help.

iblindu commented 2 years ago

Glad it works! You're very welcome!