Skip to content

Commit 5ba242c

Browse files
authored
feat: Adds send_user_provided_resource_tags attribute for mongodbatlas_third_party_integration (#3454)
* add send_user_provided_resource_tags * changelog * fmt * docs and example * test * refactor * rename files * new line
1 parent 764b788 commit 5ba242c

File tree

12 files changed

+131
-81
lines changed

12 files changed

+131
-81
lines changed

.changelog/3454.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:enhancement
2+
resource/mongodbatlas_third_party_integration Adds `send_user_provided_resource_tags` attribute to support sending $querystats to DataDog
3+
```
4+
5+
```release-note:enhancement
6+
data-source/mongodbatlas_third_party_integration Adds `send_user_provided_resource_tags` attribute to support sending $querystats to DataDog
7+
```
8+
9+
```release-note:enhancement
10+
data-source/mongodbatlas_third_party_integrations Adds `send_user_provided_resource_tags` attribute to support sending $querystats to DataDog
11+
```

docs/data-sources/third_party_integration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Additional values based on Type
4848
* `region` - Two-letter code that indicates which API URL to use. See the `region` response field of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/getThirdPartyIntegration) for more details. Datadog will use "US" by default.
4949
* `send_collection_latency_metrics` - Toggle sending collection latency metrics that includes database names and collection name sand latency metrics on reads, writes, commands, and transactions.
5050
* `send_database_metrics` - Toggle sending database metrics that includes database names and metrics on the number of collections, storage size, and index size.
51+
* `send_user_provided_resource_tags` - Toggle sending user provided group and cluster resource tags with the datadog metrics.
5152
* `OPS_GENIE`
5253
* `api_key` - Your API Key.
5354
* `region` - Two-letter code that indicates which API URL to use. See the `region` response field of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/getThirdPartyIntegration) for more details. Opsgenie will use US by default.

docs/data-sources/third_party_integrations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Additional values based on Type
6262
* `region` - Two-letter code that indicates which API URL to use. See the `region` response field of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/getThirdPartyIntegration) for more details. Datadog will use "US" by default.
6363
* `send_collection_latency_metrics` - Toggle sending collection latency metrics that includes database names and collection names and latency metrics on reads, writes, commands, and transactions.
6464
* `send_database_metrics` - Toggle sending database metrics that includes database names and metrics on the number of collections, storage size, and index size.
65+
* `send_user_provided_resource_tags` - Toggle sending user provided group and cluster resource tags with the datadog metrics.
6566
* `OPS_GENIE`
6667
* `api_key` - Your API Key.
6768
* `region` - Two-letter code that indicates which API URL to use. See the `region` response field of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/getThirdPartyIntegration) for more details. Opsgenie will use US by default.

docs/resources/third_party_integration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ resource "mongodbatlas_third_party_integration" "test_datadog" {
4545
* `region` (Required) - Two-letter code that indicates which API URL to use. See the `region` request parameter of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/createThirdPartyIntegration) for more details.
4646
* `send_collection_latency_metrics` - Toggle sending collection latency metrics that includes database names and collection names and latency metrics on reads, writes, commands, and transactions. Default: `false`.
4747
* `send_database_metrics` - Toggle sending database metrics that includes database names and metrics on the number of collections, storage size, and index size. Default: `false`.
48+
* `send_user_provided_resource_tags` - Toggle sending user provided group and cluster resource tags with the datadog metrics. Default: `false`.
4849
* `OPS_GENIE`
4950
* `api_key` - Your API Key.
5051
* `region` (Required) - Two-letter code that indicates which API URL to use. See the `region` request parameter of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/createThirdPartyIntegration) for more details.

examples/mongodbatlas_third_party_integration/datadog/integration.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ resource "mongodbatlas_third_party_integration" "test-datadog" {
44
api_key = var.datadog_api_key
55
region = var.datadog_region
66

7-
send_collection_latency_metrics = var.send_collection_latency_metrics
8-
send_database_metrics = var.send_database_metrics
7+
send_collection_latency_metrics = var.send_collection_latency_metrics
8+
send_database_metrics = var.send_database_metrics
9+
send_user_provided_resource_tags = var.send_user_provided_resource_tags
910
}

examples/mongodbatlas_third_party_integration/datadog/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ variable "send_database_metrics" {
3636
default = false
3737
type = bool
3838
}
39+
40+
variable "send_user_provided_resource_tags" {
41+
description = "Send user provided resource tags (only for Datadog integrations)"
42+
default = false
43+
type = bool
44+
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func DataSource() *schema.Resource {
2323
Description: "Third-party service integration identifier",
2424
}
2525

26-
integration.ReadContext = dataSourceMongoDBAtlasThirdPartyIntegrationRead
26+
integration.ReadContext = dataSourceRead
2727

2828
return integration
2929
}
@@ -110,11 +110,15 @@ func thirdPartyIntegrationSchema() *schema.Resource {
110110
Type: schema.TypeBool,
111111
Computed: true,
112112
},
113+
"send_user_provided_resource_tags": {
114+
Type: schema.TypeBool,
115+
Computed: true,
116+
},
113117
},
114118
}
115119
}
116120

117-
func dataSourceMongoDBAtlasThirdPartyIntegrationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
121+
func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
118122
projectID := d.Get("project_id").(string)
119123
queryType := d.Get("type").(string)
120124

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,13 @@
11
package thirdpartyintegration
22

33
import (
4-
"context"
5-
"fmt"
6-
74
"go.mongodb.org/atlas-sdk/v20250312005/admin"
85

9-
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
116
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
127

138
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
14-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
159
)
1610

17-
func PluralDataSource() *schema.Resource {
18-
return &schema.Resource{
19-
ReadContext: dataSourceMongoDBAtlasThirdPartyIntegrationsRead,
20-
Schema: map[string]*schema.Schema{
21-
"project_id": {
22-
Type: schema.TypeString,
23-
Required: true,
24-
},
25-
"results": {
26-
Type: schema.TypeList,
27-
Computed: true,
28-
Elem: thirdPartyIntegrationSchema(),
29-
},
30-
},
31-
}
32-
}
33-
34-
func dataSourceMongoDBAtlasThirdPartyIntegrationsRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
35-
connV2 := meta.(*config.MongoDBClient).AtlasV2
36-
37-
projectID := d.Get("project_id").(string)
38-
integrations, _, err := connV2.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(ctx, projectID).Execute()
39-
40-
if err != nil {
41-
return diag.FromErr(fmt.Errorf("error getting third party integration list: %s", err))
42-
}
43-
44-
if err = d.Set("results", flattenIntegrations(d, integrations, projectID)); err != nil {
45-
return diag.FromErr(fmt.Errorf("error setting results for third party integrations %s", err))
46-
}
47-
48-
d.SetId(id.UniqueId())
49-
50-
return nil
51-
}
52-
5311
func flattenIntegrations(d *schema.ResourceData, integrations *admin.PaginatedIntegration, projectID string) (list []map[string]any) {
5412
results := integrations.GetResults()
5513
if len(results) == 0 {
@@ -99,23 +57,24 @@ func integrationToSchema(d *schema.ResourceData, integration *admin.ThirdPartyIn
9957
}
10058

10159
out := map[string]any{
102-
"id": integration.Id,
103-
"type": integration.Type,
104-
"api_key": integrationSchema.ApiKey,
105-
"region": integration.Region,
106-
"service_key": integrationSchema.ServiceKey,
107-
"team_name": integration.TeamName,
108-
"channel_name": integration.ChannelName,
109-
"routing_key": integration.RoutingKey,
110-
"url": integrationSchema.Url,
111-
"secret": integrationSchema.Secret,
112-
"microsoft_teams_webhook_url": integrationSchema.MicrosoftTeamsWebhookUrl,
113-
"user_name": integration.Username,
114-
"password": integrationSchema.Password,
115-
"service_discovery": integration.ServiceDiscovery,
116-
"enabled": integration.Enabled,
117-
"send_collection_latency_metrics": integration.SendCollectionLatencyMetrics,
118-
"send_database_metrics": integration.SendDatabaseMetrics,
60+
"id": integration.Id,
61+
"type": integration.Type,
62+
"api_key": integrationSchema.ApiKey,
63+
"region": integration.Region,
64+
"service_key": integrationSchema.ServiceKey,
65+
"team_name": integration.TeamName,
66+
"channel_name": integration.ChannelName,
67+
"routing_key": integration.RoutingKey,
68+
"url": integrationSchema.Url,
69+
"secret": integrationSchema.Secret,
70+
"microsoft_teams_webhook_url": integrationSchema.MicrosoftTeamsWebhookUrl,
71+
"user_name": integration.Username,
72+
"password": integrationSchema.Password,
73+
"service_discovery": integration.ServiceDiscovery,
74+
"enabled": integration.Enabled,
75+
"send_collection_latency_metrics": integration.SendCollectionLatencyMetrics,
76+
"send_database_metrics": integration.SendDatabaseMetrics,
77+
"send_user_provided_resource_tags": integration.SendUserProvidedResourceTags,
11978
}
12079

12180
// removing optional empty values, terraform complains about unexpected values even though they're empty
@@ -201,6 +160,10 @@ func schemaToIntegration(in *schema.ResourceData) (out *admin.ThirdPartyIntegrat
201160
out.SendDatabaseMetrics = admin.PtrBool(sendDatabaseMetrics.(bool))
202161
}
203162

163+
if sendUserProvidedResourceTags, ok := in.GetOk("send_user_provided_resource_tags"); ok {
164+
out.SendUserProvidedResourceTags = admin.PtrBool(sendUserProvidedResourceTags.(bool))
165+
}
166+
204167
return out
205168
}
206169

@@ -262,4 +225,8 @@ func updateIntegrationFromSchema(d *schema.ResourceData, integration *admin.Thir
262225
if d.HasChange("send_database_metrics") {
263226
integration.SendDatabaseMetrics = admin.PtrBool(d.Get("send_database_metrics").(bool))
264227
}
228+
229+
if d.HasChange("send_user_provided_resource_tags") {
230+
integration.SendUserProvidedResourceTags = admin.PtrBool(d.Get("send_user_provided_resource_tags").(bool))
231+
}
265232
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package thirdpartyintegration
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
11+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
12+
)
13+
14+
func PluralDataSource() *schema.Resource {
15+
return &schema.Resource{
16+
ReadContext: pluralDataSourceRead,
17+
Schema: map[string]*schema.Schema{
18+
"project_id": {
19+
Type: schema.TypeString,
20+
Required: true,
21+
},
22+
"results": {
23+
Type: schema.TypeList,
24+
Computed: true,
25+
Elem: thirdPartyIntegrationSchema(),
26+
},
27+
},
28+
}
29+
}
30+
31+
func pluralDataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
32+
connV2 := meta.(*config.MongoDBClient).AtlasV2
33+
34+
projectID := d.Get("project_id").(string)
35+
integrations, _, err := connV2.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(ctx, projectID).Execute()
36+
37+
if err != nil {
38+
return diag.FromErr(fmt.Errorf("error getting third party integration list: %s", err))
39+
}
40+
41+
if err = d.Set("results", flattenIntegrations(d, integrations, projectID)); err != nil {
42+
return diag.FromErr(fmt.Errorf("error setting results for third party integrations %s", err))
43+
}
44+
45+
d.SetId(id.UniqueId())
46+
47+
return nil
48+
}

internal/service/thirdpartyintegration/resource_third_party_integration.go renamed to internal/service/thirdpartyintegration/resource.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ var requiredPerType = map[string][]string{
3535

3636
func Resource() *schema.Resource {
3737
return &schema.Resource{
38-
CreateContext: resourceMongoDBAtlasThirdPartyIntegrationCreate,
39-
ReadContext: resourceMongoDBAtlasThirdPartyIntegrationRead,
40-
UpdateContext: resourceMongoDBAtlasThirdPartyIntegrationUpdate,
41-
DeleteContext: resourceMongoDBAtlasThirdPartyIntegrationDelete,
38+
CreateContext: resourceCreate,
39+
ReadContext: resourceRead,
40+
UpdateContext: resourceUpdate,
41+
DeleteContext: resourceDelete,
4242
Importer: &schema.ResourceImporter{
43-
StateContext: resourceMongoDBAtlasThirdPartyIntegrationImportState,
43+
StateContext: resourceImportState,
4444
},
4545
Schema: map[string]*schema.Schema{
4646
"id": {
@@ -140,11 +140,16 @@ func Resource() *schema.Resource {
140140
Computed: true,
141141
Optional: true,
142142
},
143+
"send_user_provided_resource_tags": {
144+
Type: schema.TypeBool,
145+
Computed: true,
146+
Optional: true,
147+
},
143148
},
144149
}
145150
}
146151

147-
func resourceMongoDBAtlasThirdPartyIntegrationCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
152+
func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
148153
connV2 := meta.(*config.MongoDBClient).AtlasV2
149154
projectID := d.Get("project_id").(string)
150155
integrationType := d.Get("type").(string)
@@ -168,10 +173,10 @@ func resourceMongoDBAtlasThirdPartyIntegrationCreate(ctx context.Context, d *sch
168173
return diag.FromErr(fmt.Errorf("error creating third party integration %s", err))
169174
}
170175

171-
return resourceMongoDBAtlasThirdPartyIntegrationRead(ctx, d, meta)
176+
return resourceRead(ctx, d, meta)
172177
}
173178

174-
func resourceMongoDBAtlasThirdPartyIntegrationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
179+
func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
175180
connV2 := meta.(*config.MongoDBClient).AtlasV2
176181

177182
projectID := d.Get("project_id").(string)
@@ -199,7 +204,7 @@ func resourceMongoDBAtlasThirdPartyIntegrationRead(ctx context.Context, d *schem
199204
return nil
200205
}
201206

202-
func resourceMongoDBAtlasThirdPartyIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
207+
func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
203208
connV2 := meta.(*config.MongoDBClient).AtlasV2
204209

205210
projectID := d.Get("project_id").(string)
@@ -221,10 +226,10 @@ func resourceMongoDBAtlasThirdPartyIntegrationUpdate(ctx context.Context, d *sch
221226
return diag.FromErr(fmt.Errorf("error updating third party integration type `%s` (%s): %w", integrationType, d.Id(), err))
222227
}
223228

224-
return resourceMongoDBAtlasThirdPartyIntegrationRead(ctx, d, meta)
229+
return resourceRead(ctx, d, meta)
225230
}
226231

227-
func resourceMongoDBAtlasThirdPartyIntegrationDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
232+
func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
228233
conn := meta.(*config.MongoDBClient).Atlas
229234

230235
projectID := d.Get("project_id").(string)
@@ -239,7 +244,7 @@ func resourceMongoDBAtlasThirdPartyIntegrationDelete(ctx context.Context, d *sch
239244
return nil
240245
}
241246

242-
func resourceMongoDBAtlasThirdPartyIntegrationImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) {
247+
func resourceImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) {
243248
connV2 := meta.(*config.MongoDBClient).AtlasV2
244249

245250
projectID, integrationType, err := splitIntegrationTypeID(d.Id())

0 commit comments

Comments
 (0)