@@ -67,23 +67,24 @@ func sameRoles(roles1, roles2 []string) bool {
67
67
68
68
// getKeyDetails returns nil error and nil details if not found as it's not considered an error
69
69
func getKeyDetails (ctx context.Context , connV2 * admin.APIClient , apiKeyID string ) (* admin.ApiKeyUserDetails , string , error ) {
70
- root , _ , err := connV2 .RootApi . GetSystemStatus (ctx ).Execute ()
70
+ resp , _ , err := connV2 .OrganizationsApi . ListOrgs (ctx ).Execute ()
71
71
if err != nil {
72
72
return nil , "" , err
73
73
}
74
- for _ , role := range root . ApiKey . GetRoles () {
75
- if orgID := role . GetOrgId (); orgID != "" {
76
- key , _ , err := connV2 . ProgrammaticAPIKeysApi . GetOrgApiKey ( ctx , orgID , apiKeyID ). Execute ( )
77
- if err != nil {
78
- if admin . IsErrorCode ( err , "API_KEY_NOT_FOUND" ) {
79
- return nil , orgID , nil
80
- }
81
- return nil , orgID , fmt . Errorf ( "error getting api key information: %s" , err )
82
- }
83
- return key , orgID , nil
74
+ orgIDs := resp . GetResults ()
75
+ if len ( orgIDs ) == 0 {
76
+ return nil , "" , fmt . Errorf ( "no organizations found" )
77
+ }
78
+ // At present a PAK or SA belongs to exactly one organization. If this changes in the future, this logic will need to be updated.
79
+ orgID := orgIDs [ 0 ]. GetId ()
80
+ key , _ , err := connV2 . ProgrammaticAPIKeysApi . GetOrgApiKey ( ctx , orgID , apiKeyID ). Execute ()
81
+ if err != nil {
82
+ if admin . IsErrorCode ( err , "API_KEY_NOT_FOUND" ) {
83
+ return nil , orgID , nil
84
84
}
85
+ return nil , orgID , fmt .Errorf ("error getting api key information: %s" , err )
85
86
}
86
- return nil , "" , nil
87
+ return key , orgID , nil
87
88
}
88
89
89
90
func validateUniqueProjectIDs (d * schema.ResourceData ) error {
0 commit comments