Skip to content

Commit 60b4bca

Browse files
coderGo93Edgar López
andauthored
INTMDB-142: Fixes the bug for alertconfiguration using data dog (#366)
* fix: changed the name of struct for datadog api key * test: added testacc for data dog aler configuration Co-authored-by: Edgar López <[email protected]>
1 parent 99bbd23 commit 60b4bca

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

mongodbatlas/resource_mongodbatlas_alert_configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ func flattenAlertConfigurationNotifications(notifications []matlas.Notification)
593593
nts[i] = map[string]interface{}{
594594
"api_token": notifications[i].APIToken,
595595
"channel_name": notifications[i].ChannelName,
596-
"datadog_api_key": notifications[i].DatadogRegion,
596+
"datadog_api_key": notifications[i].DatadogAPIKey,
597597
"datadog_region": notifications[i].DatadogRegion,
598598
"delay_min": notifications[i].DelayMin,
599599
"email_address": notifications[i].EmailAddress,

mongodbatlas/resource_mongodbatlas_alert_configuration_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,33 @@ func TestAccResourceMongoDBAtlasAlertConfiguration_importConfigNotifications(t *
261261
})
262262
}
263263

264+
func TestAccResourceMongoDBAtlasAlertConfiguration_DataDog(t *testing.T) {
265+
SkipTestExtCred(t) // Will skip because requires external credentials aka api key
266+
SkipTest(t) // Will force skip if enabled
267+
var (
268+
resourceName = "mongodbatlas_alert_configuration.test"
269+
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
270+
ddAPIKey = os.Getenv("DD_API_KEY")
271+
ddRegion = "US"
272+
alert = &matlas.AlertConfiguration{}
273+
)
274+
275+
resource.Test(t, resource.TestCase{
276+
PreCheck: func() { testAccPreCheck(t) },
277+
Providers: testAccProviders,
278+
CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy,
279+
Steps: []resource.TestStep{
280+
{
281+
Config: testAccMongoDBAtlasAlertConfigurationConfigWithDataDog(projectID, ddAPIKey, ddRegion, true),
282+
Check: resource.ComposeTestCheckFunc(
283+
testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert),
284+
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
285+
),
286+
},
287+
},
288+
})
289+
}
290+
264291
func testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName string, alert *matlas.AlertConfiguration) resource.TestCheckFunc {
265292
return func(s *terraform.State) error {
266293
conn := testAccProvider.Meta().(*matlas.Client)
@@ -505,3 +532,49 @@ func testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(projectID s
505532
}
506533
`, projectID, enabled, threshold)
507534
}
535+
536+
func testAccMongoDBAtlasAlertConfigurationConfigWithDataDog(projectID, dataDogAPIKey, dataDogRegion string, enabled bool) string {
537+
return fmt.Sprintf(`
538+
resource "mongodbatlas_third_party_integration" "atlas_datadog" {
539+
project_id = "%[1]s"
540+
type = "DATADOG"
541+
api_key = "%[3]s"
542+
region = "%[4]s"
543+
}
544+
545+
resource "mongodbatlas_alert_configuration" "test" {
546+
project_id = "%[1]s"
547+
event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT"
548+
enabled = %t
549+
550+
notification {
551+
type_name = "GROUP"
552+
interval_min = 5
553+
delay_min = 0
554+
sms_enabled = false
555+
email_enabled = true
556+
roles = ["GROUP_OWNER"]
557+
}
558+
559+
notification {
560+
type_name = "DATADOG"
561+
datadog_api_key = mongodbatlas_third_party_integration.atlas_datadog.api_key
562+
datadog_region = mongodbatlas_third_party_integration.atlas_datadog.region
563+
interval_min = 5
564+
delay_min = 0
565+
}
566+
567+
matcher {
568+
field_name = "HOSTNAME_AND_PORT"
569+
operator = "EQUALS"
570+
value = "SECONDARY"
571+
}
572+
573+
threshold = {
574+
operator = "LESS_THAN"
575+
threshold = 72
576+
units = "HOURS"
577+
}
578+
}
579+
`, projectID, enabled, dataDogAPIKey, dataDogRegion)
580+
}

0 commit comments

Comments
 (0)