@@ -6,12 +6,14 @@ import (
6
6
"log"
7
7
"net/http"
8
8
9
+ "go.mongodb.org/atlas-sdk/v20231115003/admin"
10
+
9
11
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10
12
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
13
+ "github.com/mwielbut/pointy"
14
+
11
15
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
12
16
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
13
- "github.com/mwielbut/pointy"
14
- matlas "go.mongodb.org/atlas/mongodbatlas"
15
17
)
16
18
17
19
func Resource () * schema.Resource {
@@ -64,8 +66,8 @@ func Resource() *schema.Resource {
64
66
}
65
67
66
68
func resourceMongoDBAtlasOrganizationCreate (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
67
- conn := meta .(* config.MongoDBClient ).Atlas
68
- organization , resp , err := conn .Organizations . Create (ctx , newCreateOrganizationRequest (d ))
69
+ conn := meta .(* config.MongoDBClient ).AtlasV2
70
+ organization , resp , err := conn .OrganizationsApi . CreateOrganization (ctx , newCreateOrganizationRequest (d )). Execute ( )
69
71
if err != nil {
70
72
if resp != nil && resp .StatusCode == http .StatusNotFound {
71
73
d .SetId ("" )
@@ -75,20 +77,20 @@ func resourceMongoDBAtlasOrganizationCreate(ctx context.Context, d *schema.Resou
75
77
return diag .FromErr (fmt .Errorf ("error create Organization: %s" , err ))
76
78
}
77
79
78
- if err := d .Set ("private_key" , organization .APIKey . PrivateKey ); err != nil {
80
+ if err := d .Set ("private_key" , organization .ApiKey . GetPrivateKey () ); err != nil {
79
81
return diag .FromErr (fmt .Errorf ("error setting `private_key`: %s" , err ))
80
82
}
81
83
82
- if err := d .Set ("public_key" , organization .APIKey . PublicKey ); err != nil {
84
+ if err := d .Set ("public_key" , organization .ApiKey . GetPublicKey () ); err != nil {
83
85
return diag .FromErr (fmt .Errorf ("error setting `public_key`: %s" , err ))
84
86
}
85
87
86
- if err := d .Set ("org_id" , organization .Organization .ID ); err != nil {
88
+ if err := d .Set ("org_id" , organization .Organization .GetId () ); err != nil {
87
89
return diag .FromErr (fmt .Errorf ("error setting `org_id`: %s" , err ))
88
90
}
89
91
90
92
d .SetId (conversion .EncodeStateID (map [string ]string {
91
- "org_id" : organization .Organization .ID ,
93
+ "org_id" : organization .Organization .GetId () ,
92
94
}))
93
95
94
96
return resourceMongoDBAtlasOrganizationRead (ctx , d , meta )
@@ -103,12 +105,12 @@ func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resourc
103
105
}
104
106
105
107
clients , _ := cfg .NewClient (ctx )
106
- conn := clients .(* config.MongoDBClient ).Atlas
108
+ conn := clients .(* config.MongoDBClient ).AtlasV2
107
109
108
110
ids := conversion .DecodeStateID (d .Id ())
109
111
orgID := ids ["org_id" ]
110
112
111
- organization , resp , err := conn .Organizations . Get (ctx , orgID )
113
+ organization , resp , err := conn .OrganizationsApi . GetOrganization (ctx , orgID ). Execute ( )
112
114
if err != nil {
113
115
if resp != nil && resp .StatusCode == http .StatusNotFound {
114
116
log .Printf ("warning Organization deleted will recreate: %s \n " , err .Error ())
@@ -118,7 +120,7 @@ func resourceMongoDBAtlasOrganizationRead(ctx context.Context, d *schema.Resourc
118
120
return diag .FromErr (fmt .Errorf ("error reading organization information: %s" , err ))
119
121
}
120
122
d .SetId (conversion .EncodeStateID (map [string ]string {
121
- "org_id" : organization .ID ,
123
+ "org_id" : organization .GetId () ,
122
124
}))
123
125
return nil
124
126
}
@@ -132,14 +134,14 @@ func resourceMongoDBAtlasOrganizationUpdate(ctx context.Context, d *schema.Resou
132
134
}
133
135
134
136
clients , _ := cfg .NewClient (ctx )
135
- conn := clients .(* config.MongoDBClient ).Atlas
137
+ conn := clients .(* config.MongoDBClient ).AtlasV2
136
138
ids := conversion .DecodeStateID (d .Id ())
137
139
orgID := ids ["org_id" ]
138
140
139
- updateRequest := new (matlas. Organization )
141
+ updateRequest := new (admin. AtlasOrganization )
140
142
if d .HasChange ("name" ) {
141
143
updateRequest .Name = d .Get ("name" ).(string )
142
- _ , _ , err := conn .Organizations . Update (ctx , orgID , updateRequest )
144
+ _ , _ , err := conn .OrganizationsApi . RenameOrganization (ctx , orgID , updateRequest ). Execute ( )
143
145
if err != nil {
144
146
return diag .FromErr (fmt .Errorf ("error updating Organization: %s" , err ))
145
147
}
@@ -156,28 +158,29 @@ func resourceMongoDBAtlasOrganizationDelete(ctx context.Context, d *schema.Resou
156
158
}
157
159
158
160
clients , _ := cfg .NewClient (ctx )
159
- conn := clients .(* config.MongoDBClient ).Atlas
161
+ conn := clients .(* config.MongoDBClient ).AtlasV2
160
162
ids := conversion .DecodeStateID (d .Id ())
161
163
orgID := ids ["org_id" ]
162
164
163
- if _ , err := conn .Organizations . Delete (ctx , orgID ); err != nil {
165
+ if _ , _ , err := conn .OrganizationsApi . DeleteOrganization (ctx , orgID ). Execute ( ); err != nil {
164
166
return diag .FromErr (fmt .Errorf ("error Organization: %s" , err ))
165
167
}
166
168
return nil
167
169
}
168
170
169
- func newCreateOrganizationRequest (d * schema.ResourceData ) * matlas .CreateOrganizationRequest {
170
- createRequest := & matlas .CreateOrganizationRequest {
171
+ func newCreateOrganizationRequest (d * schema.ResourceData ) * admin .CreateOrganizationRequest {
172
+ createRequest := & admin .CreateOrganizationRequest {
171
173
Name : d .Get ("name" ).(string ),
172
- OrgOwnerID : pointy .String (d .Get ("org_owner_id" ).(string )),
173
- APIKey : & matlas.APIKeyInput {
174
+ OrgOwnerId : pointy .String (d .Get ("org_owner_id" ).(string )),
175
+
176
+ ApiKey : & admin.CreateAtlasOrganizationApiKey {
174
177
Roles : conversion .ExpandStringList (d .Get ("role_names" ).(* schema.Set ).List ()),
175
178
Desc : d .Get ("description" ).(string ),
176
179
},
177
180
}
178
181
179
182
if federationSettingsID , ok := d .Get ("federation_settings_id" ).(string ); ok && federationSettingsID != "" {
180
- createRequest .FederationSettingsID = & federationSettingsID
183
+ createRequest .FederationSettingsId = & federationSettingsID
181
184
}
182
185
183
186
return createRequest
0 commit comments