@@ -9,13 +9,11 @@ import (
9
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10
10
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
11
11
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
12
-
13
- matlas "go.mongodb.org/atlas/mongodbatlas"
14
12
)
15
13
16
14
func DataSource () * schema.Resource {
17
15
return & schema.Resource {
18
- ReadContext : dataSourceMongoDBAtlasOrgIDRead ,
16
+ ReadContext : dataSourceRead ,
19
17
Schema : map [string ]* schema.Schema {
20
18
"org_id" : {
21
19
Type : schema .TypeString ,
@@ -25,29 +23,21 @@ func DataSource() *schema.Resource {
25
23
}
26
24
}
27
25
28
- func dataSourceMongoDBAtlasOrgIDRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
29
- // Get client connection.
30
- conn := meta .(* config.MongoDBClient ).Atlas
31
-
32
- var err error
33
-
34
- options := & matlas.ListOptions {}
35
- apiKeyOrgList , _ , err := conn .Root .List (ctx , options )
26
+ func dataSourceRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
27
+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
28
+ apiKeyOrgList , _ , err := connV2 .RootApi .GetSystemStatus (ctx ).Execute ()
36
29
if err != nil {
37
30
return diag .Errorf ("error getting API Key's org assigned (%s): " , err )
38
31
}
39
-
40
- for idx , role := range apiKeyOrgList .APIKey .Roles {
41
- if strings .HasPrefix (role .RoleName , "ORG_" ) {
42
- if err := d .Set ("org_id" , apiKeyOrgList .APIKey .Roles [idx ].OrgID ); err != nil {
32
+ for _ , role := range apiKeyOrgList .ApiKey .GetRoles () {
33
+ if strings .HasPrefix (role .GetRoleName (), "ORG_" ) {
34
+ if err := d .Set ("org_id" , role .GetOrgId ()); err != nil {
43
35
return diag .Errorf (constant .ErrorSettingAttribute , "org_id" , err )
44
36
}
45
- d .SetId (apiKeyOrgList . APIKey . Roles [ idx ]. OrgID )
37
+ d .SetId (role . GetOrgId () )
46
38
return nil
47
39
}
48
40
}
49
-
50
41
d .SetId (id .UniqueId ())
51
-
52
42
return nil
53
43
}
0 commit comments