@@ -26,7 +26,7 @@ func TestAccServiceAccount_basic(t *testing.T) {
2626 CheckDestroy : serviceAccountCheckExists .destroyed (& updatedSA , nil ),
2727 Steps : []resource.TestStep {
2828 {
29- Config : testServiceAccountConfig (name , "Editor" ),
29+ Config : testServiceAccountConfig (name , "Editor" , false ),
3030 Check : resource .ComposeTestCheckFunc (
3131 serviceAccountCheckExists .exists ("grafana_service_account.test" , & sa ),
3232 resource .TestCheckResourceAttr ("grafana_service_account.test" , "name" , name ),
@@ -38,7 +38,7 @@ func TestAccServiceAccount_basic(t *testing.T) {
3838 },
3939 // Change the name. Check that the ID stays the same.
4040 {
41- Config : testServiceAccountConfig (name + "-updated" , "Editor" ),
41+ Config : testServiceAccountConfig (name + "-updated" , "Editor" , false ),
4242 Check : resource .ComposeTestCheckFunc (
4343 serviceAccountCheckExists .exists ("grafana_service_account.test" , & updatedSA ),
4444 func (s * terraform.State ) error {
@@ -54,6 +54,12 @@ func TestAccServiceAccount_basic(t *testing.T) {
5454 resource .TestMatchResourceAttr ("grafana_service_account.test" , "id" , defaultOrgIDRegexp ),
5555 ),
5656 },
57+ // Import test
58+ {
59+ ResourceName : "grafana_service_account.test" ,
60+ ImportState : true ,
61+ ImportStateVerify : true ,
62+ },
5763 },
5864 })
5965}
@@ -69,7 +75,7 @@ func TestAccServiceAccount_NoneRole(t *testing.T) {
6975 CheckDestroy : serviceAccountCheckExists .destroyed (& sa , nil ),
7076 Steps : []resource.TestStep {
7177 {
72- Config : testServiceAccountConfig (name , "None" ),
78+ Config : testServiceAccountConfig (name , "None" , false ),
7379 Check : resource .ComposeTestCheckFunc (
7480 serviceAccountCheckExists .exists ("grafana_service_account.test" , & sa ),
7581 resource .TestCheckResourceAttr ("grafana_service_account.test" , "name" , name ),
@@ -79,6 +85,24 @@ func TestAccServiceAccount_NoneRole(t *testing.T) {
7985 resource .TestMatchResourceAttr ("grafana_service_account.test" , "id" , defaultOrgIDRegexp ),
8086 ),
8187 },
88+ // Disable the SA
89+ {
90+ Config : testServiceAccountConfig (name , "None" , true ),
91+ Check : resource .ComposeTestCheckFunc (
92+ serviceAccountCheckExists .exists ("grafana_service_account.test" , & sa ),
93+ resource .TestCheckResourceAttr ("grafana_service_account.test" , "name" , name ),
94+ resource .TestCheckResourceAttr ("grafana_service_account.test" , "org_id" , "1" ),
95+ resource .TestCheckResourceAttr ("grafana_service_account.test" , "role" , "None" ),
96+ resource .TestCheckResourceAttr ("grafana_service_account.test" , "is_disabled" , "true" ),
97+ resource .TestMatchResourceAttr ("grafana_service_account.test" , "id" , defaultOrgIDRegexp ),
98+ ),
99+ },
100+ // Import test
101+ {
102+ ResourceName : "grafana_service_account.test" ,
103+ ImportState : true ,
104+ ImportStateVerify : true ,
105+ },
82106 },
83107 })
84108}
@@ -121,7 +145,7 @@ func TestAccServiceAccount_invalid_role(t *testing.T) {
121145 Steps : []resource.TestStep {
122146 {
123147 ExpectError : regexp .MustCompile (`.*expected role to be one of \[.+\], got InvalidRole` ),
124- Config : testServiceAccountConfig ("any" , "InvalidRole" ),
148+ Config : testServiceAccountConfig ("any" , "InvalidRole" , false ),
125149 },
126150 },
127151 })
@@ -143,11 +167,11 @@ func testManyServiceAccountsConfig(prefix string, count int) string {
143167 return config
144168}
145169
146- func testServiceAccountConfig (name , role string ) string {
170+ func testServiceAccountConfig (name , role string , disabled bool ) string {
147171 return fmt .Sprintf (`
148172resource "grafana_service_account" "test" {
149173 name = "%[1]s"
150174 role = "%[2]s"
151- is_disabled = false
152- }` , name , role )
175+ is_disabled = %[3]t
176+ }` , name , role , disabled )
153177}
0 commit comments