77 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
88 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
99 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+ "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
1011 "github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
11- matlas "go.mongodb.org/atlas/mongodbatlas "
12+ "go.mongodb.org/atlas-sdk/v20231115012/admin "
1213)
1314
1415func PluralDataSource () * schema.Resource {
@@ -29,10 +30,10 @@ func PluralDataSource() *schema.Resource {
2930}
3031
3132func dataSourceMongoDBAtlasThirdPartyIntegrationsRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
32- conn := meta .(* config.MongoDBClient ).Atlas
33+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
3334
3435 projectID := d .Get ("project_id" ).(string )
35- integrations , _ , err := conn . Integrations . List (ctx , projectID )
36+ integrations , _ , err := connV2 . ThirdPartyIntegrationsApi . ListThirdPartyIntegrations (ctx , projectID ). Execute ( )
3637
3738 if err != nil {
3839 return diag .FromErr (fmt .Errorf ("error getting third party integration list: %s" , err ))
@@ -47,62 +48,62 @@ func dataSourceMongoDBAtlasThirdPartyIntegrationsRead(ctx context.Context, d *sc
4748 return nil
4849}
4950
50- func flattenIntegrations (d * schema.ResourceData , integrations * matlas.ThirdPartyIntegrations , projectID string ) (list []map [string ]any ) {
51- if len (integrations .Results ) == 0 {
51+ func flattenIntegrations (d * schema.ResourceData , integrations * admin.PaginatedIntegration , projectID string ) (list []map [string ]any ) {
52+ results := integrations .GetResults ()
53+ if len (results ) == 0 {
5254 return
5355 }
5456
55- list = make ([]map [string ]any , 0 , len (integrations . Results ))
57+ list = make ([]map [string ]any , 0 , len (results ))
5658
57- for _ , integration := range integrations . Results {
58- service := integrationToSchema (d , integration )
59+ for i := range results {
60+ service := integrationToSchema (d , & results [ i ] )
5961 service ["project_id" ] = projectID
6062 list = append (list , service )
6163 }
6264
6365 return
6466}
6567
66- func integrationToSchema (d * schema.ResourceData , integration * matlas .ThirdPartyIntegration ) map [string ]any {
68+ func integrationToSchema (d * schema.ResourceData , integration * admin .ThirdPartyIntegration ) map [string ]any {
6769 integrationSchema := schemaToIntegration (d )
6870
69- if integrationSchema .APIKey == "" {
70- integrationSchema .APIKey = integration .APIKey
71+ if integrationSchema .ApiKey == nil {
72+ integrationSchema .ApiKey = integration .ApiKey
7173 }
72- if integrationSchema .ServiceKey == "" {
74+ if integrationSchema .ServiceKey == nil {
7375 integrationSchema .ServiceKey = integration .ServiceKey
7476 }
75- if integrationSchema .APIToken == "" {
76- integrationSchema .APIToken = integration .APIToken
77+ if integrationSchema .ApiToken == nil {
78+ integrationSchema .ApiToken = integration .ApiToken
7779 }
78- if integrationSchema .RoutingKey == "" {
80+ if integrationSchema .RoutingKey == nil {
7981 integrationSchema .RoutingKey = integration .RoutingKey
8082 }
81- if integrationSchema .Secret == "" {
83+ if integrationSchema .Secret == nil {
8284 integrationSchema .Secret = integration .Secret
8385 }
84- if integrationSchema .Password == "" {
86+ if integrationSchema .Password == nil {
8587 integrationSchema .Password = integration .Password
8688 }
87- if integrationSchema .URL == "" {
88- integrationSchema .URL = integration .URL
89+ if integrationSchema .Url == nil {
90+ integrationSchema .Url = integration .Url
8991 }
9092
9193 out := map [string ]any {
9294 "type" : integration .Type ,
93- "api_key" : integrationSchema .APIKey ,
95+ "api_key" : integrationSchema .ApiKey ,
9496 "region" : integration .Region ,
9597 "service_key" : integrationSchema .ServiceKey ,
9698 "team_name" : integration .TeamName ,
9799 "channel_name" : integration .ChannelName ,
98100 "routing_key" : integration .RoutingKey ,
99- "url" : integrationSchema .URL ,
101+ "url" : integrationSchema .Url ,
100102 "secret" : integrationSchema .Secret ,
101- "microsoft_teams_webhook_url" : integrationSchema .MicrosoftTeamsWebhookURL ,
102- "user_name" : integration .UserName ,
103+ "microsoft_teams_webhook_url" : integrationSchema .MicrosoftTeamsWebhookUrl ,
104+ "user_name" : integration .Username ,
103105 "password" : integrationSchema .Password ,
104106 "service_discovery" : integration .ServiceDiscovery ,
105- "scheme" : integration .Scheme ,
106107 "enabled" : integration .Enabled ,
107108 }
108109
@@ -112,8 +113,8 @@ func integrationToSchema(d *schema.ResourceData, integration *matlas.ThirdPartyI
112113
113114 for _ , attr := range optionals {
114115 if val , ok := out [attr ]; ok {
115- strval , okT := val .(string )
116- if okT && strval == "" {
116+ stringPtr , okT := val .(* string )
117+ if okT && ! conversion . IsStringPresent ( stringPtr ) {
117118 delete (out , attr )
118119 }
119120 }
@@ -122,124 +123,116 @@ func integrationToSchema(d *schema.ResourceData, integration *matlas.ThirdPartyI
122123 return out
123124}
124125
125- func schemaToIntegration (in * schema.ResourceData ) (out * matlas .ThirdPartyIntegration ) {
126- out = & matlas .ThirdPartyIntegration {}
126+ func schemaToIntegration (in * schema.ResourceData ) (out * admin .ThirdPartyIntegration ) {
127+ out = & admin .ThirdPartyIntegration {}
127128
128129 if _type , ok := in .GetOk ("type" ); ok {
129- out .Type = _type .(string )
130+ out .Type = admin . PtrString ( _type .(string ) )
130131 }
131132
132133 if apiKey , ok := in .GetOk ("api_key" ); ok {
133- out .APIKey = apiKey .(string )
134+ out .ApiKey = admin . PtrString ( apiKey .(string ) )
134135 }
135136
136137 if region , ok := in .GetOk ("region" ); ok {
137- out .Region = region .(string )
138+ out .Region = admin . PtrString ( region .(string ) )
138139 }
139140
140141 if serviceKey , ok := in .GetOk ("service_key" ); ok {
141- out .ServiceKey = serviceKey .(string )
142+ out .ServiceKey = admin . PtrString ( serviceKey .(string ) )
142143 }
143144
144145 if teamName , ok := in .GetOk ("team_name" ); ok {
145- out .TeamName = teamName .(string )
146+ out .TeamName = admin . PtrString ( teamName .(string ) )
146147 }
147148
148149 if channelName , ok := in .GetOk ("channel_name" ); ok {
149- out .ChannelName = channelName .(string )
150+ out .ChannelName = admin . PtrString ( channelName .(string ) )
150151 }
151152
152153 if routingKey , ok := in .GetOk ("routing_key" ); ok {
153- out .RoutingKey = routingKey .(string )
154+ out .RoutingKey = admin . PtrString ( routingKey .(string ) )
154155 }
155156
156157 if url , ok := in .GetOk ("url" ); ok {
157- out .URL = url .(string )
158+ out .Url = admin . PtrString ( url .(string ) )
158159 }
159160
160161 if secret , ok := in .GetOk ("secret" ); ok {
161- out .Secret = secret .(string )
162+ out .Secret = admin . PtrString ( secret .(string ) )
162163 }
163164
164165 if microsoftTeamsWebhookURL , ok := in .GetOk ("microsoft_teams_webhook_url" ); ok {
165- out .MicrosoftTeamsWebhookURL = microsoftTeamsWebhookURL .(string )
166+ out .MicrosoftTeamsWebhookUrl = admin . PtrString ( microsoftTeamsWebhookURL .(string ) )
166167 }
167168
168169 if userName , ok := in .GetOk ("user_name" ); ok {
169- out .UserName = userName .(string )
170+ out .Username = admin . PtrString ( userName .(string ) )
170171 }
171172
172173 if password , ok := in .GetOk ("password" ); ok {
173- out .Password = password .(string )
174+ out .Password = admin . PtrString ( password .(string ) )
174175 }
175176
176177 if serviceDiscovery , ok := in .GetOk ("service_discovery" ); ok {
177- out .ServiceDiscovery = serviceDiscovery .(string )
178- }
179-
180- if scheme , ok := in .GetOk ("scheme" ); ok {
181- out .Scheme = scheme .(string )
178+ out .ServiceDiscovery = admin .PtrString (serviceDiscovery .(string ))
182179 }
183180
184181 if enabled , ok := in .GetOk ("enabled" ); ok {
185- out .Enabled = enabled .(bool )
182+ out .Enabled = admin . PtrBool ( enabled .(bool ) )
186183 }
187184
188185 return out
189186}
190187
191- func updateIntegrationFromSchema (d * schema.ResourceData , integration * matlas .ThirdPartyIntegration ) {
192- integration .APIKey = d .Get ("api_key" ).(string )
188+ func updateIntegrationFromSchema (d * schema.ResourceData , integration * admin .ThirdPartyIntegration ) {
189+ integration .ApiKey = conversion . StringPtr ( d .Get ("api_key" ).(string ) )
193190
194191 if d .HasChange ("region" ) {
195- integration .Region = d .Get ("region" ).(string )
192+ integration .Region = conversion . StringPtr ( d .Get ("region" ).(string ) )
196193 }
197194
198195 if d .HasChange ("service_key" ) {
199- integration .ServiceKey = d .Get ("service_key" ).(string )
196+ integration .ServiceKey = conversion . StringPtr ( d .Get ("service_key" ).(string ) )
200197 }
201198
202199 if d .HasChange ("team_name" ) {
203- integration .TeamName = d .Get ("team_name" ).(string )
200+ integration .TeamName = conversion . StringPtr ( d .Get ("team_name" ).(string ) )
204201 }
205202
206203 if d .HasChange ("channel_name" ) {
207- integration .ChannelName = d .Get ("channel_name" ).(string )
204+ integration .ChannelName = conversion . StringPtr ( d .Get ("channel_name" ).(string ) )
208205 }
209206
210207 if d .HasChange ("routing_key" ) {
211- integration .RoutingKey = d .Get ("routing_key" ).(string )
208+ integration .RoutingKey = conversion . StringPtr ( d .Get ("routing_key" ).(string ) )
212209 }
213210
214211 if d .HasChange ("url" ) {
215- integration .URL = d .Get ("url" ).(string )
212+ integration .Url = conversion . StringPtr ( d .Get ("url" ).(string ) )
216213 }
217214
218215 if d .HasChange ("secret" ) {
219- integration .Secret = d .Get ("secret" ).(string )
216+ integration .Secret = conversion . StringPtr ( d .Get ("secret" ).(string ) )
220217 }
221218
222219 if d .HasChange ("microsoft_teams_webhook_url" ) {
223- integration .MicrosoftTeamsWebhookURL = d .Get ("microsoft_teams_webhook_url" ).(string )
220+ integration .MicrosoftTeamsWebhookUrl = conversion . StringPtr ( d .Get ("microsoft_teams_webhook_url" ).(string ) )
224221 }
225222
226223 if d .HasChange ("user_name" ) {
227- integration .UserName = d .Get ("user_name" ).(string )
224+ integration .Username = conversion . StringPtr ( d .Get ("user_name" ).(string ) )
228225 }
229226
230227 if d .HasChange ("password" ) {
231- integration .Password = d .Get ("password" ).(string )
228+ integration .Password = conversion . StringPtr ( d .Get ("password" ).(string ) )
232229 }
233230
234231 if d .HasChange ("service_discovery" ) {
235- integration .ServiceDiscovery = d .Get ("service_discovery" ).(string )
236- }
237-
238- if d .HasChange ("scheme" ) {
239- integration .Scheme = d .Get ("scheme" ).(string )
232+ integration .ServiceDiscovery = conversion .StringPtr (d .Get ("service_discovery" ).(string ))
240233 }
241234
242235 if d .HasChange ("enabled" ) {
243- integration .Enabled = d .Get ("enabled" ).(bool )
236+ integration .Enabled = admin . PtrBool ( d .Get ("enabled" ).(bool ) )
244237 }
245238}
0 commit comments