The Spotify provider allows you to manage Spotify resources like playlists and tracks using infrastructure as code. It also provides data sources for retrieving information based on weather, time, and user profiles to create dynamic, mood-based playlists.
terraform {
required_providers {
spotify = {
source = "ashrafxbilal/spotify"
version = "0.1.0"
}
}
}
provider "spotify" {
client_id = var.spotify_client_id
client_secret = var.spotify_client_secret
redirect_uri = var.spotify_redirect_uri
refresh_token = var.spotify_refresh_token
}
The Spotify provider requires several credentials to authenticate with the Spotify API:
| Credential | Description |
|---|---|
client_id |
Your Spotify application client ID |
client_secret |
Your Spotify application client secret |
redirect_uri |
The redirect URI configured for your Spotify application |
refresh_token |
A refresh token obtained through the OAuth flow |
These can be provided in the provider configuration block or as environment variables:
# Set environment variables for authentication
export SPOTIFY_CLIENT_ID="your-client-id"
export SPOTIFY_CLIENT_SECRET="your-client-secret"
export SPOTIFY_REDIRECT_URI="your-redirect-uri"
export SPOTIFY_REFRESH_TOKEN="your-refresh-token"
Before using this provider, you need to create a Spotify Developer application:
http://localhost:8888/callback)To obtain a refresh token, you can use the included authentication helper:
# Clone the repository
git clone https://github.com/ashrafxbilal/terraform-provider-spotify.git
cd terraform-provider-spotify
# Set your Spotify credentials
export SPOTIFY_CLIENT_ID="your-client-id"
export SPOTIFY_CLIENT_SECRET="your-client-secret"
export SPOTIFY_REDIRECT_URI="your-redirect-uri"
# Run the authentication helper
go run spotify_auth_proxy/spotify-auth.go
Follow the instructions to authorize the application and obtain a refresh token.
Create a Terraform configuration file (e.g., main.tf) with the provider configuration:
terraform {
required_providers {
spotify = {
source = "ashrafxbilal/spotify"
version = "0.1.0"
}
}
}
provider "spotify" {
client_id = var.spotify_client_id
client_secret = var.spotify_client_secret
redirect_uri = var.spotify_redirect_uri
refresh_token = var.spotify_refresh_token
}
| Argument | Description |
|---|---|
client_id |
(Required) Your Spotify application client ID. Can also be set with the SPOTIFY_CLIENT_ID environment variable. |
client_secret |
(Required) Your Spotify application client secret. Can also be set with the SPOTIFY_CLIENT_SECRET environment variable. |
redirect_uri |
(Required) The redirect URI configured for your Spotify application. Can also be set with the SPOTIFY_REDIRECT_URI environment variable. |
refresh_token |
(Required) A refresh token obtained through the OAuth flow. Can also be set with the SPOTIFY_REFRESH_TOKEN environment variable. |
api_url |
(Optional) The Spotify API URL. Defaults to https://api.spotify.com/v1. |
auth_url |
(Optional) The Spotify authentication URL. Defaults to https://accounts.spotify.com/api/token. |