Get Started
Created by Bilal Ashraf

Manage Spotify with Terraform

Create dynamic playlists based on weather, time of day, and your listening history using infrastructure as code.

Weather-Based

Sunny day? Rainy evening? Your playlist adapts to match the current weather conditions.

Time-Aware

Morning energy, afternoon focus, or evening chill - get the right vibe at the right time.

Listening History

Recommendations based on your short, medium, and long-term listening patterns.

Bilal Ashraf - Creator

Disclaimer

I am not affiliated with either Terraform or Spotify.

Features

Everything you need to manage your Spotify experience with Terraform

Playlist Management

Create, update, and manage playlists with infrastructure as code. Define tracks, descriptions, and visibility settings.

Cover Images

Generate dynamic cover images based on mood, weather, or custom emojis to give your playlists visual personality.

Scheduled Refreshes

Keep your playlists fresh with scheduled updates using GitHub Actions or any CI/CD pipeline.

User Preferences

Access your top artists, genres, and tracks to create personalized recommendations.

Weather Integration

Connect to weather APIs to generate mood-appropriate playlists based on current conditions.

Time-Based Logic

Create different playlists for different times of day, days of the week, or seasons.

See It In Action

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
}

Getting Started

Set up the Terraform Spotify Provider in minutes

1

Install the Provider

Add the provider to your Terraform configuration:

terraform {
  required_providers {
    spotify = {
      source  = "ashrafxbilal/spotify"
      version = "0.1.0"
    }
  }
}
2

Configure Authentication

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"
}
3

Create Your First Playlist

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"
  ]
}

Documentation

Explore the full capabilities of the Terraform Spotify Provider

Provider Configuration

Learn how to configure the provider with your Spotify credentials.

Read more →

Playlist Resource

Create and manage Spotify playlists with Terraform.

Read more →

Playlist Cover Resource

Generate dynamic cover images for your playlists.

Read more →

Tracks Data Source

Get track recommendations based on various criteria.

Read more →

Weather Data Source

Use weather conditions to influence your playlists.

Read more →

Time Data Source

Create time-aware playlists that change throughout the day.

Read more →