Giter Club home page Giter Club logo

terraform-provider-spotify's Introduction

terraform-provider-spotify

docs downloads latest version code coverage

This is a terraform provider for managing your spotify playlists.

Featured tutorial - https://learn.hashicorp.com/tutorials/terraform/spotify-playlist

Featured interview - https://www.hashicorp.com/blog/build-your-summer-spotify-playlist-with-terraform

I am not affiliated with Hashicorp or Terraform.

If you are having trouble with the provider, try updating to the latest version before submitting a bug report

Example

resource "spotify_playlist" "playlist" {
  name        = "My playlist"
  description = "My playlist is so awesome"
  public      = false

  tracks = flatten([
    data.spotify_track.overkill.id,
    data.spotify_track.blackwater.id,
    data.spotify_track.overkill.id,
    data.spotify_search_track.search.tracks[*].id,
  ])
}

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

data "spotify_search_track" "search" {
  name   = "Somebody Told Me"
  artist = "The Killers"
  album  = "Hot Fuss"
}

output "test" {
  value = data.spotify_search_track.search.tracks
}

Installation

Add the following to your terraform configuration

terraform {
  required_providers {
    spotify = {
      source  = "conradludgate/spotify"
      version = "~> 0.2.0"
    }
  }
}

How to use

First, you need an instance of a spotify oauth2 server running. This acts as a middleware between terraform and spotify to allow easy access to access tokens.

Public proxy

For a simple way to manage your spotify oauth2 tokens is to use https://oauth2.conrad.cafe. (source code)

Register a new account, create a spotify token with the following scopes

  • user-read-email
  • user-read-private
  • playlist-read-private
  • playlist-modify-private
  • playlist-modify-public
  • user-library-read
  • user-library-modify

Then take note of the token id in the URL and the API key that is shown on the page

Configure the terraform provider like so

provider "spotify" {
  auth_server = "https://oauth2.conrad.cafe"
  api_key     = var.spotify_api_key
  username    = "your username"
  token_id    = "your token id"
}

variable "spotify_api_key" {
  type = string
}

Self hosted

If you want a bit more control over your tokens, you can self host a simple instance of the oauth2 proxy designed specifically for this terraform provider

See spotify_auth_proxy to get started.

Once you have the server running, make note of the API Key it gives you.

Configure the terraform provider like so

variable "spotify_api_key" {
  type = string
}

provider "spotify" {
  api_key = var.spotify_api_key
}

terraform-provider-spotify's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-provider-spotify's Issues

Panic when using `spotify_search_track`

When using the spotify_search_track data source, it panics.

What I did

I used sample code to create a playlist and add some tracks. This worked correctly the first time and on subsequent times when making small changes.

Then I added these lines to search for a track.

data "spotify_search_track" "beatles_search" {
  name = "Here comes the sun"
}

What happened

When I added three lines to use spotify_search_track, it threw a panic.

Error: rpc error: code = Unavailable desc = transport is closing

panic: runtime error: invalid memory address or nil pointer dereference
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1b061c6]
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: 
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: goroutine 25 [running]:
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: main.dataSourceSearchTrackRead(0xc0000f8620, 0x1d73960, 0xc000364820, 0xc0000f8620, 0x0)
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: 	github.com/conradludgate/terraform-provider-spotify/data_source_search_track.go:167 +0xa86
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).ReadDataApply(0xc0003683f0, 0xc000365d80, 0x1d73960, 0xc000364820, 0xc00037f5a8, 0x1, 0x0)
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: 	github.com/hashicorp/[email protected]/helper/schema/resource.go:403 +0x88
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).ReadDataApply(0xc000044500, 0xc00014daf8, 0xc000365d80, 0xc000365d80, 0x0, 0x0)
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: 	github.com/hashicorp/[email protected]/helper/schema/provider.go:451 +0x8f
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadDataSource(0xc00000ef20, 0x1f4fd00, 0xc00010f7a0, 0xc0008509c0, 0xc00000ef20, 0xc00010f7a0, 0xc0004f1ba0)
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: 	github.com/hashicorp/[email protected]/internal/helper/plugin/grpc_provider.go:1036 +0x42d
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadDataSource_Handler(0x1d37220, 0xc00000ef20, 0x1f4fd00, 0xc00010f7a0, 0xc00008b7a0, 0x0, 0x1f4fd00, 0xc00010f7a0, 0xc0004ba230, 0x63)
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: 	github.com/hashicorp/[email protected]/internal/tfplugin5/tfplugin5.pb.go:3341 +0x214
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: google.golang.org/grpc.(*Server).processUnaryRPC(0xc00037d340, 0x1f5ad80, 0xc000642f00, 0xc0000da400, 0xc0004f5140, 0x25adcb0, 0x0, 0x0, 0x0)
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: 	google.golang.org/[email protected]/server.go:1210 +0x522
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: google.golang.org/grpc.(*Server).handleStream(0xc00037d340, 0x1f5ad80, 0xc000642f00, 0xc0000da400, 0x0)
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: 	google.golang.org/[email protected]/server.go:1533 +0xd05
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc0003b01d0, 0xc00037d340, 0x1f5ad80, 0xc000642f00, 0xc0000da400)
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: 	google.golang.org/[email protected]/server.go:871 +0xa5
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: created by google.golang.org/grpc.(*Server).serveStreams.func1
2021-05-14T11:28:02.214-0700 [DEBUG] plugin.terraform-provider-spotify_v0.1.4: 	google.golang.org/[email protected]/server.go:869 +0x1fd
2021/05/14 11:28:02 [TRACE] vertex "spotify_playlist.playlist": visit complete
2021/05/14 11:28:02 [TRACE] vertex "spotify_playlist.playlist": dynamic subgraph encountered errors
2021/05/14 11:28:02 [TRACE] vertex "spotify_playlist.playlist": visit complete
2021/05/14 11:28:02 [TRACE] vertex "data.spotify_search_track.my_search": visit complete
2021/05/14 11:28:02 [TRACE] vertex "spotify_playlist.playlist (expand)": dynamic subgraph encountered errors
2021/05/14 11:28:02 [TRACE] vertex "spotify_playlist.playlist (expand)": visit complete
2021-05-14T11:28:02.217-0700 [WARN]  plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2021/05/14 11:28:02 [TRACE] vertex "data.spotify_search_track.my_search": dynamic subgraph encountered errors
2021/05/14 11:28:02 [TRACE] vertex "data.spotify_search_track.my_search": visit complete
2021/05/14 11:28:02 [TRACE] vertex "data.spotify_search_track.my_search (expand)": dynamic subgraph encountered errors
2021/05/14 11:28:02 [TRACE] vertex "data.spotify_search_track.my_search (expand)": visit complete
2021/05/14 11:28:02 [TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
2021/05/14 11:28:02 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/conradludgate/spotify\"] (close)" errored, so skipping
2021/05/14 11:28:02 [TRACE] dag/walk: upstream of "root" errored, so skipping
2021-05-14T11:28:02.217-0700 [DEBUG] plugin: plugin process exited: path=.terraform/providers/registry.terraform.io/conradludgate/spotify/0.1.4/darwin_amd64/terraform-provider-spotify_v0.1.4 pid=57876 error="exit status 2"
2021/05/14 11:28:02 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
2021/05/14 11:28:02 [TRACE] statemgr.Filesystem: unlocking terraform.tfstate using fcntl flock
2021-05-14T11:28:02.217-0700 [DEBUG] plugin: plugin exited

What I expected to happen

I expected to receive a list of tracks or a single track that could be used in a playlist.

Full example

terraform {
  required_providers {
    spotify = {
      version = "~> 0.1.4"
      source  = "conradludgate/spotify"
    }
  }
}

variable "spotify_api_key" {
  type = string
}

provider "spotify" {
  api_key = var.spotify_api_key
}

resource "spotify_playlist" "playlist" {
  name        = "My Terraform playlist Friday"
  description = "My Terraform playlist is so awesome"
  public      = false

  tracks = [
    data.spotify_track.overkill.id,
    data.spotify_track.blackwater.id,
    data.spotify_track.overkill.id,
    data.spotify_track.digital-love.id,
  ]
}

data "spotify_search_track" "beatles_search" {
  name = "Here comes the sun"
}

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

data "spotify_track" "blackwater" {
  spotify_id = "4lE6N1E0L8CssgKEUCgdbA"
}

data "spotify_track" "digital-love" {
  url = "https://open.spotify.com/track/2VEZx7NWsZ1D0eJ4uv5Fym?si=62441a1b053c4f66"
}

artists are note accepted as argument as doc shows.

│ Error: Unsupported argument

│ on main.tf line 19, in data "spotify_search_track" "by_artist":
│ 19: artists = ["Koop","Living Light","Wildlight","Ayla Nereo"]

│ An argument named "artists" is not expected here. Did you mean "artist"?

Plugin crashes when terraform plan

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/[email protected]/token.go:59 +0x26
golang.org/x/oauth2.(*Token).SetAuthHeader(0x0, 0xc000158800)
golang.org/x/[email protected]/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/[email protected]/spotify.go:220 +0x6a
github.com/zmb3/spotify.(*Client).GetTrack(0xc0000be0c0, 0xc00003a6df, 0x16, 0x1, 0x0, 0x22f3901)
github.com/zmb3/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/server.go:1210 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc000413a40, 0x1d64918, 0xc000130480, 0xc000158700, 0x0)
google.golang.org/[email protected]/server.go:1533 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc00042c2f0, 0xc000413a40, 0x1d64918, 0xc000130480, 0xc000158700)
google.golang.org/[email protected]/server.go:871 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/[email protected]/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"
}`

unable to create private playlist

I am trying to create a private playlist without success. This is on the playlist creation:

➜ tf apply -target=spotify_playlist.test_private

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:

  # spotify_playlist.test_private will be created
  + resource "spotify_playlist" "test_private" {
      + id          = (known after apply)
      + name        = "test if playlist can be private"
      + public      = false
      + snapshot_id = (known after apply)
      + tracks      = [
          + "4VWfod1Vw2b8VVruLKrUzx,
        ]
    }

Plan: 1 to add, 0 to change, 0 to destroy.

The next times that I run terraform apply I get the following:

Terraform will perform the following actions:

  # spotify_playlist.test_private will be updated in-place
  ~ resource "spotify_playlist" "test_private" {
        id          = "*******"
        name        = "test if playlist can be private"
      ~ public      = true -> false
        # (2 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

I confirm that the playlist is public in Spotify, no matter how many times I executed the apply. I took a look also at the tfstate file, which shows that the public param is properly set to false:

    {
      "mode": "managed",
      "type": "spotify_playlist",
      "name": "test_private",
      "provider": "provider[\"registry.terraform.io/conradludgate/spotify\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "description": "",
            "id": "*******",
            "name": "test if playlist can be private",
            "public": false,
            "snapshot_id": "*****",
            "tracks": [
              "4VWfod1Vw2b8VVruLKrUzx"
            ]
          },
          "sensitive_attributes": [],
          "private": "******"
        }
      ]
    }

According to the Spotify API docs, we need the playlist-modify-private authorization scope, which is properly set in spotify-auth-proxy so I'm clueless why it doesn't work.

Issue with superfluous response.WriteHeader

I previously had the terraform provider setup fine, after recently migrating my state from s3 back to local (which worked fine)

I now find myself unable to authenticate properly:

docker run --rm -it -p 27228:27228 --env-file ./.env ghcr.io/conradludgate/spotify-auth-proxy
APIKey:   xxxxxxxxxxxxxxxxxxxxxxxx
Auth URL: http://localhost:27228/authorize?token=xxxxxxxxxxxx
2023/11/18 03:25:05 http: superfluous response.WriteHeader call from main.SpotifyCallback (main.go:175)
2023/11/18 03:25:26 http: superfluous response.WriteHeader call from main.SpotifyCallback (main.go:175)
2023/11/18 03:26:12 http: superfluous response.WriteHeader call from main.SpotifyCallback (main.go:175)

Never had this issue previously, I have set my client_id and client_secret (recreated the app via spotify dashboard) - Recreating the app at least let me hit the "do you want to allow x app to modify spotify on your behalf" - but after clicking yes, I am hit with:

Could not complete authorization: invalid auth code

Any help would be greatly appreciated, cheers!

Feature Request: Preserve Playlist Ordering

Currently, the tracks argument is a set of tracks that comprise a Spotify playlist. Modifying this list appropriately triggers song to be added and removed from the playlist; however, the relative ordering of songs is not preserved.

Since playlists are ordered, and the order may be useful (e.g. the ending of one song immediately flowing into the prelude of another) it would be nice if the playlist resource preserved the ordering of songs to match the order of tracks

For example:

The playlist denoted here lists the track "Induction" by Terraform as the first song, immediately followed by Hanz Zimmer's "Terraforming"; however, the resulting playlist has "FXMLDR" by Thank You Scientist as the first song.

I believe songs are being added to the bottom of the playlist on each application if they're new, and correctly being removed in-place.

feat: Expose Auth URL inside docker container

Feature

Add Auth URL as an environment variable inside the container

Detailed Description

For the ability to run this in Github Actions I would need to be able to curl the Auth URL from inside the docker container. It would be nice if the were set an environment variable or some other way to get this URL in order to be able to curl it. As of right now I only see this URL being generated and display on the container stdout or in the container logs. I do not see a way to retrieve this from inside the container.

Expectation

I can run docker exec -ti <container name or ID> sh and then be able to retrive the Auth URL to run a curl from inside the container to get a bearer token, to be able to run the Terraform from inside this container.

Reason For Feature

In Github Actions if I run the container as a job, the workspace will disappear on job completion and therefore the functionality of this docker image will go away and not be available downstream when running other jobs such as Terraform plan/apply.

Error: The terraform-provider-spotify_v0.1.6 plugin crashed!

Hello

I have tried spotify terraform provider but it gives below error. I have also refered to #11 issue and after running docker I opened the auth url and authorized it. But still it gives me the below error.

`╷
│ Error: Plugin did not respond

│ with data.spotify_search_track.by_artist,
│ on main.tf line 34, in data "spotify_search_track" "by_artist":
│ 34: data "spotify_search_track" "by_artist" {

│ 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=0xa908c6]

goroutine 42 [running]:
golang.org/x/oauth2.(*Token).Type(0x0, 0x0, 0xc00016c200)
golang.org/x/[email protected]/token.go:59 +0x26
golang.org/x/oauth2.(*Token).SetAuthHeader(0x0, 0xc00016c100)
golang.org/x/[email protected]/token.go:80 +0x32
main.(*transport).RoundTrip(0xc00029fb40, 0xc00016c100, 0xc00029fb40, 0x0, 0x0)
github.com/conradludgate/terraform-provider-spotify/spotify.go:87 +0x5b
net/http.send(0xc00016c100, 0x1149dc0, 0xc00029fb40, 0x0, 0x0, 0x0, 0xc00000e278, 0x0, 0x1, 0x0)
net/http/client.go:251 +0x454
net/http.(*Client).send(0xc000116810, 0xc00016c100, 0x0, 0x0, 0x0, 0xc00000e278, 0x0, 0x1, 0xc000032800)
net/http/client.go:175 +0xff
net/http.(*Client).do(0xc000116810, 0xc00016c100, 0x0, 0x0, 0x0)
net/http/client.go:717 +0x45f
net/http.(*Client).Do(...)
net/http/client.go:585
net/http.(*Client).Get(0xc000116810, 0xc0000420f0, 0x4e, 0xc0000ad380, 0x40e0f8, 0x20)
net/http/client.go:474 +0xbe
github.com/zmb3/spotify.(*Client).get(0xc0003a4040, 0xc0000420f0, 0x4e, 0xe04fe0, 0xc0005ac520, 0x0, 0x0)
github.com/zmb3/[email protected]/spotify.go:220 +0x6a
github.com/zmb3/spotify.(*Client).SearchOpt(0xc0003a4040, 0xc0001822b0, 0x10, 0x8, 0xc0000ad778, 0xc0001822b0, 0x10, 0xc0006bcc50)
github.com/zmb3/[email protected]/search.go:138 +0x305
main.dataSourceSearchTrackRead(0xc000726e00, 0xf90740, 0xc0003a4040, 0xc000726e00, 0x0)
github.com/conradludgate/terraform-provider-spotify/data_source_search_track.go:143 +0x4a6
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).ReadDataApply(0xc000118360, 0xc0005ac260, 0xf90740, 0xc0003a4040, 0xc0004efb58, 0x1, 0x0)
github.com/hashicorp/[email protected]/helper/schema/resource.go:403 +0x91
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).ReadDataApply(0xc0001d6480, 0xc0000adaf8, 0xc0005ac260, 0xc0005ac260, 0x0, 0x0)
github.com/hashicorp/[email protected]/helper/schema/provider.go:451 +0x8f
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadDataSource(0xc000728588, 0x115bcb0, 0xc000712ea0, 0xc00018d9c0, 0xc000728588, 0xc000712ea0, 0xc0002dfba0)
github.com/hashicorp/[email protected]/internal/helper/plugin/grpc_provider.go:1036 +0x42d
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadDataSource_Handler(0xf5a6a0, 0xc000728588, 0x115bcb0, 0xc000712ea0, 0xc000188540, 0x0, 0x115bcb0, 0xc000712ea0, 0xc0006c61e0, 0x59)
github.com/hashicorp/[email protected]/internal/tfplugin5/tfplugin5.pb.go:3341 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00035fa40, 0x1164a18, 0xc000001680, 0xc00016c000, 0xc000096960, 0x16b1d70, 0x0, 0x0, 0x0)
google.golang.org/[email protected]/server.go:1210 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc00035fa40, 0x1164a18, 0xc000001680, 0xc00016c000, 0x0)
google.golang.org/[email protected]/server.go:1533 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000034320, 0xc00035fa40, 0x1164a18, 0xc000001680, 0xc00016c000)
google.golang.org/[email protected]/server.go:871 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/[email protected]/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.
`

getting duplicate songs from different albums - different id's

I'm new to Terraform and have been playing with this configuration. It might be a quick fix, but is there a way to not allow songs with the same name to be added to the playlist? It is happening because they have different ID's

for example,
bootsy

Just wondering if there's a way to prevent this.

PEBKAC: Working with my playlist from another computer does not pull playlist state

So I was on my work laptop and wanted to add a song to the playlist. But after terraform init. All the songs were in the terraform.tfstate but the playlist wasn't. terraform plan showed that it would create a new playlist. terraform apply` created a second playlist with a new ID and the same name

Steps to reproduce:

  • Clone your playlist repo to another computer. (different folder would probably work as well since the state is local)
  • Get local authenticator working with the docker image
  • terraform init
  • terraform plan

End result:

  • plan output shows a whole new playlist to add

Expected result:

  • no changes

Support for resource import?

Are there plans to support state import for playlists? I was thinking of managing all of my Spotify playlists with this and it would be nice to import the playlists I've already made.

I've started looking at forking and trying this implementation myself, but wanted to see if there is already a roadmap for this.

data source missing in tracks

resource "spotify_playlist" "ariana_grande" {
name = "My Ariana Grande Playlist"

tracks = flatten([
spotify_search_track.ariana_grande.tracks[*].id,
])
}

data "spotify_search_track" "ariana_grande" {
artist = "Ariana Grande"
limit = 10
}

from the above given example, in the "tracks " nested schema, the tracks list should be prefixed with "data."

So the tracks nested schema be as follows,
tracks = flatten([
**data.**spotify_search_track.ariana_grande.tracks[*].id,
])

Hosted instance of spotify auth proxy

I intend to make a hosted instance of the spotify auth proxy server so that it's as straight forward as possible to get started with this provider.

How I imagine it to work:

  1. User signs up to proxy service (using spotify account)
  2. Server creates the token, gets the user's spotify ID and saves it with the hash of a new API key
  3. User is given the ID and API Key as well as a dashboard for how many times their API Key has been used (with failure attempts too)
  4. From the dashboard, the user can revoke the API Key to get a new one

Error: could not perform search while executing terraform plan

Hey guys I am getting the following error while executing terraform plan

Error: could not perform search [[artist:"Dolly Parton"]]: Get "https://api.spotify.com/v1/search?limit=10&q=artist%3A%22Dolly+Parton%22&type=track": 404 page not found

What could be the reason for this error?

Here is my main.tf file :

terraform {
  required_providers {
    spotify = {
      version = "~> 0.1.5"
      source  = "conradludgate/spotify"
    }
  }
}


provider "spotify" {
  api_key = var.spotify_api_key
}

resource "spotify_playlist" "playlist" {
  name        = "Terraform"
  description = "This playlist was created by Terraform"
  public      = true

  tracks = [
    data.spotify_search_track.by_artist.tracks[0].id,
  ]
}

data "spotify_search_track" "by_artist" {
  artists = ["Dolly Parton"]
  #  album = "Jolene"
  #  name  = "Early Morning Breeze"
}

How to use the provider?

Hi,

I can see that you have a section abotu the installation and I vaguely remember tweaking some things for a provider back in TF v0.11 where I installed the provider locally or cached it somehow. But I can't find any info on this stuff nowadays and don't know how to use this provider. I tried the example in plain and got a

Error while installing hashicorp/spotify: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/spotify

Then I tried adding:

terraform {
  required_providers {
    spotify = {
      source  = "github.com/conradludgate/spotify"
    }
  }
}

Which lead to a:

The given source address "github.com/conradludgate/spotify" specifies a GitHub
repository rather than a Terraform provider. Refer to the documentation of the
provider to find the correct source address to use.

Somehow the official terraform documentation is leaving me hanging. Would you mind adding a section on terraform version constraints and how to tell terraform how to find the installed provider? Or link me to the official documentation describing it? I seem to be blind.

Thanks in advance. I am really keen on trying out this provider cause so far I manage my playlists via a script which is taking a veeeeery long time due to API calls per minute constraints and I'd love to see a TF provider in action.

spotify_search_track limit

I love this provider and had so much fun using it! I am curious if there is a hard limit to the amount of songs I can pull using the spotify_search_track by_artist data block. It seems like that limit might be 50 right now, but I am trying to pull every song from a particular artist. Let me know if I am missing something or if there is a fix. Thanks!

Make darwin_amd64 version available

Hello,

I was working to use your provider, but I'm using a MacBook Pro M1. I saw the provider isn't built for this platform.

So I cloned your repo and build the provider.

How could I help you to make the darwin_amd64 version of the provider available for all ?

404 Page Not Found : Invalid / Non-existant token id

Hey - I'm following your blog and can't seem to get a a successful query using your provider.

I'm using a self hosted Auth Proxy and have authenticated;

 % docker run --rm -it -p 27228:27228 --env-file ./.env ghcr.io/conradludgate/spotify-auth-proxy
APIKey:   qoYoZ-_ouqBGi7cFslJw8Ilpe9xRPHn7qe3ytPQIxxK4tTrnGrai7VGWL7mdjvlb
Auth URL: http://localhost:27228/authorize?token=QQQDuc8UIw-5Og6DmWhzdQJKbzhOxtbTEPQsN89KcjejJ4ctEInpiJ78q8fO0tl_
Authorization successful

However, when I run the Terraform Apply command I'm met with;

│ Error: could not perform search [[artist:"Dolly Parton"]]: Get "https://api.spotify.com/v1/search?limit=10&q=artist%3A%22Dolly+Parton%22&type=track": 404 page not found
│ 
│ 
│   with data.spotify_search_track.by_artist,
│   on main.tf line 36, in data "spotify_search_track" "by_artist":
│   36: data "spotify_search_track" "by_artist" {

Taking the URL that was spat out above results in;

{
    "error": {
        "status": 401,
        "message": "No token provided"
    }
}

By adding in a Bearer token (Generated through the Dev Console of Spotify) I finally get results to print to POSTMAN, but I don't see anything in your doc that would suggest I could use my bearer token...

Any thoughts?

Support: Terraform does not see the state of songs added to a playlist in the webui

Using Terraform 1.0
Using Provider v0.2.5

Steps to reproduce:
Create a playlist using the terraform provider
Add a track manually through the webui.
Update the state with terraform refresh or try to apply it with terraform apply

Terraform returns no changes.

I thought it should attempt to delete the track that was added through the webui since the playlist was managed.
I checked the terraform.tfstate. I don't see the song added through the webui in there. my playlist

auth_code: ExactlyOneOf cannot be set with Required

Hey Conrad,

Thanks for getting this one working! I think you may get some traffic on this as I posted it to reddit a while back.

I have tried to get this working but running in to an issue.

I have attached it below:

spotify_new on  master [!+?] 🏎💨 v0.13.4 default via  14GiB/16GiB | 976MiB/976MiB on ☁️  (us-east-1) took 6s 
➜ terraform init

Initializing the backend...

Initializing provider plugins...
- Using previously-installed conradludgate/spotify v0.1.3

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

spotify_new on  master [!+?] 🏎💨 v0.13.4 default via  14GiB/16GiB | 976MiB/976MiB on ☁️  (us-east-1) 
➜ terraform plan

Error: Internal validation of the provider failed! This is always a bug
with the provider itself, and not a user issue. Please report
this bug:

1 error occurred:
        * auth_code: ExactlyOneOf cannot be set with Required





spotify_new on  master [!+?] 🏎💨 v0.13.4 default via  14GiB/16GiB | 976MiB/976MiB on ☁️  (us-east-1) 

Not sure what to do here. I will drop you an email to my terraform github and you can let me know if I've gone wrong somewhere.

I ask as I really want to write a blog post for this as I love strange terraform providers!

v0.2

Version 0.2 is in the works. Hopefully I'll have it finished by the end of the week:

Features:

  • More resources that better represent the API and underlying data
  • Interactive and non-interactive provider config, whether you intend to run terraform apply locally or in CI

I've got a bit more experience with implementing terraform providers since working on https://github.com/conradludgate/terraform-provider-caddy and https://github.com/conradludgate/tfutils so hopefully the code should be cleaner and better tested

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.