@@ -2,7 +2,7 @@ package grafana_test
22
33import (
44 "fmt"
5- "regexp "
5+ "strings "
66 "testing"
77
88 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
@@ -30,7 +30,7 @@ func TestAccRole_basic(t *testing.T) {
3030 resource .TestCheckResourceAttr ("grafana_role.test" , "display_name" , "testdisplay" ),
3131 resource .TestCheckResourceAttr ("grafana_role.test" , "group" , "testgroup" ),
3232 resource .TestCheckResourceAttr ("grafana_role.test" , "version" , "1" ),
33- resource .TestCheckResourceAttr ("grafana_role.test" , "uid" , "testuid " ),
33+ resource .TestCheckResourceAttr ("grafana_role.test" , "uid" , "terraform-acc-test " ),
3434 resource .TestCheckResourceAttr ("grafana_role.test" , "global" , "true" ),
3535 resource .TestCheckResourceAttr ("grafana_role.test" , "hidden" , "true" ),
3636 ),
@@ -44,7 +44,7 @@ func TestAccRole_basic(t *testing.T) {
4444 resource .TestCheckResourceAttr ("grafana_role.test" , "display_name" , "testdisplay" ),
4545 resource .TestCheckResourceAttr ("grafana_role.test" , "group" , "testgroup" ),
4646 resource .TestCheckResourceAttr ("grafana_role.test" , "version" , "2" ),
47- resource .TestCheckResourceAttr ("grafana_role.test" , "uid" , "testuid " ),
47+ resource .TestCheckResourceAttr ("grafana_role.test" , "uid" , "terraform-acc-test " ),
4848 resource .TestCheckResourceAttr ("grafana_role.test" , "global" , "true" ),
4949 resource .TestCheckResourceAttr ("grafana_role.test" , "hidden" , "true" ),
5050 resource .TestCheckResourceAttr ("grafana_role.test" , "permissions.#" , "2" ),
@@ -57,18 +57,14 @@ func TestAccRole_basic(t *testing.T) {
5757 })
5858}
5959
60- func TestAccRole_GlobalRolesNeedBasicAuth (t * testing.T ) {
60+ func TestAccRole_NonGlobalRolesCanBeManagedWithSA (t * testing.T ) {
6161 testutils .CheckEnterpriseTestsEnabled (t , ">=9.0.0" )
6262 orgScopedTest (t )
6363 randomName := acctest .RandString (10 )
6464
6565 resource .Test (t , resource.TestCase {
6666 ProtoV5ProviderFactories : testutils .ProtoV5ProviderFactories ,
6767 Steps : []resource.TestStep {
68- {
69- Config : roleConfig (randomName , true ),
70- ExpectError : regexp .MustCompile ("global scope resources cannot be managed with an API key. Use basic auth instead" ),
71- },
7268 {
7369 Config : roleConfig (randomName , false ),
7470 Check : resource .ComposeTestCheckFunc (
@@ -77,7 +73,7 @@ func TestAccRole_GlobalRolesNeedBasicAuth(t *testing.T) {
7773 resource .TestCheckResourceAttr ("grafana_role.test" , "display_name" , "testdisplay" ),
7874 resource .TestCheckResourceAttr ("grafana_role.test" , "group" , "testgroup" ),
7975 resource .TestCheckResourceAttr ("grafana_role.test" , "version" , "1" ),
80- resource .TestCheckResourceAttr ("grafana_role.test" , "uid" , "testuid" ),
76+ resource .TestCheckResourceAttr ("grafana_role.test" , "uid" , randomName ),
8177 resource .TestCheckResourceAttr ("grafana_role.test" , "global" , "false" ),
8278 resource .TestCheckResourceAttr ("grafana_role.test" , "hidden" , "true" ),
8379 ),
@@ -86,6 +82,44 @@ func TestAccRole_GlobalRolesNeedBasicAuth(t *testing.T) {
8682 })
8783}
8884
85+ func TestAccRole_GlobalCanBeManagedInGrafanaCloud (t * testing.T ) {
86+ t .Skip ("Broken for now. Fix incoming." )
87+ testutils .CheckCloudInstanceTestsEnabled (t )
88+ randomName := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
89+
90+ resource .ParallelTest (t , resource.TestCase {
91+ ProtoV5ProviderFactories : testutils .ProtoV5ProviderFactories ,
92+ Steps : []resource.TestStep {
93+ {
94+ Config : roleConfig (randomName , true ),
95+ Check : resource .ComposeTestCheckFunc (
96+ resource .TestCheckResourceAttr ("grafana_role.test" , "name" , randomName ),
97+ resource .TestCheckResourceAttr ("grafana_role.test" , "description" , "test desc" ),
98+ resource .TestCheckResourceAttr ("grafana_role.test" , "display_name" , "testdisplay" ),
99+ resource .TestCheckResourceAttr ("grafana_role.test" , "group" , "testgroup" ),
100+ resource .TestCheckResourceAttr ("grafana_role.test" , "version" , "1" ),
101+ resource .TestCheckResourceAttr ("grafana_role.test" , "uid" , randomName ),
102+ resource .TestCheckResourceAttr ("grafana_role.test" , "global" , "true" ),
103+ resource .TestCheckResourceAttr ("grafana_role.test" , "hidden" , "true" ),
104+ ),
105+ },
106+ {
107+ Config : strings .ReplaceAll (roleConfig (randomName , true ), "test desc" , "updated desc" ),
108+ Check : resource .ComposeTestCheckFunc (
109+ resource .TestCheckResourceAttr ("grafana_role.test" , "name" , randomName ),
110+ resource .TestCheckResourceAttr ("grafana_role.test" , "description" , "updated desc" ),
111+ resource .TestCheckResourceAttr ("grafana_role.test" , "display_name" , "testdisplay" ),
112+ resource .TestCheckResourceAttr ("grafana_role.test" , "group" , "testgroup" ),
113+ resource .TestCheckResourceAttr ("grafana_role.test" , "version" , "1" ),
114+ resource .TestCheckResourceAttr ("grafana_role.test" , "uid" , randomName ),
115+ resource .TestCheckResourceAttr ("grafana_role.test" , "global" , "true" ),
116+ resource .TestCheckResourceAttr ("grafana_role.test" , "hidden" , "true" ),
117+ ),
118+ },
119+ },
120+ })
121+ }
122+
89123func TestAccRoleVersioning (t * testing.T ) {
90124 testutils .CheckEnterpriseTestsEnabled (t , ">=9.0.0" )
91125
@@ -218,11 +252,11 @@ var roleConfigBasic = roleConfig("terraform-acc-test", true)
218252func roleConfig (name string , global bool ) string {
219253 return fmt .Sprintf (`
220254 resource "grafana_role" "test" {
221- name = "%s"
255+ name = "%[1] s"
222256 description = "test desc"
223257 version = 1
224- uid = "testuid "
225- global = %t
258+ uid = "%[1]s "
259+ global = %[2] t
226260 group = "testgroup"
227261 display_name = "testdisplay"
228262 hidden = true
@@ -235,7 +269,7 @@ resource "grafana_role" "test" {
235269 name = "terraform-acc-test"
236270 description = "test desc"
237271 version = 2
238- uid = "testuid "
272+ uid = "terraform-acc-test "
239273 global = true
240274 group = "testgroup"
241275 display_name = "testdisplay"
0 commit comments