mumoshu / terraform-provider-eksctl

Manage AWS EKS clusters using Terraform and eksctl
Apache License 2.0
234 stars 44 forks source link

invalid memory address or nil pointer dereference #43

Open devops-k8s-by opened 3 years ago

devops-k8s-by commented 3 years ago

I can't destroy infrastructure.

Got

Error: unhandled error: runtime error: invalid memory address or nil pointer dereference goroutine 22 [running]: runtime/debug.Stack(0xc00045f438, 0x1918280, 0x2fa7860) runtime/debug/stack.go:24 +0x9d github.com/mumoshu/terraform-provider-eksctl/pkg/resource/cluster.ResourceCluster.func5.1(0xc00045f8c0) github.com/mumoshu/terraform-provider-eksctl@/pkg/resource/cluster/resource.go:108 +0x57 panic(0x1918280, 0x2fa7860) runtime/panic.go:679 +0x1b2 github.com/mumoshu/terraform-provider-eksctl/pkg/resource/cluster.doWriteKubeconfig(0xc00045f7c0, 0x21503c0, 0xc00053a690, 0xc000034a4c, 0x4, 0xc000034a66, 0x9, 0x42d7a1, 0x1c74d70) github.com/mumoshu/terraform-provider-eksctl@/pkg/resource/cluster/cluster_create.go:113 +0xb74 github.com/mumoshu/terraform-provider-eksctl/pkg/resource/cluster.(Manager).readCluster(0xc000124de8, 0x21503c0, 0xc00053a690, 0xc000299860, 0xc000299860, 0x40c828) github.com/mumoshu/terraform-provider-eksctl@/pkg/resource/cluster/cluster_read.go:41 +0x449 github.com/mumoshu/terraform-provider-eksctl/pkg/resource/cluster.ResourceCluster.func5(0xc00053a690, 0x175dbc0, 0xc000122548, 0x0, 0x0) github.com/mumoshu/terraform-provider-eksctl@/pkg/resource/cluster/resource.go:112 +0xa1 github.com/hashicorp/terraform-plugin-sdk/helper/schema.(Resource).RefreshWithoutUpgrade(0xc00013a700, 0xc000152460, 0x175dbc0, 0xc000122548, 0xc00000e818, 0x0, 0x0) github.com/hashicorp/terraform-plugin-sdk@v1.0.0/helper/schema/resource.go:455 +0x119 github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(GRPCProviderServer).ReadResource(0xc0001222d8, 0x215d840, 0xc00024e1b0, 0xc0001521e0, 0xc0001222d8, 0xc00024e1b0, 0xc000817a80) github.com/hashicorp/terraform-plugin-sdk@v1.0.0/internal/helper/plugin/grpc_provider.go:525 +0x3d8 github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler(0x1b88680, 0xc0001222d8, 0x215d840, 0xc00024e1b0, 0xc00011a2a0, 0x0, 0x215d840, 0xc00024e1b0, 0xc000418500, 0x22a1) github.com/hashicorp/terraform-plugin-sdk@v1.0.0/internal/tfplugin5/tfplugin5.pb.go:3153 +0x217 google.golang.org/grpc.(Server).processUnaryRPC(0xc0005362c0, 0x2173de0, 0xc000155e00, 0xc000178500, 0xc0003f7d40, 0x2fb4ab0, 0x0, 0x0, 0x0) google.golang.org/grpc@v1.23.0/server.go:995 +0x460 google.golang.org/grpc.(Server).handleStream(0xc0005362c0, 0x2173de0, 0xc000155e00, 0xc000178500, 0x0) google.golang.org/grpc@v1.23.0/server.go:1275 +0xd97 google.golang.org/grpc.(Server).serveStreams.func1.1(0xc000124260, 0xc0005362c0, 0x2173de0, 0xc000155e00, 0xc000178500) google.golang.org/grpc@v1.23.0/server.go:710 +0xbb created by google.golang.org/grpc.(*Server).serveStreams.func1 google.golang.org/grpc@v1.23.0/server.go:708 +0xa1

I don't want install eksctl on server before it.

Code: main.tf

resource "eksctl_cluster" "primary" { depends_on = [null_resource.eksctl] name = "subs" region = "us-east-1" spec = <<EOS nodeGroups:

resource "null_resource" "eksctl" {

triggers = { build_number = "${timestamp()}" }

provisioner "local-exec" { command = "/usr/bin/wget https://eksctl84.s3.amazonaws.com/eksctl -O /tmp/eksctl && /bin/chmod +x /tmp/eksctl && PATH=$PATH:/tmp && echo $PATH" }

}

mumoshu commented 3 years ago

@beltelebot Seems like it's failing here:

https://github.com/mumoshu/terraform-provider-eksctl/blob/52d0d0f7c07a6d3399cb8115a76414590de298d7/pkg/resource/cluster/cluster_create.go#L113

And that should be due to that eksctl doesn't exist at the time of running that code. Are you sure Terraform does execute a local-exec provisioned before Terraform's internal "plan" step that should be run before actual "destroy" operation?

Perhaps we'd better add a native support for obtaining eksctl binary from S3 bucket or via https?

shridhar-at-droit commented 3 years ago

I am getting the same error Error: unhandled error: runtime error: invalid memory address or nil pointer dereference while creating cluster. In my case cluster is created but at the end terraform exited with the runtime error.

resource "eksctl_cluster" "primary" { name = "my-cluster" api_version = var.api_version version = var.k8s_version region= "us-east-1" tags = var.tags spec = <<-EOS availabilityZones: ["us-east-1a", "us-east-1b"] iam: withOIDC: true serviceAccounts: [] fargateProfiles:

Error: unhandled error: runtime error: invalid memory address or nil pointer dereference goroutine 150 [running]: runtime/debug.Stack(0xc0007711e0, 0x2516c60, 0x3babb80) runtime/debug/stack.go:24 +0x9d github.com/mumoshu/terraform-provider-eksctl/pkg/resource/cluster.ResourceCluster.func1.1(0xc0007716d0) github.com/mumoshu/terraform-provider-eksctl@/pkg/resource/cluster/resource.go:24 +0x57 panic(0x2516c60, 0x3babb80) runtime/panic.go:679 +0x1b2 github.com/mumoshu/terraform-provider-eksctl/pkg/resource/cluster.doWriteKubeconfig(0xc00017f578, 0x2d4f560, 0xc0003f1f80, 0xc00084a560, 0x15, 0xc0007591a6, 0x9, 0x0, 0x0) github.com/mumoshu/terraform-provider-eksctl@/pkg/resource/cluster/cluster_create.go:113 +0xb74 github.com/mumoshu/terraform-provider-eksctl/pkg/resource/cluster.(Manager).createCluster(0xc00013eea8, 0xc0003f1f80, 0x0, 0x2, 0x2873120) github.com/mumoshu/terraform-provider-eksctl@/pkg/resource/cluster/cluster_create.go:48 +0x548 github.com/mumoshu/terraform-provider-eksctl/pkg/resource/cluster.ResourceCluster.func1(0xc0003f1f80, 0x235c5c0, 0xc00000e140, 0x0, 0x0) github.com/mumoshu/terraform-provider-eksctl@/pkg/resource/cluster/resource.go:28 +0x95 github.com/hashicorp/terraform-plugin-sdk/helper/schema.(Resource).Apply(0xc0005e4880, 0xc000866640, 0xc000821800, 0x235c5c0, 0xc00000e140, 0xc0000b7601, 0xc000876240, 0xc0000b7740) github.com/hashicorp/terraform-plugin-sdk@v1.0.0/helper/schema/resource.go:305 +0x365 github.com/hashicorp/terraform-plugin-sdk/helper/schema.(Provider).Apply(0xc0005e4e00, 0xc00072d918, 0xc000866640, 0xc000821800, 0xc000870748, 0xc0005e0550, 0x24c17a0) github.com/hashicorp/terraform-plugin-sdk@v1.0.0/helper/schema/provider.go:289 +0x99 github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(GRPCProviderServer).ApplyResourceChange(0xc00000e188, 0x2d5c9e0, 0xc00085f950, 0xc000049440, 0xc00000e188, 0xc00085f950, 0xc00025ea80) github.com/hashicorp/terraform-plugin-sdk@v1.0.0/internal/helper/plugin/grpc_provider.go:885 +0x882 github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x27874a0, 0xc00000e188, 0x2d5c9e0, 0xc00085f950, 0xc0000493e0, 0x0, 0x2d5c9e0, 0xc00085f950, 0xc000718300, 0x6c2) github.com/hashicorp/terraform-plugin-sdk@v1.0.0/internal/tfplugin5/tfplugin5.pb.go:3189 +0x217 google.golang.org/grpc.(Server).processUnaryRPC(0xc00040c000, 0x2d73260, 0xc000540a80, 0xc000516000, 0xc00040fa40, 0x3bb8c60, 0x0, 0x0, 0x0) google.golang.org/grpc@v1.23.0/server.go:995 +0x460 google.golang.org/grpc.(Server).handleStream(0xc00040c000, 0x2d73260, 0xc000540a80, 0xc000516000, 0x0) google.golang.org/grpc@v1.23.0/server.go:1275 +0xd97 google.golang.org/grpc.(Server).serveStreams.func1.1(0xc0005d6250, 0xc00040c000, 0x2d73260, 0xc000540a80, 0xc000516000) google.golang.org/grpc@v1.23.0/server.go:710 +0xbb created by google.golang.org/grpc.(Server).serveStreams.func1 google.golang.org/grpc@v1.23.0/server.go:708 +0xa1

shridhar-at-droit commented 3 years ago

error is disappeared after adding eksctl_bin = "eksctl"

r351574nc3 commented 1 year ago

I am encountering this on version 0.16.2. I noticed the binary is downloaded to .shoal/bin/eksctl. Any idea why I would still encounter this?