rancher / terraform-provider-rancher2

Terraform Rancher2 provider
https://www.terraform.io/docs/providers/rancher2/
Mozilla Public License 2.0
253 stars 216 forks source link

BUG: rancher2_app_v2.rancher-monitoring terraform apply failed #995

Open sdryga opened 1 year ago

sdryga commented 1 year ago

Hi!

I tried to deploy "rancher-monitoring" using "racher2" terraform provided and got an error:

│ Error: Plugin did not respond
│ 
│   with rancher2_app_v2.rancher-monitoring,
│   on rancher-monitoring.tf line 1, in resource "rancher2_app_v2" "rancher-monitoring":
│    1: resource "rancher2_app_v2" "rancher-monitoring" {
│ 
│ 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-rancher2_v1.24.1 plugin:
panic: runtime error: invalid memory address or nil pointer dereference

Details you can find below.


Rancher version: 2.6.7 Managed k8s cluster version: v1.24.4+rke2r1 Terraform version: 1.2.8 Rancher2 terraform provider version: v1.24.1

Terraform provider:

terraform {
  required_providers {
    rancher2 = {
      source = "rancher/rancher2"
      version = "1.24.1"
    }
  }
  backend "s3" {
    ...
  }
}

provider "rancher2" {
  api_url = "https://rancher.mydomain.com"
  insecure = true
  token_key = "admin-user-token"
}

Terraform resource:

resource "rancher2_app_v2" "rancher-monitoring" {
  cluster_id = "c-m-q4snf84z"
  name = "rancher-monitoring"
  namespace = "cattle-monitoring-system"
  repo_name = "rancher-charts"
  chart_name = "rancher-monitoring"
  chart_version = "100.1.2+up19.0.3"
  project_id = "p-f5cgk"
  values = file("values/rancher-monitoring.yaml")
}

Terraform plan:

$ terraform plan -lock=true -lock-timeout=5m -parallelism=10
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
Terraform will perform the following actions:
  # rancher2_app_v2.rancher-monitoring will be created
  + resource "rancher2_app_v2" "rancher-monitoring" {
      + annotations                 = (known after apply)
      + chart_name                  = "rancher-monitoring"
      + chart_version               = "100.1.2+up19.0.3"
      + cleanup_on_fail             = false
      + cluster_id                  = "c-m-q4snf84z"
      + cluster_name                = (known after apply)
      + disable_hooks               = false
      + disable_open_api_validation = false
      + force_upgrade               = false
      + id                          = (known after apply)
      + labels                      = (known after apply)
      + name                        = "rancher-monitoring"
      + namespace                   = "cattle-monitoring-system"
      + project_id                  = "p-f5cgk"
      + repo_name                   = "rancher-charts"
      + system_default_registry     = (known after apply)
      + values                      = <<-EOT
            prometheus:
              prometheusSpec:
                evaluationInterval: 30s
                resources:
                  limits:
                    cpu: "3"
                    memory: 16Gi
                  requests:
                    cpu: "1"
                    memory: 8Gi
                retentionSize: 99GiB
                scrapeInterval: 30s
                storageSpec:
                  volumeClaimTemplate:
                    spec:
                      accessModes:
                      - ReadWriteOnce
                      resources:
                        requests:
                          storage: 100Gi
                      storageClassName: longhorn
                      volumeMode: Filesystem
            grafana:
              persistence:
                accessModes:
                - ReadWriteOnce
                annotations: null
                enabled: true
                finalizers: null
                size: 5Gi
                storageClassName: longhorn
                subPath: null
                type: pvc
            rke2ControllerManager:
              enabled: true
            rke2Etcd:
              enabled: true
            rke2Proxy:
              enabled: true
            rke2Scheduler:
              enabled: true
        EOT
      + wait                        = true
    }
Plan: 1 to add, 0 to change, 0 to destroy.

Terraform apply:

$ terraform apply -auto-approve -lock=true -lock-timeout=5m -parallelism=10
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
Terraform will perform the following actions:
  # rancher2_app_v2.rancher-monitoring will be created
  + resource "rancher2_app_v2" "rancher-monitoring" {
      + annotations                 = (known after apply)
      + chart_name                  = "rancher-monitoring"
      + chart_version               = "100.1.2+up19.0.3"
      + cleanup_on_fail             = false
      + cluster_id                  = "c-m-q4snf84z"
      + cluster_name                = (known after apply)
      + disable_hooks               = false
      + disable_open_api_validation = false
      + force_upgrade               = false
      + id                          = (known after apply)
      + labels                      = (known after apply)
      + name                        = "rancher-monitoring"
      + namespace                   = "cattle-monitoring-system"
      + project_id                  = "p-f5cgk"
      + repo_name                   = "rancher-charts"
      + system_default_registry     = (known after apply)
      + values                      = <<-EOT
            prometheus:
              prometheusSpec:
                evaluationInterval: 30s
                resources:
                  limits:
                    cpu: "3"
                    memory: 16Gi
                  requests:
                    cpu: "1"
                    memory: 8Gi
                retentionSize: 99GiB
                scrapeInterval: 30s
                storageSpec:
                  volumeClaimTemplate:
                    spec:
                      accessModes:
                      - ReadWriteOnce
                      resources:
                        requests:
                          storage: 100Gi
                      storageClassName: longhorn
                      volumeMode: Filesystem
            grafana:
              persistence:
                accessModes:
                - ReadWriteOnce
                annotations: null
                enabled: true
                finalizers: null
                size: 5Gi
                storageClassName: longhorn
                subPath: null
                type: pvc
            rke2ControllerManager:
              enabled: true
            rke2Etcd:
              enabled: true
            rke2Proxy:
              enabled: true
            rke2Scheduler:
              enabled: true
        EOT
      + wait                        = true
    }
Plan: 1 to add, 0 to change, 0 to destroy.
rancher2_app_v2.rancher-monitoring: Creating...
╷
│ Error: Plugin did not respond
│ 
│   with rancher2_app_v2.rancher-monitoring,
│   on rancher-monitoring.tf line 1, in resource "rancher2_app_v2" "rancher-monitoring":
│    1: resource "rancher2_app_v2" "rancher-monitoring" {
│ 
│ 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-rancher2_v1.24.1 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xd07c36]
goroutine 56 [running]:
github.com/rancher/norman/clientbase.(*APIOperations).DoByID(0x0, {0x1ff6ac1, 0x7}, {0x1ffcf9d, 0xb}, {0x1bd2640, 0xc000974000})
    /go/pkg/mod/github.com/rancher/norman@v0.0.0-20220627222520-b74009fac3ff/clientbase/ops.go:251 +0x96
github.com/rancher/rancher/pkg/client/generated/management/v3.(*SettingClient).ByID(0xc000307100, {0x1ffcf9d, 0xb})
    /go/pkg/mod/github.com/rancher/rancher/pkg/client@v0.0.0-20220722085125-e464ea405677/generated/management/v3/zz_generated_setting.go:120 +0x67
github.com/rancher/terraform-provider-rancher2/rancher2.(*Config).getK8SDefaultVersion(0xc0001b4240)
    /go/src/github.com/rancher/terraform-provider-rancher2/rancher2/config.go:135 +0x148
github.com/rancher/terraform-provider-rancher2/rancher2.(*Config).ManagementClient(0xc0001b4240)
    /go/src/github.com/rancher/terraform-provider-rancher2/rancher2/config.go:285 +0x1df
github.com/rancher/terraform-provider-rancher2/rancher2.(*Config).GetClusterByID(0xc0000e8050, {0xc001[63](http://gitlab.dc/mw-deploy/mw-dev-terraform/-/jobs/642776#L63)4900, 0xc0016536f0})
    /go/src/github.com/rancher/terraform-provider-rancher2/rancher2/config.go:720 +0x34
github.com/rancher/terraform-provider-rancher2/rancher2.(*Config).checkClusterCondition(0x2045bea, {0xc001634900, 0xc0016537e0}, {0x1ff5b5c, 0x7})
    /go/src/github.com/rancher/terraform-provider-rancher2/rancher2/config.go:887 +0x36
github.com/rancher/terraform-provider-rancher2/rancher2.(*Config).isClusterActive(...)
    /go/src/github.com/rancher/terraform-provider-rancher2/rancher2/config.go:905
github.com/rancher/terraform-provider-rancher2/rancher2.resourceRancher2AppV2Create(0xc001662810, {0x1fec1e0, 0xc0001b4240})
    /go/src/github.com/rancher/terraform-provider-rancher2/rancher2/resource_rancher2_app_v2.go:43 +0x252
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc000766990, 0xc001638b40, 0xc001[64](http://gitlab.dc/mw-deploy/mw-dev-terraform/-/jobs/642776#L64)0960, {0x1fec1e0, 0xc0001b4240})
    /go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.14.0/helper/schema/resource.go:310 +0x438
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0xc00021e600, 0xc001[65](http://gitlab.dc/mw-deploy/mw-dev-terraform/-/jobs/642776#L65)3a40, 0x2004037, 0xf)
    /go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.14.0/helper/schema/provider.go:294 +0x70
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc0002c43e0, {0xc001654690, 0x4b98c6}, 0xc001654690)
    /go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.14.0/internal/helper/plugin/grpc_provider.go:885 +0x7c5
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1f2d3a0, 0xc0002c43e0}, {0x2429c30, 0xc001[66](http://gitlab.dc/mw-deploy/mw-dev-terraform/-/jobs/642776#L66)2000}, 0xc001654620, 0x0)
    /go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.14.0/internal/tfplugin5/tfplugin5.pb.go:3305 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00070ec40, {0x245ed90, 0xc000d8a340}, 0xc000a28a20, 0xc000f777d0, 0x35a7a00, 0x0)
    /go/pkg/mod/google.golang.org/grpc@v1.48.0/server.go:1295 +0xb03
google.golang.org/grpc.(*Server).handleStream(0xc000[70](http://gitlab.dc/mw-deploy/mw-dev-terraform/-/jobs/642776#L70)ec40, {0x245ed90, 0xc000d8a340}, 0xc000a28a20, 0x0)
    /go/pkg/mod/google.golang.org/grpc@v1.48.0/server.go:1636 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    /go/pkg/mod/google.golang.org/grpc@v1.48.0/server.go:932 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
    /go/pkg/mod/google.golang.org/grpc@v1.48.0/server.go:930 +0x294
Error: The terraform-provider-rancher2_v1.24.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.
sdryga commented 1 year ago

Hi! Please comment on this issie, problem is still active. Thanks!