@@ -3,7 +3,6 @@ package acceptance
33import (
44 "context"
55 "fmt"
6- "os"
76 "testing"
87
98 "github.com/databricks/databricks-sdk-go"
@@ -22,36 +21,34 @@ const awsSpn = `resource "databricks_service_principal" "this" {
2221}`
2322
2423func TestAccServicePrincipalHomeDeleteSuccess (t * testing.T ) {
25- GetEnvOrSkipTest (t , "ARM_CLIENT_ID" )
24+ loadWorkspaceEnv (t )
25+ if ! isAzure (t ) {
26+ skipf (t )("Test only valid for Azure" )
27+ }
28+ uuid := createUuid ()
29+ template := `
30+ resource "databricks_service_principal" "a" {
31+ application_id = "` + uuid + `"
32+ force_delete_home_dir = true
33+ }`
34+ var spId string
2635 workspaceLevel (t , step {
27- Template : `
28- resource "databricks_service_principal" "a" {
29- application_id = "{var.RANDOM_UUID}"
30- force_delete_home_dir = true
31- }` ,
36+ Template : template ,
3237 Check : func (s * terraform.State ) error {
33- appId := s .RootModule ().Resources ["databricks_service_principal.a" ].Primary .Attributes ["application_id" ]
34- os .Setenv ("application_id_a" , appId )
38+ spId = s .RootModule ().Resources ["databricks_service_principal.a" ].Primary .Attributes ["application_id" ]
3539 return nil
3640 },
3741 }, step {
38- Template : `
39- resource "databricks_service_principal" "b" {
40- application_id = "{var.RANDOM_UUID}"
41- }
42- ` ,
42+ Template : template ,
43+ Destroy : true ,
4344 Check : func (s * terraform.State ) error {
4445 w , err := databricks .NewWorkspaceClient ()
4546 if err != nil {
4647 return err
4748 }
4849 ctx := context .Background ()
49- _ , err = w .Workspace .GetStatusByPath (ctx , fmt .Sprintf ("/Users/%v" , os .Getenv ("application_id_a" )))
50- os .Remove ("application_id_a" )
51- if err != nil {
52- if apierr .IsMissing (err ) {
53- return nil
54- }
50+ _ , err = w .Workspace .GetStatusByPath (ctx , fmt .Sprintf ("/Users/%v" , spId ))
51+ if err != nil && ! apierr .IsMissing (err ) {
5552 return err
5653 }
5754 return nil
@@ -60,24 +57,26 @@ func TestAccServicePrincipalHomeDeleteSuccess(t *testing.T) {
6057}
6158
6259func TestAccServicePrinicpalHomeDeleteNotDeleted (t * testing.T ) {
63- GetEnvOrSkipTest (t , "ARM_CLIENT_ID" )
60+ loadWorkspaceEnv (t )
61+ if ! isAzure (t ) {
62+ skipf (t )("Test only valid for Azure" )
63+ }
64+ uuid := createUuid ()
65+ template := `
66+ resource "databricks_service_principal" "a" {
67+ application_id = "` + uuid + `"
68+ force_delete_home_dir = false
69+ }`
6470 var appId string
6571 workspaceLevel (t , step {
66- Template : `
67- resource "databricks_service_principal" "a" {
68- application_id = "{var.RANDOM_UUID}"
69- force_delete_home_dir = false
70- }` ,
72+ Template : template ,
7173 Check : func (s * terraform.State ) error {
7274 appId = s .RootModule ().Resources ["databricks_service_principal.a" ].Primary .Attributes ["application_id" ]
7375 return provisionHomeFolder (context .Background (), s , "databricks_service_principal.a" , appId )
7476 },
7577 }, step {
76- Template : `
77- resource "databricks_service_principal" "b" {
78- application_id = "{var.RANDOM_UUID}"
79- }
80- ` ,
78+ Template : template ,
79+ Destroy : true ,
8180 Check : func (s * terraform.State ) error {
8281 w , err := databricks .NewWorkspaceClient ()
8382 if err != nil {
0 commit comments