fluxcd/terraform-provider-flux

[Bug]: Terraform Flux Provider Plugin Segmentation Fault (SIGSEGV) - Nil Pointer Dereference

Opened this issue · 2 comments

Describe the bug

I am trying to bootstrap FluxCD on my Talos VM running on my home lab with Proxmox. When I run terraform plan, it takes a very long time before the plan stops due to a crash. proxmox_virtual_environment_vm.talos_cp_01: Refreshing state... [id=100] appears, and then something happens that seems like it’s complaining about memory based on my understanding of the error message. My server seems to have enough memory, and the same goes for the machine I’m running this from, where it uses a maximum of 4 GB out of 16 GB available on the machine.

Steps to reproduce

terraform plan on this code, in addition gitlab stores the state file
https://gitlab.com/sh-homelab/terraform-talos/

Expected behavior

I am running terraform plan, and the plan will be created so that I can run an application and then bootstrap Flux.

Screenshots and recordings

╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ValidateProviderConfig call. The plugin logs may
│ contain more details.
╵
Releasing state lock. This may take a few moments...

Stack trace from the terraform-provider-flux_v1.4.0 plugin:

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

Error: The terraform-provider-flux_v1.4.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.

Terraform and provider versions

Terraform v1.10.2
on linux_amd64

  • provider registry.terraform.io/bpg/proxmox v0.66.2
  • provider registry.terraform.io/fluxcd/flux v1.4.0
  • provider registry.terraform.io/gitlabhq/gitlab v17.5.0
  • provider registry.terraform.io/hashicorp/tls v4.0.6
  • provider registry.terraform.io/siderolabs/talos v0.7.0-alpha.0

Terraform provider configurations

terraform {
  backend "http" {}
  required_providers {
    proxmox = {
      source  = "bpg/proxmox"
      version = "0.66.2"
    }
    talos = {
      source  = "siderolabs/talos"
      version = "0.7.0-alpha.0"
    }
    flux = {
      source  = "fluxcd/flux"
      version = "1.4.0"
    }
    tls = {
      source  = "hashicorp/tls"
      version = "4.0.6"
    }
    gitlab = {
      source  = "gitlabhq/gitlab"
      version = "17.5.0"
    }
  }
}

provider "proxmox" {
  endpoint = var.api_url
  api_token = var.api_token
  insecure  = true
  ssh {
    agent = true
  }
}

provider "flux" {
  kubernetes = {
    config_path = talos_cluster_kubeconfig.cluster_kubeconfige.kubeconfig_raw
  }
  git = {
    url = var.flux_gitlab_url
    ssh = {
      username    = "git"
      private_key = tls_private_key.flux.private_key_pem
    }
  }
}

provider "gitlab" {
  token = var.gitlab_token
}

flux_bootstrap_git resource

resource "tls_private_key" "flux" {
  algorithm   = "ECDSA"
  ecdsa_curve = "P384"
}

resource "gitlab_deploy_key" "this" {
  project  = var.gitlab_flux_project
  title    = "Flux"
  key      = tls_private_key.flux.public_key_openssh
  can_push = true
}

resource "flux_bootstrap_git" "this" {
  path               = var.flux_gitlab_url
}

Flux version

v2.4.0

Additional context

The code runs locally from my laptop over a VPN (zerotier) connection to my server at home.

`Stack trace from the terraform-provider-flux_v1.4.0 plugin:

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

goroutine 69 [running]:
github.com/fluxcd/terraform-provider-flux/internal/provider.(*fluxProvider).ValidateConfig(0xc0006ff320?, {0x262dba8, 0xc0006ff320}, {{{{0x2638f70, 0xc00073c540}, {0x1eb17c0, 0xc00073b680}}, {0x263d868, 0xc000534c80}}}, 0xc0006db398)
	github.com/fluxcd/terraform-provider-flux/internal/provider/provider.go:330 +0x318
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ValidateProviderConfig(0xc00079e3c0, {0x262dba8, 0xc0006ff320}, 0xc0001502f8, 0xc00074b6e8)
	github.com/hashicorp/terraform-plugin-framework@v1.11.0/internal/fwserver/server_validateproviderconfig.go:74 +0x5fd
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ValidateProviderConfig(0xc00079e3c0, {0x262dba8?, 0xc0006ff230?}, 0xc0001502d8)
	github.com/hashicorp/terraform-plugin-framework@v1.11.0/internal/proto6server/server_validateproviderconfig.go:39 +0x1a5
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ValidateProviderConfig(0xc0007a0140, {0x262dba8?, 0xc00045c000?}, 0xc0006fe000)
	github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov6/tf6server/server.go:586 +0x27b
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ValidateProviderConfig_Handler({0x2148bc0, 0xc0007a0140}, {0x262dba8, 0xc00045c000}, 0xc000286300, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:392 +0x1a9
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001d9800, {0x262dba8, 0xc0006a3e00}, {0x263af80, 0xc00079a300}, 0xc0003c0c60, 0xc0007101b0, 0x38bfcf0, 0x0)
	google.golang.org/grpc@v1.65.0/server.go:1379 +0xdf8
google.golang.org/grpc.(*Server).handleStream(0xc0001d9800, {0x263af80, 0xc00079a300}, 0xc0003c0c60)
	google.golang.org/grpc@v1.65.0/server.go:1790 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/grpc@v1.65.0/server.go:1029 +0x7f
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 68
	google.golang.org/grpc@v1.65.0/server.go:1040 +0x125

Error: The terraform-provider-flux_v1.4.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.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Would you like to implement a fix?

None

As an alternative to this provider you could try Flux Operator. Terraform example here: https://github.com/controlplaneio-fluxcd/flux-operator/tree/main/config/terraform

Thank you very much, I can take a look at it.