Skip to content

Commit 9183dd4

Browse files
Playlist: Fix update (#719)
* Playlist: Update interval test * Set ID when updating
1 parent fd9ca4c commit 9183dd4

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

grafana/resource_playlist.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package grafana
33
import (
44
"context"
55
"log"
6+
"strconv"
67
"strings"
78

89
gapi "github.com/grafana/grafana-api-golang-client"
@@ -124,6 +125,13 @@ func UpdatePlaylist(ctx context.Context, d *schema.ResourceData, meta interface{
124125
Items: expandPlaylistItems(d.Get("item").(*schema.Set).List()),
125126
}
126127

128+
// Support both Grafana 9.0+ and older versions (UID is used in 9.0+)
129+
if idInt, err := strconv.Atoi(d.Id()); err == nil {
130+
playlist.ID = idInt
131+
} else {
132+
playlist.UID = d.Id()
133+
}
134+
127135
err := client.UpdatePlaylist(playlist)
128136
if err != nil {
129137
return diag.Errorf("error updating Playlist (%s): %v", d.Id(), err)

grafana/resource_playlist_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestAccPlaylist_basic(t *testing.T) {
2222
CheckDestroy: testAccPlaylistDestroy,
2323
Steps: []resource.TestStep{
2424
{
25-
Config: testAccPlaylistConfigBasic(rName),
25+
Config: testAccPlaylistConfigBasic(rName, "5m"),
2626
Check: resource.ComposeTestCheckFunc(
2727
testAccPlaylistCheckExists(),
2828
resource.TestMatchResourceAttr(paylistResource, "id", uidRegexp),
@@ -58,9 +58,17 @@ func TestAccPlaylist_update(t *testing.T) {
5858
CheckDestroy: testAccPlaylistDestroy,
5959
Steps: []resource.TestStep{
6060
{
61-
Config: testAccPlaylistConfigBasic(rName),
61+
Config: testAccPlaylistConfigBasic(rName, "5m"),
6262
Check: resource.ComposeTestCheckFunc(
6363
testAccPlaylistCheckExists(),
64+
resource.TestCheckResourceAttr(paylistResource, "interval", "5m"),
65+
),
66+
},
67+
{
68+
Config: testAccPlaylistConfigBasic(rName, "10m"),
69+
Check: resource.ComposeTestCheckFunc(
70+
testAccPlaylistCheckExists(),
71+
resource.TestCheckResourceAttr(paylistResource, "interval", "10m"),
6472
),
6573
},
6674
{
@@ -97,7 +105,7 @@ func TestAccPlaylist_disappears(t *testing.T) {
97105
CheckDestroy: testAccPlaylistDestroy,
98106
Steps: []resource.TestStep{
99107
{
100-
Config: testAccPlaylistConfigBasic(rName),
108+
Config: testAccPlaylistConfigBasic(rName, "5m"),
101109
Check: resource.ComposeTestCheckFunc(
102110
testAccPlaylistCheckExists(),
103111
testAccPlaylistDisappears(),
@@ -172,11 +180,11 @@ func testAccPlaylistDestroy(s *terraform.State) error {
172180
return nil
173181
}
174182

175-
func testAccPlaylistConfigBasic(name string) string {
183+
func testAccPlaylistConfigBasic(name, interval string) string {
176184
return fmt.Sprintf(`
177185
resource "grafana_playlist" "test" {
178186
name = %[1]q
179-
interval = "5m"
187+
interval = %[2]q
180188
181189
item {
182190
order = 1
@@ -188,7 +196,7 @@ resource "grafana_playlist" "test" {
188196
title = "Terraform Dashboard By ID"
189197
}
190198
}
191-
`, name)
199+
`, name, interval)
192200
}
193201

194202
func testAccPlaylistConfigUpdate(name string) string {

0 commit comments

Comments
 (0)