Skip to content

ryanbynoe/spotifytf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

Custom Spotify Playlist Using Terraform!

Build A Spotify Playlist using Docker and Terraform!

bart

diagram

Table of Contents

Prerequisites

Walkthrough

I posess a Spotify account so all I needed was to create a Spotify Developer account. A free spotify account will suffice.

First we need to setup the Spotify provider in order to obtain and use the resources. We will use the spotify provider here and pressing the use provider to display code or below.

terraform {
  required_providers {
    spotify = {
      source = "conradludgate/spotify"
      version = "0.2.7"
    }
  }
}

provider "spotify" {
  # Configuration options
}

Spotify Provider

provider.tf file should look like this and we will add the configuration options later: ProviderTF

Next we will need an API Key and this will be used to connect with the Spotify account. After creating a free Spotify account, Create a Developer account.

createapp

Enter the details to your liking except the Redirect URL must be:

http://localhost:27228/spotify_callback

spoptifydetails

Next we will need to grab the Client ID and Client Secret from the settings. We will store these two codes in an .env file. Settings

SPOTIFY_CLIENT_ID=<enter_spotify_client_id_without>
SPOTIFY_CLIENT_SECRET=<enter_spotify_client_secret>

Should look like this below:

env

Run docker to retrieve the API Key. Confirm Docker Desktop is running first.

docker run --rm -it -p 27228:27228 --env-file .env ghcr.io/conradludgate/spotify-auth-proxy

Authorization successful will display if setup correctly. Copy the API Key and enter in a new file called terraform.tfvars. Then press the link in Auth Url: and the page will open to allow access to your Spotify account. Leave terminal open and create a new terminal:

authsuccess

tf

Set a variable in the provider.tf file in configuration options: provup

Create the variables.tf file to hold the api_key variable as a string type:

variable "api_key" {
    type = string
}

variable

The fun part is here. Now we will run terraform init which will run and install the files we have created.

terraforminit

Create Spotify playlist by first creating a playlist.tf file. The artist of choice is Larry June one of my favorite artists. More resources can be found on the documentation of the spotify provider here

data "spotify_search_track" "by_artist" {
  artist = "Larry June"
}


resource "spotify_playlist" "Larry_June_Terraform" {
  name        = "Larry June 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.tracks[1].id,
    data.spotify_search_track.by_artist.tracks[2].id,
  ]
}

After the information has been entered in, next is terraform plan in terminal. This will tell us the actions that will be executed when applied. I created a previous playlist so notice how that will be destroyed when the code has been updated: plan

terraform apply -auto-approve will apply the actions: apply

Result

lj

Challenges

Docker issue: Docker for Windows: image operating system “linux” cannot be used on this platform.

  • Check Docker Desktop Builders to ensure desktop-linux is up and running. if desktop-windows is running, the error will display. If error persists, try to uninstall and reinistall Docker.

dockbuild

Code Error: Inappropriate value for attribute "artist": string required.

  • Confirm brackets aren't wrapped around the artist name. Only quotations. code

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published