GitHub
Back to Documentation
Created by Bilal Ashraf

Resource: spotify_playlist

Manages a Spotify playlist. This resource allows you to create, update, and delete playlists in your Spotify account, as well as manage the tracks within them.

Example Usage

resource "spotify_playlist" "example" {
  name        = "My Terraform Playlist"
  description = "Created and managed by Terraform"
  public      = true
  tracks      = ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"]
}

Dynamic Playlist Example

data "spotify_time" "now" {}
data "spotify_weather" "current" {}
data "spotify_tracks" "recommended" {
  genre = data.spotify_time.now.genre
  mood  = data.spotify_weather.current.mood
  limit = 20
}

resource "spotify_playlist" "dynamic" {
  name        = "${data.spotify_weather.current.mood} ${data.spotify_time.now.time_of_day} Mix"
  description = "Auto-generated based on weather and time of day"
  public      = true
  tracks      = data.spotify_tracks.recommended.ids
}

Argument Reference

Argument Description
name (Required) The name of the playlist.
description (Optional) The description of the playlist.
public (Optional) Whether the playlist is public. Defaults to true.
tracks (Optional) A list of Spotify track URIs or IDs to add to the playlist.
collaborative (Optional) Whether the playlist is collaborative. Defaults to false.

Attribute Reference

Attribute Description
id The ID of the playlist.
snapshot_id The version identifier for the current state of the playlist.
uri The Spotify URI for the playlist.
url The Spotify URL for the playlist.
track_count The number of tracks in the playlist.
owner_id The Spotify user ID of the playlist owner.

Import

Playlists can be imported using the Spotify playlist ID, e.g.:

terraform import spotify_playlist.example 3cEYpjA9oz9GiPac4AsH4n