@@ -9,13 +9,11 @@ import (
99 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1010 "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
1111 "github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
12-
13- matlas "go.mongodb.org/atlas/mongodbatlas"
1412)
1513
1614func DataSource () * schema.Resource {
1715 return & schema.Resource {
18- ReadContext : dataSourceMongoDBAtlasOrgIDRead ,
16+ ReadContext : dataSourceRead ,
1917 Schema : map [string ]* schema.Schema {
2018 "org_id" : {
2119 Type : schema .TypeString ,
@@ -25,29 +23,21 @@ func DataSource() *schema.Resource {
2523 }
2624}
2725
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 ()
3629 if err != nil {
3730 return diag .Errorf ("error getting API Key's org assigned (%s): " , err )
3831 }
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 {
4335 return diag .Errorf (constant .ErrorSettingAttribute , "org_id" , err )
4436 }
45- d .SetId (apiKeyOrgList . APIKey . Roles [ idx ]. OrgID )
37+ d .SetId (role . GetOrgId () )
4638 return nil
4739 }
4840 }
49-
5041 d .SetId (id .UniqueId ())
51-
5242 return nil
5343}
0 commit comments