Skip to content

Commit 61d9097

Browse files
author
leofigy
authored
Third party integrations datasources (#321)
* new datasource * refactor datasource * 3party integration skeleton functions * 3rd party update, delete and import functions skeletons * setting optional field * adding skeleton functions for testing * default values for test * test for 3rd party integration data source * third party integration resources test * Documentation for datasources * integrations test basic * Third party integrations resources test (#322) * resource test creation & destroy * import testing * update test and clean-up for third-party intg * chore: adding resource documentation * chore: id description * deprecating slack * schema for region * slack note back :)
1 parent dfd7b22 commit 61d9097

10 files changed

+1419
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package mongodbatlas
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
matlas "go.mongodb.org/atlas/mongodbatlas"
9+
)
10+
11+
func dataSourceMongoDBAtlasThirdPartyIntegration() *schema.Resource {
12+
integration := thirdPartyIntegrationSchema()
13+
integration.Schema["project_id"] = &schema.Schema{
14+
Type: schema.TypeString,
15+
Required: true,
16+
}
17+
18+
integration.Schema["type"] = &schema.Schema{
19+
Type: schema.TypeString,
20+
Required: true,
21+
Description: "Third-party service integration identifier",
22+
}
23+
24+
integration.Read = dataSourceMongoDBAtlasThirdPartyIntegrationRead
25+
26+
return integration
27+
}
28+
29+
func thirdPartyIntegrationSchema() *schema.Resource {
30+
return &schema.Resource{
31+
Schema: map[string]*schema.Schema{
32+
"project_id": {
33+
Type: schema.TypeString,
34+
Computed: true,
35+
},
36+
"type": {
37+
Type: schema.TypeString,
38+
Computed: true,
39+
},
40+
"license_key": {
41+
Type: schema.TypeString,
42+
Sensitive: true,
43+
Computed: true,
44+
},
45+
"account_id": {
46+
Type: schema.TypeString,
47+
Computed: true,
48+
},
49+
"write_token": {
50+
Type: schema.TypeString,
51+
Sensitive: true,
52+
Computed: true,
53+
},
54+
"read_token": {
55+
Type: schema.TypeString,
56+
Sensitive: true,
57+
Computed: true,
58+
},
59+
"api_key": {
60+
Type: schema.TypeString,
61+
Sensitive: true,
62+
Computed: true,
63+
},
64+
"region": {
65+
Type: schema.TypeString,
66+
Computed: true,
67+
},
68+
"service_key": {
69+
Type: schema.TypeString,
70+
Sensitive: true,
71+
Computed: true,
72+
},
73+
"api_token": {
74+
Type: schema.TypeString,
75+
Sensitive: true,
76+
Computed: true,
77+
},
78+
"team_name": {
79+
Type: schema.TypeString,
80+
Computed: true,
81+
},
82+
"channel_name": {
83+
Type: schema.TypeString,
84+
Computed: true,
85+
},
86+
"routing_key": {
87+
Type: schema.TypeString,
88+
Sensitive: true,
89+
Computed: true,
90+
},
91+
"flow_name": {
92+
Type: schema.TypeString,
93+
Computed: true,
94+
},
95+
"org_name": {
96+
Type: schema.TypeString,
97+
Computed: true,
98+
},
99+
"url": {
100+
Type: schema.TypeString,
101+
Computed: true,
102+
},
103+
"secret": {
104+
Type: schema.TypeString,
105+
Sensitive: true,
106+
Computed: true,
107+
},
108+
},
109+
}
110+
}
111+
112+
func dataSourceMongoDBAtlasThirdPartyIntegrationRead(d *schema.ResourceData, meta interface{}) error {
113+
projectID := d.Get("project_id").(string)
114+
queryType := d.Get("type").(string)
115+
116+
conn := meta.(*matlas.Client)
117+
118+
integration, _, err := conn.Integrations.Get(context.Background(), projectID, queryType)
119+
120+
if err != nil {
121+
return fmt.Errorf("error getting third party integration for type %s %w", queryType, err)
122+
}
123+
124+
fieldMap := integrationToSchema(integration)
125+
126+
for property, value := range fieldMap {
127+
if err = d.Set(property, value); err != nil {
128+
return fmt.Errorf("error setting %s for third party integration %w", property, err)
129+
}
130+
}
131+
132+
d.SetId(encodeStateID(map[string]string{
133+
"project_id": projectID,
134+
"type": queryType,
135+
}))
136+
137+
return nil
138+
}

0 commit comments

Comments
 (0)