@@ -29,7 +29,7 @@ func TestAccGrafanaServiceAccountFromCloud(t *testing.T) {
2929 CheckDestroy : testAccStackCheckDestroy (& stack ),
3030 Steps : []resource.TestStep {
3131 {
32- Config : testAccGrafanaServiceAccountFromCloud (slug , slug , true ),
32+ Config : testAccGrafanaServiceAccountFromCloud (slug , slug , true , "Admin" ),
3333 Check : resource .ComposeTestCheckFunc (
3434 testAccStackCheckExists ("grafana_cloud_stack.test" , & stack ),
3535 testAccGrafanaAuthCheckServiceAccounts (& stack , []string {"management-sa" }),
@@ -42,9 +42,10 @@ func TestAccGrafanaServiceAccountFromCloud(t *testing.T) {
4242 ),
4343 },
4444 {
45- Config : testAccGrafanaServiceAccountFromCloud (slug , slug , false ),
45+ Config : testAccGrafanaServiceAccountFromCloud (slug , slug , false , "Editor" ),
4646 Check : resource .ComposeTestCheckFunc (
4747 resource .TestCheckResourceAttr ("grafana_cloud_stack_service_account.management" , "is_disabled" , "false" ),
48+ resource .TestCheckResourceAttr ("grafana_cloud_stack_service_account.management" , "role" , "Editor" ),
4849 ),
4950 },
5051 {
@@ -60,6 +61,37 @@ func TestAccGrafanaServiceAccountFromCloud(t *testing.T) {
6061 })
6162}
6263
64+ func TestAccGrafanaServiceAccountFromCloudNoneRole (t * testing.T ) {
65+ testutils .CheckCloudAPITestsEnabled (t )
66+
67+ var stack gcom.FormattedApiInstance
68+ prefix := "tfsanone"
69+ slug := GetRandomStackName (prefix )
70+
71+ resource .ParallelTest (t , resource.TestCase {
72+ PreCheck : func () {
73+ testAccDeleteExistingStacks (t , prefix )
74+ },
75+ ProtoV5ProviderFactories : testutils .ProtoV5ProviderFactories ,
76+ CheckDestroy : testAccStackCheckDestroy (& stack ),
77+ Steps : []resource.TestStep {
78+ {
79+ Config : testAccGrafanaServiceAccountFromCloud (slug , slug , true , "None" ),
80+ Check : resource .ComposeTestCheckFunc (
81+ testAccStackCheckExists ("grafana_cloud_stack.test" , & stack ),
82+ testAccGrafanaAuthCheckServiceAccounts (& stack , []string {"management-sa" }),
83+ resource .TestCheckResourceAttr ("grafana_cloud_stack_service_account.management" , "name" , "management-sa" ),
84+ resource .TestCheckResourceAttr ("grafana_cloud_stack_service_account.management" , "role" , "None" ),
85+ resource .TestCheckResourceAttr ("grafana_cloud_stack_service_account.management" , "is_disabled" , "true" ),
86+ resource .TestCheckResourceAttr ("grafana_cloud_stack_service_account_token.management_token" , "name" , "management-sa-token" ),
87+ resource .TestCheckNoResourceAttr ("grafana_cloud_stack_service_account_token.management_token" , "expiration" ),
88+ resource .TestCheckResourceAttrSet ("grafana_cloud_stack_service_account_token.management_token" , "key" ),
89+ ),
90+ },
91+ },
92+ })
93+ }
94+
6395// Tests that the ID change from 2.13.0 to latest works
6496// Remove on next major release
6597func TestAccGrafanaServiceAccountFromCloud_MigrateFrom213 (t * testing.T ) {
@@ -112,12 +144,12 @@ func TestAccGrafanaServiceAccountFromCloud_MigrateFrom213(t *testing.T) {
112144 })
113145}
114146
115- func testAccGrafanaServiceAccountFromCloud (name , slug string , disabled bool ) string {
147+ func testAccGrafanaServiceAccountFromCloud (name , slug string , disabled bool , role string ) string {
116148 return testAccStackConfigBasic (name , slug , "description" ) + fmt .Sprintf (`
117149 resource "grafana_cloud_stack_service_account" "management" {
118150 stack_slug = grafana_cloud_stack.test.slug
119151 name = "management-sa"
120- role = "Admin "
152+ role = "%s "
121153 is_disabled = %t
122154 }
123155
@@ -126,11 +158,11 @@ func testAccGrafanaServiceAccountFromCloud(name, slug string, disabled bool) str
126158 service_account_id = grafana_cloud_stack_service_account.management.id
127159 name = "management-sa-token"
128160 }
129- ` , disabled )
161+ ` , role , disabled )
130162}
131163
132164func testAccGrafanaServiceAccountWithStackFolder (name , slug string , withFolder bool ) string {
133- return testAccGrafanaServiceAccountFromCloud (name , slug , false ) + fmt .Sprintf (`
165+ return testAccGrafanaServiceAccountFromCloud (name , slug , false , "Admin" ) + fmt .Sprintf (`
134166 provider "grafana" {
135167 alias = "stack"
136168 auth = grafana_cloud_stack_service_account_token.management_token.key
0 commit comments