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

Provider panics when providing a IONOS_API_URL #12

Closed maboehm closed 3 years ago

maboehm commented 3 years ago

Description

I had set the environment variable IONOS_API_URL=https://api.ionos.com/cloudapi/v5 in my terminal and the provider immediately panics during terraform plan

Expected behavior

Expected it not to panic.

Environment

Terraform version:

Terraform v0.15.4
on linux_amd64
+ provider registry.terraform.io/ionos-cloud/ionoscloud v5.1.3

Configuration Files

# main.tf
terraform {
  required_version = ">= 0.15.0"
  required_providers {
    ionoscloud = {
      source  = "ionos-cloud/ionoscloud"
      version = "5.1.3"
    }
  }
}

provider "ionoscloud" {
}

data "ionoscloud_datacenter" "example" {
  name = "my-dc"
}

Run commands:

export IONOS_API_URL=https://api.ionos.com/cloudapi/v5
export IONOS_USERNAME=<redacted>
export IONOS_PASSWORD=<redacted>
terraform init
terraform plan

Error and Debug Output

╷
│ Error: Plugin did not respond
│ 
│   with provider["registry.terraform.io/ionos-cloud/ionoscloud"],
│   on main.tf line 11, in provider "ionoscloud":
│   11: provider "ionoscloud" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ConfigureProvider call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-ionoscloud_v5.1.3 plugin:

panic: runtime error: index out of range [2] with length 2

goroutine 16 [running]:
github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud.providerConfigure(0xc000194a10, 0xc00089dae8, 0x6, 0x1, 0x1, 0xebfd78, 0x1508140)
        github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud/provider.go:137 +0x752
github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud.Provider.func1(0xc000194a10, 0x0, 0xc0006a1640, 0xc000194a10, 0x0)
        github.com/ionos-cloud/terraform-provider-ionoscloud/ionoscloud/provider.go:102 +0xd1
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Configure(0xc000310b80, 0xc00015de90, 0x137b820, 0xc00015de00)
        github.com/hashicorp/terraform-plugin-sdk@v1.16.1/helper/schema/provider.go:275 +0xf6
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).Configure(0xc000794c10, 0x18d0ea0, 0xc00015d140, 0xc000382080, 0xc000794c10, 0xc00015d140, 0xc000652ba0)
        github.com/hashicorp/terraform-plugin-sdk@v1.16.1/internal/helper/plugin/grpc_provider.go:487 +0x2e6
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_Configure_Handler(0x14f1c40, 0xc000794c10, 0x18d0ea0, 0xc00015d140, 0xc0008b1800, 0x0, 0x18d0ea0, 0xc00015d140, 0xc000040500, 0x3b)
        github.com/hashicorp/terraform-plugin-sdk@v1.16.1/internal/tfplugin5/tfplugin5.pb.go:3251 +0x217
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000453500, 0x18df9a0, 0xc000702c00, 0xc000314200, 0xc00060db60, 0x22c3358, 0x0, 0x0, 0x0)
        google.golang.org/grpc@v1.31.1/server.go:1180 +0x50a
google.golang.org/grpc.(*Server).handleStream(0xc000453500, 0x18df9a0, 0xc000702c00, 0xc000314200, 0x0)
        google.golang.org/grpc@v1.31.1/server.go:1503 +0xcfd
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000796190, 0xc000453500, 0x18df9a0, 0xc000702c00, 0xc000314200)
        google.golang.org/grpc@v1.31.1/server.go:843 +0xa1
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.31.1/server.go:841 +0x204

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

the fix is probably just changing the indices to 0 and 1 respectively, unless I did something wrong.

benschmi commented 3 years ago

@m2hofi94 , have you tried using the endpoint parameter inside the provider resource as described here?

Or why not leaving it out completely since it seems your are using the default endpoint?

larsen0815 commented 3 years ago

No difference using the parameter inside, see https://github.com/ionos-cloud/terraform-provider-ionoscloud/issues/5#issuecomment-856759889

maboehm commented 3 years ago

It's still a bug, regardless of whether or not I need to set it or not ;)

I have to set it at some point anyways thanks to annoying proxies on my way out, I just wanted to provide a simple example here

jbuchhammer commented 3 years ago

It's more seroius than it seems in the beginning: One customer is accessing IONOS via a partner which means that he has to use a rebranded URL to access the API. Thus it must be fixed asap.

mflorin commented 3 years ago

@jbuchhammer - working on it, will have the fix released later today.

mflorin commented 3 years ago

@m2hofi94 @jbuchhammer - I've just released v5.1.5 - let me know if it fixes the issue for you.

larsen0815 commented 3 years ago

5.1.5 fixes this issue.

Unfortunately, I now get another crash that I had experienced before, see https://github.com/ionos-cloud/terraform-provider-ionoscloud/issues/5 @m2hofi94 Can you reproduce the other crash?

mflorin commented 3 years ago

@larsen0815, I'll take a look