conradludgate/terraform-provider-spotify

Plugin crashes when terraform plan

Closed this issue · 9 comments

Just doing a simple example an when executing terraform plan it crashes with a segmentation violation. Terraform init was great tho.
Error log:
`╷
│ Error: Plugin did not respond

│ with data.spotify_track.overkill,
│ on main.tf line 30, in data "spotify_track" "overkill":
│ 30: data "spotify_track" "overkill" {

│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The plugin logs may
│ contain more details.

Stack trace from the terraform-provider-spotify_v0.1.6 plugin:

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

goroutine 45 [running]:
golang.org/x/oauth2.(*Token).Type(0x0, 0x0, 0xc000158900)
golang.org/x/oauth2@v0.0.0-20201208152858-08078c50e5b5/token.go:59 +0x26
golang.org/x/oauth2.(*Token).SetAuthHeader(0x0, 0xc000158800)
golang.org/x/oauth2@v0.0.0-20201208152858-08078c50e5b5/token.go:80 +0x32
main.(*transport).RoundTrip(0xc000152640, 0xc000158800, 0xc000152640, 0x0, 0x0)
github.com/conradludgate/terraform-provider-spotify/spotify.go:87 +0x5b
net/http.send(0xc000158800, 0x1d499c0, 0xc000152640, 0x0, 0x0, 0x0, 0xc00000e378, 0x203000, 0x1, 0x0)
net/http/client.go:251 +0x454
net/http.(*Client).send(0xc00057c120, 0xc000158800, 0x0, 0x0, 0x0, 0xc00000e378, 0x0, 0x1, 0xc000158800)
net/http/client.go:175 +0xff
net/http.(*Client).do(0xc00057c120, 0xc000158800, 0x0, 0x0, 0x0)
net/http/client.go:717 +0x45f
net/http.(*Client).Do(...)
net/http/client.go:585
net/http.(*Client).Get(0xc00057c120, 0xc00003a700, 0x38, 0xc00067d828, 0x100df38, 0x188)
net/http/client.go:474 +0xbe
github.com/zmb3/spotify.(*Client).get(0xc0000be0c0, 0xc00003a700, 0x38, 0x1a82d80, 0xc00047dd40, 0x0, 0x0)
github.com/zmb3/spotify@v0.0.0-20200525010707-bc712583571e/spotify.go:220 +0x6a
github.com/zmb3/spotify.(*Client).GetTrack(0xc0000be0c0, 0xc00003a6df, 0x16, 0x1, 0x0, 0x22f3901)
github.com/zmb3/spotify@v0.0.0-20200525010707-bc712583571e/track.go:93 +0xd2
main.dataSourceTrackRead(0xc00016b570, 0x1b8f9e0, 0xc0000be0c0, 0xc00016b570, 0x0)
github.com/conradludgate/terraform-provider-spotify/data_source_track.go:66 +0x1ae
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).ReadDataApply(0xc0004ffcb0, 0xc000540f00, 0x1b8f9e0, 0xc0000be0c0, 0xc0001194e0, 0x1, 0x0)
github.com/hashicorp/terraform-plugin-sdk@v1.15.0/helper/schema/resource.go:403 +0x91
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).ReadDataApply(0xc000154300, 0xc00067daf8, 0xc000540f00, 0xc000540f00, 0x0, 0x0)
github.com/hashicorp/terraform-plugin-sdk@v1.15.0/helper/schema/provider.go:451 +0x8f
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadDataSource(0xc0001445b0, 0x1d5b9f0, 0xc00066c5d0, 0xc000660880, 0xc0001445b0, 0xc00066c5d0, 0xc0006a1ba0)
github.com/hashicorp/terraform-plugin-sdk@v1.15.0/internal/helper/plugin/grpc_provider.go:1036 +0x42d
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadDataSource_Handler(0x1b59fa0, 0xc0001445b0, 0x1d5b9f0, 0xc00066c5d0, 0xc00007d2c0, 0x0, 0x1d5b9f0, 0xc00066c5d0, 0xc000044200, 0x75)
github.com/hashicorp/terraform-plugin-sdk@v1.15.0/internal/tfplugin5/tfplugin5.pb.go:3341 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000413a40, 0x1d64918, 0xc000130480, 0xc000158700, 0xc000116b40, 0x22b5f30, 0x0, 0x0, 0x0)
google.golang.org/grpc@v1.34.0/server.go:1210 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc000413a40, 0x1d64918, 0xc000130480, 0xc000158700, 0x0)
google.golang.org/grpc@v1.34.0/server.go:1533 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc00042c2f0, 0xc000413a40, 0x1d64918, 0xc000130480, 0xc000158700)
google.golang.org/grpc@v1.34.0/server.go:871 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/grpc@v1.34.0/server.go:869 +0x1fd

Error: The terraform-provider-spotify_v0.1.6 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.`

main.tf:
`terraform {
required_providers {
spotify = {
version = "~> 0.1.6"
source = "conradludgate/spotify"
}
}
}

provider "spotify" {
api_key = var.spotify_api_key
}

resource "spotify_playlist" "playlist" {
name = "playlist name"
description = "some description"
public = false

tracks = [
data.spotify_track.overkill.id
]
}

data "spotify_track" "overkill" {
url = "https://open.spotify.com/track/4XdaaDFE881SlIaz31pTAG"
}

variable "spotify_api_key" {
type = string
}

output "playlist_url" {
value = "https://open.spotify.com/playlist/${spotify_playlist.playlist.id}"
description = "Visit this URL in your browser to listen to the playlist"
}`

Running on a mac.
Versions:
Terraform v1.0.2
on darwin_amd64

  • provider registry.terraform.io/conradludgate/spotify v0.1.6

I've encountered same error.

hbokh commented

And another "me too" - same versions in use as mentioned above.

Weird thing is: it DID work the first time. I managed to create a new playlist, was able to destroy it and re-create, adapt and apply again, etc., etc.
When I was happy with the first results, I stopped the Docker container onradludgate/spotify-auth-proxy and stepped away for app. 1 hour. Then tried all the required steps again and ran into this issue.

See my repo for a reference: https://github.com/hbokh/spotify-playlist

hbokh commented

I found out what I was doing wrong: every time you start the container conradludgate/spotify-auth-proxy, a different APIKey is generated, that needs to be replaced in file terraform.tfvars too:

spotify_api_key = "..."

Editing this specific file manually, running terraform plan / terraform apply --auto-approve fixed my issue.
Wondering if this is possible to automate.

Hi, @hbokh I looked into what you see and although this is important and true, it's not the solution, but luckily I find out why this error happens! I turns out that when you run the docker, you have to access the http address that appears below the token because there you will have to approve that you give acces to you account(weird). Once done this step, terraform plan worked great.

Hi, @hbokh I looked into what you see and although this is important and true, it's not the solution, but luckily I find out why this error happens! I turns out that when you run the docker, you have to access the http address that appears below the token because there you will have to approve that you give acces to you account(weird). Once done this step, terraform plan worked great.

This worked @PauSabatesC Thank you!!

Sorry for the late response, apparently my notifications were disabled! I'll try and get all these errors better documented and with better errors

Fixed in #15. Running a release now. Thanks everyone

a different APIKey is generated, that needs to be replaced in file terraform.tfvars too:

Yeah good point. Currently it's random everytime you run. I should add an environment variable so that you can manually specify the auth key

I should add an environment variable so that you can manually specify the auth key

Added in v0.1.10 :)