@@ -37,7 +37,7 @@ func dataSourceMongoDBAtlasThirdPartyIntegrationsRead(ctx context.Context, d *sc
37
37
return diag .FromErr (fmt .Errorf ("error getting third party integration list: %s" , err ))
38
38
}
39
39
40
- if err = d .Set ("results" , flattenIntegrations (integrations , projectID )); err != nil {
40
+ if err = d .Set ("results" , flattenIntegrations (d , integrations , projectID )); err != nil {
41
41
return diag .FromErr (fmt .Errorf ("error setting results for third party integrations %s" , err ))
42
42
}
43
43
@@ -46,43 +46,75 @@ func dataSourceMongoDBAtlasThirdPartyIntegrationsRead(ctx context.Context, d *sc
46
46
return nil
47
47
}
48
48
49
- func flattenIntegrations (integrations * matlas.ThirdPartyIntegrations , projectID string ) (list []map [string ]interface {}) {
49
+ func flattenIntegrations (d * schema. ResourceData , integrations * matlas.ThirdPartyIntegrations , projectID string ) (list []map [string ]interface {}) {
50
50
if len (integrations .Results ) == 0 {
51
51
return
52
52
}
53
53
54
54
list = make ([]map [string ]interface {}, 0 , len (integrations .Results ))
55
55
56
56
for _ , integration := range integrations .Results {
57
- service := integrationToSchema (integration )
57
+ service := integrationToSchema (d , integration )
58
58
service ["project_id" ] = projectID
59
59
list = append (list , service )
60
60
}
61
61
62
62
return
63
63
}
64
64
65
- func integrationToSchema (integration * matlas.ThirdPartyIntegration ) map [string ]interface {} {
65
+ func integrationToSchema (d * schema.ResourceData , integration * matlas.ThirdPartyIntegration ) map [string ]interface {} {
66
+ integrationSchema := schemaToIntegration (d )
67
+ if integrationSchema .LicenseKey == "" {
68
+ integrationSchema .APIKey = integration .LicenseKey
69
+ }
70
+ if integrationSchema .WriteToken == "" {
71
+ integrationSchema .APIKey = integration .WriteToken
72
+ }
73
+ if integrationSchema .ReadToken == "" {
74
+ integrationSchema .APIKey = integration .ReadToken
75
+ }
76
+ if integrationSchema .APIKey == "" {
77
+ integrationSchema .APIKey = integration .APIKey
78
+ }
79
+ if integrationSchema .ServiceKey == "" {
80
+ integrationSchema .APIKey = integration .ServiceKey
81
+ }
82
+ if integrationSchema .APIToken == "" {
83
+ integrationSchema .APIKey = integration .APIToken
84
+ }
85
+ if integrationSchema .RoutingKey == "" {
86
+ integrationSchema .APIKey = integration .RoutingKey
87
+ }
88
+ if integrationSchema .Secret == "" {
89
+ integrationSchema .APIKey = integration .Secret
90
+ }
91
+ if integrationSchema .Password == "" {
92
+ integrationSchema .APIKey = integration .Password
93
+ }
94
+ if integrationSchema .UserName == "" {
95
+ integrationSchema .APIKey = integration .UserName
96
+ }
97
+
66
98
out := map [string ]interface {}{
67
99
"type" : integration .Type ,
68
- "license_key" : integration .LicenseKey ,
100
+ "license_key" : integrationSchema .LicenseKey ,
69
101
"account_id" : integration .AccountID ,
70
- "write_token" : integration .WriteToken ,
71
- "read_token" : integration .ReadToken ,
72
- "api_key" : integration .APIKey ,
102
+ "write_token" : integrationSchema .WriteToken ,
103
+ "read_token" : integrationSchema .ReadToken ,
104
+ "api_key" : integrationSchema .APIKey ,
73
105
"region" : integration .Region ,
74
- "service_key" : integration .ServiceKey ,
75
- "api_token" : integration .APIToken ,
106
+ "service_key" : integrationSchema .ServiceKey ,
107
+ "api_token" : integrationSchema .APIToken ,
76
108
"team_name" : integration .TeamName ,
77
109
"channel_name" : integration .ChannelName ,
78
- "routing_key" : integration .RoutingKey ,
110
+ "routing_key" : integrationSchema .RoutingKey ,
79
111
"flow_name" : integration .FlowName ,
80
112
"org_name" : integration .OrgName ,
81
113
"url" : integration .URL ,
82
- "secret" : integration .Secret ,
114
+ "secret" : integrationSchema .Secret ,
83
115
"microsoft_teams_webhook_url" : integration .MicrosoftTeamsWebhookURL ,
84
- "user_name" : integration .UserName ,
85
- "password" : integration .Password ,
116
+ "user_name" : integrationSchema .UserName ,
117
+ "password" : integrationSchema .Password ,
86
118
"service_discovery" : integration .ServiceDiscovery ,
87
119
"scheme" : integration .Scheme ,
88
120
"enabled" : integration .Enabled ,
0 commit comments