Skip to content

Commit 919a5e0

Browse files
authored
feat: Adds support for send_collection_latency_metrics and send_database_metrics for Datadog integrations in mongodbatlas_third_party_integration (#3259)
1 parent 7d59ab6 commit 919a5e0

File tree

10 files changed

+147
-23
lines changed

10 files changed

+147
-23
lines changed

.changelog/3259.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:enhancement
2+
resource/mongodbatlas_third_party_integration: Adds support for `send_collection_latency_metrics` and `send_database_metrics` for Datadog integrations
3+
```
4+
5+
```release-note:enhancement
6+
data-source/mongodbatlas_third_party_integration: Adds support for `send_collection_latency_metrics` and `send_database_metrics` for Datadog integrations
7+
```
8+
9+
```release-note:enhancement
10+
data-source/mongodbatlas_third_party_integrations: Adds support for `send_collection_latency_metrics` and `send_database_metrics` for Datadog integrations
11+
```

docs/data-sources/third_party_integration.md

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Additional values based on Type
4646
* `DATADOG`
4747
* `api_key` - Your API Key.
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.
49+
* `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.
50+
* `send_database_metrics` - Toggle sending database metrics that includes database names and metrics on the number of collections, storage size, and index size.
4951
* `OPS_GENIE`
5052
* `api_key` - Your API Key.
5153
* `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

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Additional values based on Type
6060
* `DATADOG`
6161
* `api_key` - Your API Key.
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.
63+
* `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.
64+
* `send_database_metrics` - Toggle sending database metrics that includes database names and metrics on the number of collections, storage size, and index size.
6365
* `OPS_GENIE`
6466
* `api_key` - Your API Key.
6567
* `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

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ resource "mongodbatlas_third_party_integration" "test_datadog" {
4343
* `DATADOG`
4444
* `api_key` - Your API Key.
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. Datadog will use "US" by default.
46+
* `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`.
47+
* `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`.
4648
* `OPS_GENIE`
4749
* `api_key` - Your API Key.
4850
* `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. OpsGenie will use "US" by default.
@@ -60,6 +62,8 @@ resource "mongodbatlas_third_party_integration" "test_datadog" {
6062
* `service_discovery` - Indicates which service discovery method is used, either file or http.
6163
* `enabled` - Whether your cluster has Prometheus enabled.
6264

65+
-> **NOTE:** For certain attributes with default values, it's recommended to explicitly set them back to their default instead of removing them from the configuration. For example, if `send_collection_latency_metrics` is set to `true` and you want to revert to the default (`false`), set it to `false` rather than removing it.
66+
6367
## Attributes Reference
6468

6569
* `id` - Unique identifier of the integration.

examples/mongodbatlas_third_party_integration/datadog/integration.tf

+3
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ resource "mongodbatlas_third_party_integration" "test-datadog" {
33
type = "DATADOG"
44
api_key = var.datadog_api_key
55
region = var.datadog_region
6+
7+
send_collection_latency_metrics = var.send_collection_latency_metrics
8+
send_database_metrics = var.send_database_metrics
69
}

examples/mongodbatlas_third_party_integration/datadog/variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ variable "cluster_name" {
2424
default = "datadog-test-cluster"
2525
type = string
2626
}
27+
28+
variable "send_collection_latency_metrics" {
29+
description = "Send collection latency metrics (only for Datadog integrations)"
30+
default = false
31+
type = bool
32+
}
33+
34+
variable "send_database_metrics" {
35+
description = "Send database metrics (only for Datadog integrations)"
36+
default = false
37+
type = bool
38+
}

internal/service/thirdpartyintegration/data_source_third_party_integration.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
910
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
1011
)
1112

@@ -85,21 +86,29 @@ func thirdPartyIntegrationSchema() *schema.Resource {
8586
"microsoft_teams_webhook_url": {
8687
Type: schema.TypeString,
8788
Sensitive: true,
88-
Optional: true,
89+
Computed: true,
8990
},
9091
"user_name": {
9192
Type: schema.TypeString,
9293
Sensitive: true,
93-
Optional: true,
94+
Computed: true,
9495
},
9596
"service_discovery": {
9697
Type: schema.TypeString,
9798
Sensitive: true,
98-
Optional: true,
99+
Computed: true,
99100
},
100101
"enabled": {
101102
Type: schema.TypeBool,
102-
Optional: true,
103+
Computed: true,
104+
},
105+
"send_collection_latency_metrics": {
106+
Type: schema.TypeBool,
107+
Computed: true,
108+
},
109+
"send_database_metrics": {
110+
Type: schema.TypeBool,
111+
Computed: true,
103112
},
104113
},
105114
}

internal/service/thirdpartyintegration/data_source_third_party_integrations.go

+42-16
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"context"
55
"fmt"
66

7+
"go.mongodb.org/atlas-sdk/v20250312002/admin"
8+
79
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12+
1013
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
1114
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
12-
"go.mongodb.org/atlas-sdk/v20250312002/admin"
1315
)
1416

1517
func PluralDataSource() *schema.Resource {
@@ -89,23 +91,31 @@ func integrationToSchema(d *schema.ResourceData, integration *admin.ThirdPartyIn
8991
if integrationSchema.Url == nil {
9092
integrationSchema.Url = integration.Url
9193
}
94+
if integrationSchema.SendCollectionLatencyMetrics == nil {
95+
integrationSchema.SendCollectionLatencyMetrics = integration.SendCollectionLatencyMetrics
96+
}
97+
if integrationSchema.SendDatabaseMetrics == nil {
98+
integrationSchema.SendDatabaseMetrics = integration.SendDatabaseMetrics
99+
}
92100

93101
out := map[string]any{
94-
"id": integration.Id,
95-
"type": integration.Type,
96-
"api_key": integrationSchema.ApiKey,
97-
"region": integration.Region,
98-
"service_key": integrationSchema.ServiceKey,
99-
"team_name": integration.TeamName,
100-
"channel_name": integration.ChannelName,
101-
"routing_key": integration.RoutingKey,
102-
"url": integrationSchema.Url,
103-
"secret": integrationSchema.Secret,
104-
"microsoft_teams_webhook_url": integrationSchema.MicrosoftTeamsWebhookUrl,
105-
"user_name": integration.Username,
106-
"password": integrationSchema.Password,
107-
"service_discovery": integration.ServiceDiscovery,
108-
"enabled": integration.Enabled,
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,
109119
}
110120

111121
// removing optional empty values, terraform complains about unexpected values even though they're empty
@@ -183,6 +193,14 @@ func schemaToIntegration(in *schema.ResourceData) (out *admin.ThirdPartyIntegrat
183193
out.Enabled = admin.PtrBool(enabled.(bool))
184194
}
185195

196+
if sendCollectionLatencyMetrics, ok := in.GetOk("send_collection_latency_metrics"); ok {
197+
out.SendCollectionLatencyMetrics = admin.PtrBool(sendCollectionLatencyMetrics.(bool))
198+
}
199+
200+
if sendDatabaseMetrics, ok := in.GetOk("send_database_metrics"); ok {
201+
out.SendDatabaseMetrics = admin.PtrBool(sendDatabaseMetrics.(bool))
202+
}
203+
186204
return out
187205
}
188206

@@ -236,4 +254,12 @@ func updateIntegrationFromSchema(d *schema.ResourceData, integration *admin.Thir
236254
if d.HasChange("enabled") {
237255
integration.Enabled = admin.PtrBool(d.Get("enabled").(bool))
238256
}
257+
258+
if d.HasChange("send_collection_latency_metrics") {
259+
integration.SendCollectionLatencyMetrics = admin.PtrBool(d.Get("send_collection_latency_metrics").(bool))
260+
}
261+
262+
if d.HasChange("send_database_metrics") {
263+
integration.SendDatabaseMetrics = admin.PtrBool(d.Get("send_database_metrics").(bool))
264+
}
239265
}

internal/service/thirdpartyintegration/resource_third_party_integration.go

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/hashicorp/go-cty/cty"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
1112
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate"
1213
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
1314
)
@@ -129,6 +130,16 @@ func Resource() *schema.Resource {
129130
Computed: true,
130131
Optional: true,
131132
},
133+
"send_collection_latency_metrics": {
134+
Type: schema.TypeBool,
135+
Computed: true,
136+
Optional: true,
137+
},
138+
"send_database_metrics": {
139+
Type: schema.TypeBool,
140+
Computed: true,
141+
Optional: true,
142+
},
132143
},
133144
}
134145
}

internal/service/thirdpartyintegration/resource_third_party_integration_test.go

+47-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
99
"github.com/hashicorp/terraform-plugin-testing/terraform"
10+
1011
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
1112
)
1213

@@ -178,23 +179,57 @@ func datadogTest(tb testing.TB) *resource.TestCase {
178179
CheckDestroy: checkDestroy,
179180
Steps: []resource.TestStep{
180181
{
181-
Config: configDatadog(projectID, apiKey, "US"),
182+
Config: configDatadog(projectID, apiKey, "US", false, false, false),
183+
Check: resource.ComposeAggregateTestCheckFunc(
184+
checkExists(resourceName),
185+
resource.TestCheckResourceAttr(resourceName, "type", intType),
186+
resource.TestCheckResourceAttr(resourceName, "api_key", apiKey),
187+
resource.TestCheckResourceAttr(resourceName, "region", region),
188+
resource.TestCheckResourceAttr(resourceName, "send_collection_latency_metrics", "false"),
189+
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "false"),
190+
resource.TestCheckResourceAttr(dataSourceName, "type", intType),
191+
resource.TestCheckResourceAttr(dataSourceName, "region", region),
192+
resource.TestCheckResourceAttr(dataSourceName, "send_collection_latency_metrics", "false"),
193+
resource.TestCheckResourceAttr(dataSourceName, "send_database_metrics", "false"),
194+
),
195+
},
196+
{
197+
Config: configDatadog(projectID, apiKey, "US", true, true, false),
182198
Check: resource.ComposeAggregateTestCheckFunc(
183199
checkExists(resourceName),
184200
resource.TestCheckResourceAttr(resourceName, "type", intType),
185201
resource.TestCheckResourceAttr(resourceName, "api_key", apiKey),
186202
resource.TestCheckResourceAttr(resourceName, "region", region),
203+
resource.TestCheckResourceAttr(resourceName, "send_collection_latency_metrics", "true"),
204+
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "false"),
187205
resource.TestCheckResourceAttr(dataSourceName, "type", intType),
188206
resource.TestCheckResourceAttr(dataSourceName, "region", region),
207+
resource.TestCheckResourceAttr(dataSourceName, "send_collection_latency_metrics", "true"),
208+
resource.TestCheckResourceAttr(dataSourceName, "send_database_metrics", "false"),
209+
),
210+
},
211+
{
212+
Config: configDatadog(projectID, updatedAPIKey, "US", true, false, true),
213+
Check: resource.ComposeAggregateTestCheckFunc(
214+
checkExists(resourceName),
215+
resource.TestCheckResourceAttr(resourceName, "type", intType),
216+
resource.TestCheckResourceAttr(resourceName, "api_key", updatedAPIKey),
217+
resource.TestCheckResourceAttr(resourceName, "region", region),
218+
resource.TestCheckResourceAttr(resourceName, "send_collection_latency_metrics", "false"),
219+
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "true"),
189220
),
190221
},
191222
{
192-
Config: configDatadog(projectID, updatedAPIKey, "US"),
223+
Config: configDatadog(projectID, updatedAPIKey, "US", true, true, true),
193224
Check: resource.ComposeAggregateTestCheckFunc(
194225
checkExists(resourceName),
195226
resource.TestCheckResourceAttr(resourceName, "type", intType),
196227
resource.TestCheckResourceAttr(resourceName, "api_key", updatedAPIKey),
197228
resource.TestCheckResourceAttr(resourceName, "region", region),
229+
resource.TestCheckResourceAttr(resourceName, "send_collection_latency_metrics", "true"),
230+
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "true"),
231+
resource.TestCheckResourceAttr(dataSourceName, "send_collection_latency_metrics", "true"),
232+
resource.TestCheckResourceAttr(dataSourceName, "send_database_metrics", "true"),
198233
),
199234
},
200235
importStep(resourceName),
@@ -424,19 +459,28 @@ func configVictorOps(projectID, apiKey string) string {
424459
) + singularDataStr
425460
}
426461

427-
func configDatadog(projectID, apiKey, region string) string {
462+
func configDatadog(projectID, apiKey, region string, useOptionalAttr, sendCollectionLatencyMetrics, sendDatabaseMetrics bool) string {
463+
optionalConfigAttrs := ""
464+
if useOptionalAttr {
465+
optionalConfigAttrs = fmt.Sprintf(
466+
`send_collection_latency_metrics = %[1]t
467+
send_database_metrics = %[2]t`, sendCollectionLatencyMetrics, sendDatabaseMetrics)
468+
}
428469
return fmt.Sprintf(`
429470
resource "mongodbatlas_third_party_integration" "test" {
430471
project_id = "%[1]s"
431472
type = "%[2]s"
432473
api_key = "%[3]s"
433474
region ="%[4]s"
475+
476+
%[5]s
434477
}
435478
`,
436479
projectID,
437480
"DATADOG",
438481
apiKey,
439482
region,
483+
optionalConfigAttrs,
440484
) + singularDataStr
441485
}
442486

0 commit comments

Comments
 (0)