Create dynamic playlists based on weather, time of day, and your listening history using infrastructure as code.
Create playlists that automatically update based on your mood, the weather, time of day, or your listening history.
See examples →Sunny day? Rainy evening? Your playlist adapts to match the current weather conditions.
Morning energy, afternoon focus, or evening chill - get the right vibe at the right time.
Recommendations based on your short, medium, and long-term listening patterns.
I am not affiliated with either Terraform or Spotify.
Everything you need to manage your Spotify experience with Terraform
Create, update, and manage playlists with infrastructure as code. Define tracks, descriptions, and visibility settings.
Generate dynamic cover images based on mood, weather, or custom emojis to give your playlists visual personality.
Keep your playlists fresh with scheduled updates using GitHub Actions or any CI/CD pipeline.
Access your top artists, genres, and tracks to create personalized recommendations.
Connect to weather APIs to generate mood-appropriate playlists based on current conditions.
Create different playlists for different times of day, days of the week, or seasons.
Create a dynamic weather-based playlist with just a few lines of code
# Get current weather data and mood
data "spotify_weather" "current" {}
# Get time-based information
data "spotify_time" "now" {}
# Get track recommendations based on weather and time
data "spotify_tracks" "recommended" {
genre = data.spotify_time.now.suggested_seed_genres[0]
mood = data.spotify_weather.current.mood
limit = 20
}
# Create the dynamic playlist
resource "spotify_playlist" "dynamic" {
name = "${data.spotify_weather.current.mood} ${data.spotify_time.now.time_of_day} Mix"
description = "Auto-generated based on weather (${data.spotify_weather.current.condition}) and time (${data.spotify_time.now.time_of_day})"
public = true
tracks = data.spotify_tracks.recommended.ids
}
# Add a dynamic cover image
resource "spotify_playlist_cover" "dynamic_cover" {
playlist_id = spotify_playlist.dynamic.id
mood = data.spotify_weather.current.mood
weather = data.spotify_weather.current.condition
force_update = true
}
Set up the Terraform Spotify Provider in minutes
Add the provider to your Terraform configuration:
terraform {
required_providers {
spotify = {
source = "ashrafxbilal/spotify"
version = "0.1.0"
}
}
}
Set up your Spotify API credentials:
provider "spotify" {
client_id = "your-client-id"
client_secret = "your-client-secret"
redirect_uri = "your-redirect-uri"
refresh_token = "your-refresh-token"
}
Start with a simple playlist configuration:
resource "spotify_playlist" "example" {
name = "My Terraform Playlist"
description = "Created with Terraform"
public = true
tracks = [
"spotify:track:4iV5W9uYEdYUVa79Axb7Rh",
"spotify:track:1301WleyT98MSxVHPZCA6M"
]
}
Explore the full capabilities of the Terraform Spotify Provider
Learn how to configure the provider with your Spotify credentials.
Read more →