@@ -2,12 +2,11 @@ package cockpit_test
22
33import (
44 "fmt"
5- "regexp"
65 "testing"
76
87 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
98 "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
10- cockpitSDK "github.com/scaleway/scaleway-sdk-go/api/cockpit/v1beta1 "
9+ cockpitSDK "github.com/scaleway/scaleway-sdk-go/api/cockpit/v1 "
1110 "github.com/scaleway/scaleway-sdk-go/scw"
1211 "github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
1312 "github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
@@ -32,24 +31,27 @@ func TestAccGrafanaUser_Basic(t *testing.T) {
3231 name = "%[1]s"
3332 }
3433
35- resource scaleway_cockpit main {
36- project_id = scaleway_account_project.project.id
37- }
38-
3934 resource scaleway_cockpit_grafana_user main {
40- project_id = scaleway_cockpit.main.project_id
35+ project_id = scaleway_account_project.project.id
4136 login = "%[2]s"
4237 role = "editor"
4338 }
4439 ` , projectName , grafanaTestUsername ),
4540 Check : resource .ComposeTestCheckFunc (
4641 isGrafanaUserPresent (tt , "scaleway_cockpit_grafana_user.main" ),
47- resource .TestCheckResourceAttrPair ("scaleway_cockpit_grafana_user.main" , "project_id" , "scaleway_cockpit.main " , "project_id " ),
42+ resource .TestCheckResourceAttrPair ("scaleway_cockpit_grafana_user.main" , "project_id" , "scaleway_account_project.project " , "id " ),
4843 resource .TestCheckResourceAttr ("scaleway_cockpit_grafana_user.main" , "login" , grafanaTestUsername ),
4944 resource .TestCheckResourceAttr ("scaleway_cockpit_grafana_user.main" , "role" , "editor" ),
5045 resource .TestCheckResourceAttrSet ("scaleway_cockpit_grafana_user.main" , "password" ),
5146 ),
5247 },
48+ {
49+ Config : fmt .Sprintf (`
50+ resource "scaleway_account_project" "project" {
51+ name = "%[1]s"
52+ }
53+ ` , projectName ),
54+ },
5355 },
5456 })
5557}
@@ -72,19 +74,15 @@ func TestAccGrafanaUser_Update(t *testing.T) {
7274 name = "%[1]s"
7375 }
7476
75- resource scaleway_cockpit main {
76- project_id = scaleway_account_project.project.id
77- }
78-
7977 resource scaleway_cockpit_grafana_user main {
80- project_id = scaleway_cockpit.main.project_id
78+ project_id = scaleway_account_project.project.id
8179 login = "%[2]s"
8280 role = "editor"
8381 }
8482 ` , projectName , grafanaTestUsername ),
8583 Check : resource .ComposeTestCheckFunc (
8684 isGrafanaUserPresent (tt , "scaleway_cockpit_grafana_user.main" ),
87- resource .TestCheckResourceAttrPair ("scaleway_cockpit_grafana_user.main" , "project_id" , "scaleway_cockpit.main " , "project_id " ),
85+ resource .TestCheckResourceAttrPair ("scaleway_cockpit_grafana_user.main" , "project_id" , "scaleway_account_project.project " , "id " ),
8886 resource .TestCheckResourceAttr ("scaleway_cockpit_grafana_user.main" , "login" , grafanaTestUsername ),
8987 resource .TestCheckResourceAttr ("scaleway_cockpit_grafana_user.main" , "role" , "editor" ),
9088 resource .TestCheckResourceAttrSet ("scaleway_cockpit_grafana_user.main" , "password" ),
@@ -96,53 +94,26 @@ func TestAccGrafanaUser_Update(t *testing.T) {
9694 name = "%[1]s"
9795 }
9896
99- resource scaleway_cockpit main {
100- project_id = scaleway_account_project.project.id
101- }
102-
10397 resource scaleway_cockpit_grafana_user main {
104- project_id = scaleway_cockpit.main.project_id
98+ project_id = scaleway_account_project.project.id
10599 login = "%[2]s"
106100 role = "viewer"
107101 }
108102 ` , projectName , grafanaTestUsername ),
109103 Check : resource .ComposeTestCheckFunc (
110104 isGrafanaUserPresent (tt , "scaleway_cockpit_grafana_user.main" ),
111- resource .TestCheckResourceAttrPair ("scaleway_cockpit_grafana_user.main" , "project_id" , "scaleway_cockpit.main " , "project_id " ),
105+ resource .TestCheckResourceAttrPair ("scaleway_cockpit_grafana_user.main" , "project_id" , "scaleway_account_project.project " , "id " ),
112106 resource .TestCheckResourceAttr ("scaleway_cockpit_grafana_user.main" , "login" , grafanaTestUsername ),
113107 resource .TestCheckResourceAttr ("scaleway_cockpit_grafana_user.main" , "role" , "viewer" ),
114108 resource .TestCheckResourceAttrSet ("scaleway_cockpit_grafana_user.main" , "password" ),
115109 ),
116110 },
117- },
118- })
119- }
120-
121- func TestAccGrafanaUser_NonExistentCockpit (t * testing.T ) {
122- tt := acctest .NewTestTools (t )
123- defer tt .Cleanup ()
124-
125- projectName := "tf_tests_cockpit_grafana_user_non_existent_cockpit"
126- grafanaTestUsername := "testnonexistentuser"
127-
128- resource .ParallelTest (t , resource.TestCase {
129- PreCheck : func () { acctest .PreCheck (t ) },
130- ProviderFactories : tt .ProviderFactories ,
131- CheckDestroy : isGrafanaUserDestroyed (tt ),
132- Steps : []resource.TestStep {
133111 {
134112 Config : fmt .Sprintf (`
135113 resource "scaleway_account_project" "project" {
136114 name = "%[1]s"
137115 }
138-
139- resource scaleway_cockpit_grafana_user main {
140- project_id = scaleway_account_project.project.id
141- login = "%[2]s"
142- role = "editor"
143- }
144- ` , projectName , grafanaTestUsername ),
145- ExpectError : regexp .MustCompile ("not found" ),
116+ ` , projectName ),
146117 },
147118 },
148119 })
@@ -160,7 +131,7 @@ func isGrafanaUserPresent(tt *acctest.TestTools, n string) resource.TestCheckFun
160131 return err
161132 }
162133
163- res , err := api .ListGrafanaUsers (& cockpitSDK.ListGrafanaUsersRequest {
134+ res , err := api .ListGrafanaUsers (& cockpitSDK.GlobalAPIListGrafanaUsersRequest {
164135 ProjectID : projectID ,
165136 }, scw .WithAllPages ())
166137 if err != nil {
@@ -195,7 +166,7 @@ func isGrafanaUserDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
195166 return err
196167 }
197168
198- err = api .DeleteGrafanaUser (& cockpitSDK.DeleteGrafanaUserRequest {
169+ err = api .DeleteGrafanaUser (& cockpitSDK.GlobalAPIDeleteGrafanaUserRequest {
199170 ProjectID : projectID ,
200171 GrafanaUserID : grafanaUserID ,
201172 })
0 commit comments