Skip to content

Commit a68e9e7

Browse files
committed
feat: Adds support for send_collection_latency_metrics and send_database_metrics for Datadog integrations in mongodbatlas_third_party_integration (mongodb#3259)
1 parent a65e05f commit a68e9e7

File tree

9 files changed

+65
-19
lines changed

9 files changed

+65
-19
lines changed

.changelog/3259.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 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ 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 namesand latency metrics on reads, writes, commands, and transactions.
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.
5050
* `send_database_metrics` - Toggle sending database metrics that includes database names and metrics on the number of collections, storage size, and index size.
5151
* `OPS_GENIE`
5252
* `api_key` - Your API Key.

docs/data-sources/third_party_integrations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ 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 namesand latency metrics on reads, writes, commands, and transactions.
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.
6464
* `send_database_metrics` - Toggle sending database metrics that includes database names and metrics on the number of collections, storage size, and index size.
6565
* `OPS_GENIE`
6666
* `api_key` - Your API Key.

docs/resources/third_party_integration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ 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 namesand latency metrics on reads, writes, commands, and transactions. Default: `false`.
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`.
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`.
4848
* `OPS_GENIE`
4949
* `api_key` - Your API Key.
@@ -62,6 +62,8 @@ resource "mongodbatlas_third_party_integration" "test_datadog" {
6262
* `service_discovery` - Indicates which service discovery method is used, either file or http.
6363
* `enabled` - Whether your cluster has Prometheus enabled.
6464

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+
6567
## Attributes Reference
6668

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

examples/mongodbatlas_third_party_integration/datadog/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ variable "cluster_name" {
2626
}
2727

2828
variable "send_collection_latency_metrics" {
29-
description = "Send collection latency metrics"
29+
description = "Send collection latency metrics (only for Datadog integrations)"
3030
default = false
3131
type = bool
3232
}
3333

3434
variable "send_database_metrics" {
35-
description = "Send database metrics"
35+
description = "Send database metrics (only for Datadog integrations)"
3636
default = false
3737
type = bool
3838
}

internal/service/thirdpartyintegration/data_source_third_party_integration.go

Lines changed: 13 additions & 4 deletions
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
"send_collection_latency_metrics": {
105114
Type: schema.TypeBool,

internal/service/thirdpartyintegration/data_source_third_party_integrations.go

Lines changed: 3 additions & 1 deletion
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 {

internal/service/thirdpartyintegration/resource_third_party_integration.go

Lines changed: 1 addition & 0 deletions
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
)

internal/service/thirdpartyintegration/resource_third_party_integration_test.go

Lines changed: 30 additions & 9 deletions
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,7 +179,7 @@ func datadogTest(tb testing.TB) *resource.TestCase {
178179
CheckDestroy: checkDestroy,
179180
Steps: []resource.TestStep{
180181
{
181-
Config: configDatadog(projectID, apiKey, "US", false, false),
182+
Config: configDatadog(projectID, apiKey, "US", false, false, false),
182183
Check: resource.ComposeAggregateTestCheckFunc(
183184
checkExists(resourceName),
184185
resource.TestCheckResourceAttr(resourceName, "type", intType),
@@ -193,18 +194,33 @@ func datadogTest(tb testing.TB) *resource.TestCase {
193194
),
194195
},
195196
{
196-
Config: configDatadog(projectID, updatedAPIKey, "US", false, false),
197+
Config: configDatadog(projectID, apiKey, "US", true, true, false),
198+
Check: resource.ComposeAggregateTestCheckFunc(
199+
checkExists(resourceName),
200+
resource.TestCheckResourceAttr(resourceName, "type", intType),
201+
resource.TestCheckResourceAttr(resourceName, "api_key", apiKey),
202+
resource.TestCheckResourceAttr(resourceName, "region", region),
203+
resource.TestCheckResourceAttr(resourceName, "send_collection_latency_metrics", "true"),
204+
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "false"),
205+
resource.TestCheckResourceAttr(dataSourceName, "type", intType),
206+
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),
197213
Check: resource.ComposeAggregateTestCheckFunc(
198214
checkExists(resourceName),
199215
resource.TestCheckResourceAttr(resourceName, "type", intType),
200216
resource.TestCheckResourceAttr(resourceName, "api_key", updatedAPIKey),
201217
resource.TestCheckResourceAttr(resourceName, "region", region),
202218
resource.TestCheckResourceAttr(resourceName, "send_collection_latency_metrics", "false"),
203-
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "false"),
219+
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "true"),
204220
),
205221
},
206222
{
207-
Config: configDatadog(projectID, updatedAPIKey, "US", true, true),
223+
Config: configDatadog(projectID, updatedAPIKey, "US", true, true, true),
208224
Check: resource.ComposeAggregateTestCheckFunc(
209225
checkExists(resourceName),
210226
resource.TestCheckResourceAttr(resourceName, "type", intType),
@@ -443,23 +459,28 @@ func configVictorOps(projectID, apiKey string) string {
443459
) + singularDataStr
444460
}
445461

446-
func configDatadog(projectID, apiKey, region string, sendCollectionLatencyMetrics, sendDatabaseMetrics bool) 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+
}
447469
return fmt.Sprintf(`
448470
resource "mongodbatlas_third_party_integration" "test" {
449471
project_id = "%[1]s"
450472
type = "%[2]s"
451473
api_key = "%[3]s"
452474
region ="%[4]s"
453-
send_collection_latency_metrics = %[5]t
454-
send_database_metrics = %[6]t
475+
476+
%[5]s
455477
}
456478
`,
457479
projectID,
458480
"DATADOG",
459481
apiKey,
460482
region,
461-
sendCollectionLatencyMetrics,
462-
sendDatabaseMetrics,
483+
optionalConfigAttrs,
463484
) + singularDataStr
464485
}
465486

0 commit comments

Comments
 (0)