@@ -246,6 +246,103 @@ subjects.0.subject.2.kind = group
246246subjects.0.subject.2.service_account_id =
247247subjects.0.subject.2.user_id =
248248Tainted = false
249+ ` , data .State ().String ())
250+ })
251+
252+ t .Run ("when RbacServiceAPI respond with 200 then populate the state with scopes" , func (t * testing.T ) {
253+ t .Parallel ()
254+
255+ r := require .New (t )
256+ mockClient := mock_sdk .NewMockClientInterface (gomock .NewController (t ))
257+
258+ ctx := context .Background ()
259+ provider := & ProviderConfig {
260+ api : & sdk.ClientWithResponses {
261+ ClientInterface : mockClient ,
262+ },
263+ }
264+
265+ organizationID := "4e4cd9eb-82eb-407e-a926-e5fef81cab50"
266+ roleBindingID := "a83b7bf2-5a99-45d9-bcac-b969386e751f"
267+ roleID := "4df39779-dfb2-48d3-91d8-7ee5bd2bca4b"
268+ userID := "671b2ebb-f361-42f0-aa2f-3049de93f8c1"
269+ serviceAccountID := "b11f5945-22ca-4101-a86e-d6e37f44a415"
270+ groupID := "844d2bf2-870d-42da-a81c-4e19befc78fc"
271+
272+ body := io .NopCloser (bytes .NewReader ([]byte (`{
273+ "id": "` + roleBindingID + `",
274+ "organizationId": "` + organizationID + `",
275+ "name": "role-binding-name",
276+ "description": "role-binding-description",
277+ "definition": {
278+ "roleId": "` + roleID + `",
279+ "scopes": [
280+ {
281+ "organization": {
282+ "id": "` + organizationID + `"
283+ }
284+ }
285+ ],
286+ "subjects": [
287+ {
288+ "user": {
289+ "id": "` + userID + `"
290+ }
291+ },
292+ {
293+ "serviceAccount": {
294+ "id": "` + serviceAccountID + `"
295+ }
296+ },
297+ {
298+ "group": {
299+ "id": "` + groupID + `"
300+ }
301+ }
302+ ]
303+ }
304+ }` )))
305+
306+ mockClient .EXPECT ().
307+ RbacServiceAPIGetRoleBinding (gomock .Any (), organizationID , roleBindingID ).
308+ Return (& http.Response {StatusCode : 200 , Body : body , Header : map [string ][]string {"Content-Type" : {"json" }}}, nil )
309+
310+ stateValue := cty .ObjectVal (map [string ]cty.Value {
311+ "organization_id" : cty .StringVal (organizationID ),
312+ })
313+ state := terraform .NewInstanceStateShimmedFromValue (stateValue , 0 )
314+ state .ID = roleBindingID
315+
316+ resource := resourceRoleBindings ()
317+ data := resource .Data (state )
318+
319+ result := resource .ReadContext (ctx , data , provider )
320+
321+ r .Nil (result )
322+ r .False (result .HasError ())
323+ r .Equal (`ID = ` + roleBindingID + `
324+ description = role-binding-description
325+ name = role-binding-name
326+ organization_id = ` + organizationID + `
327+ role_id = ` + roleID + `
328+ scopes.# = 1
329+ scopes.0.kind = organization
330+ scopes.0.resource_id = ` + organizationID + `
331+ subjects.# = 1
332+ subjects.0.subject.# = 3
333+ subjects.0.subject.0.group_id =
334+ subjects.0.subject.0.kind = user
335+ subjects.0.subject.0.service_account_id =
336+ subjects.0.subject.0.user_id = ` + userID + `
337+ subjects.0.subject.1.group_id =
338+ subjects.0.subject.1.kind = service_account
339+ subjects.0.subject.1.service_account_id = ` + serviceAccountID + `
340+ subjects.0.subject.1.user_id =
341+ subjects.0.subject.2.group_id = ` + groupID + `
342+ subjects.0.subject.2.kind = group
343+ subjects.0.subject.2.service_account_id =
344+ subjects.0.subject.2.user_id =
345+ Tainted = false
249346` , data .State ().String ())
250347 })
251348}
0 commit comments