Overview
Manipulating spotify playlist using Terraform, because why not?
Check out all of the configuration files on GitHub at the repository. I have various examples of Terraform using the Spotify Provider within as well!
Understanding the provider
For all Spotify API usage with Terraform, You must either run a oauth server locally and just provide the API key, or use something online and provide all 4 necessary features (api, token_id, user, and oauth_url). You will need to create a Spotify Developer account here
If you are unfamiliar with running an oauth server, I highly recommend to use this oauth server provided by the creator of the Terraform Spotify Provider! Check it out on his Github page. All the necessary instructions to get started with it will be on there.
Multi-Artist Playlist Creation
The following code will represent how to use Terraform to create a Multi-artist playlist based on artist names
Creating the Provider.tf file
In here, I defined the version to use for the provider, along with setting variables for auth_server
, api_key
, username
, and token_id
|
|
Creating the playlist.tf file
This will be where the core of the Terraform structure is provided. It will use variables defined in the other files to loop through and generate the desired playlist.
|
|
Create your varialbes in a variables.tf
|
|
Define the variables.auto.tfvars file
Ensure to change the information within this file to fit your needs
In this file, reference your spotify_api_key
, spotify_token_id
, spotify_oauth_url
, and spotify_user
|
|
Creating the playlist
After the aformentioned files are created and customized to your liking, just execute the terraform commands:
|
|
Open your spotify and see the newly genereated playlist, and delete the newly generated list with:
|
|
Since Terraform is a stateful deployment, as long as you have control of the state file that gets created alongside Terraform, you can manage and alter the created playlist as you wish.
Useful Resources
Refer to this official spotify guide for creating a self-hosted oauth server, or using the free open source one the creater made: Github
Spotify Provideron Terraform Provider list