From 1dbe9887142418401795b8aee332f3e2b8245bc8 Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Mon, 9 Oct 2023 12:41:01 +0200 Subject: [PATCH 01/10] fix: alert configuration data source nil pointer with third party notifications --- ..._data_source_mongodbatlas_alert_configuration_test.go | 3 +-- .../fw_resource_mongodbatlas_alert_configuration.go | 9 +++++---- mongodbatlas/util/type_conversion.go | 9 +++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go b/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go index 152986c307..d0c119bf51 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go @@ -102,12 +102,11 @@ func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) { } func TestAccConfigDSAlertConfiguration_withPagerDuty(t *testing.T) { - SkipTestExtCred(t) // Will skip because requires external credentials aka api key var ( alert = &matlas.AlertConfiguration{} dataSourceName = "data.mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - serviceKey = os.Getenv("PAGER_DUTY_SERVICE_KEY") + serviceKey = "dummykey111111111111111111111111" ) resource.Test(t, resource.TestCase{ diff --git a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go index 6680e3b133..816a3326d1 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go +++ b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/framework/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/util" "github.com/mwielbut/pointy" "go.mongodb.org/atlas-sdk/v20230201006/admin" matlas "go.mongodb.org/atlas/mongodbatlas" @@ -744,9 +745,9 @@ func newTFNotificationModelListV2(n []admin.AlertsNotificationRootForGroup, curr Roles: value.Roles, ChannelName: conversion.StringPtrNullIfEmpty(value.ChannelName), DatadogRegion: conversion.StringPtrNullIfEmpty(value.DatadogRegion), - DelayMin: types.Int64Value(int64(*value.DelayMin)), + DelayMin: types.Int64PointerValue(util.IntPtrToInt64Ptr(value.DelayMin)), EmailAddress: conversion.StringPtrNullIfEmpty(value.EmailAddress), - IntervalMin: types.Int64Value(int64(*value.IntervalMin)), + IntervalMin: types.Int64PointerValue(util.IntPtrToInt64Ptr(value.IntervalMin)), MobileNumber: conversion.StringPtrNullIfEmpty(value.MobileNumber), OpsGenieRegion: conversion.StringPtrNullIfEmpty(value.OpsGenieRegion), TeamID: conversion.StringPtrNullIfEmpty(value.TeamId), @@ -804,8 +805,8 @@ func newTFNotificationModelListV2(n []admin.AlertsNotificationRootForGroup, curr newState.Username = conversion.StringPtrNullIfEmpty(value.Username) } - newState.IntervalMin = types.Int64Value(int64(*value.IntervalMin)) - newState.DelayMin = types.Int64Value(int64(*value.DelayMin)) + newState.IntervalMin = types.Int64PointerValue(util.IntPtrToInt64Ptr(value.IntervalMin)) + newState.DelayMin = types.Int64PointerValue(util.IntPtrToInt64Ptr(value.DelayMin)) newState.EmailEnabled = types.BoolValue(value.EmailEnabled != nil && *value.EmailEnabled) newState.SMSEnabled = types.BoolValue(value.SmsEnabled != nil && *value.SmsEnabled) diff --git a/mongodbatlas/util/type_conversion.go b/mongodbatlas/util/type_conversion.go index 273e5bf876..1690e5ffa4 100644 --- a/mongodbatlas/util/type_conversion.go +++ b/mongodbatlas/util/type_conversion.go @@ -28,6 +28,15 @@ func Int64PtrToIntPtr(i64 *int64) *int { return &i } +func IntPtrToInt64Ptr(i *int) *int64 { + if i == nil { + return nil + } + + i64 := int64(*i) + return &i64 +} + // IsStringPresent returns true if the string is non-empty. func IsStringPresent(strPtr *string) bool { return strPtr != nil && len(*strPtr) > 0 From 0a0e735ecc28561673619ef0cafd5138ae5c3a6a Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Fri, 6 Oct 2023 16:54:14 +0200 Subject: [PATCH 02/10] modify all third party notifications to use fake credentials so acceptance tests are run in CI --- ...urce_mongodbatlas_alert_configuration_test.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go index 26bf3926b4..73b975a7b1 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go @@ -366,11 +366,10 @@ func TestAccConfigRSAlertConfiguration_importConfigNotifications(t *testing.T) { // used for testing notification that does not define interval_min attribute func TestAccConfigRSAlertConfiguration_importPagerDuty(t *testing.T) { - SkipTestExtCred(t) // Will skip because requires external credentials aka api key var ( resourceName = "mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - serviceKey = os.Getenv("PAGER_DUTY_SERVICE_KEY") + serviceKey = "dummykey111111111111111111111111" alert = &matlas.AlertConfiguration{} ) @@ -398,12 +397,10 @@ func TestAccConfigRSAlertConfiguration_importPagerDuty(t *testing.T) { } func TestAccConfigRSAlertConfiguration_DataDog(t *testing.T) { - SkipTestExtCred(t) // Will skip because requires external credentials aka api key - SkipTest(t) // Will force skip if enabled var ( resourceName = "mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - ddAPIKey = os.Getenv("DD_API_KEY") + ddAPIKey = "11111111111111111111111111111111" ddRegion = "US" alert = &matlas.AlertConfiguration{} ) @@ -425,11 +422,10 @@ func TestAccConfigRSAlertConfiguration_DataDog(t *testing.T) { } func TestAccConfigRSAlertConfiguration_PagerDuty(t *testing.T) { - SkipTestExtCred(t) // Will skip because requires external credentials aka api key var ( resourceName = "mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - serviceKey = os.Getenv("PAGER_DUTY_SERVICE_KEY") + serviceKey = "dummykey111111111111111111111111" alert = &matlas.AlertConfiguration{} ) @@ -450,11 +446,10 @@ func TestAccConfigRSAlertConfiguration_PagerDuty(t *testing.T) { } func TestAccConfigRSAlertConfiguration_OpsGenie(t *testing.T) { - SkipTestExtCred(t) // Will skip because requires external credentials aka api key var ( resourceName = "mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - apiKey = os.Getenv("OPS_GENIE_API_KEY") + apiKey = "11111111-1111-1111-1111-111111111111" alert = &matlas.AlertConfiguration{} ) @@ -475,11 +470,10 @@ func TestAccConfigRSAlertConfiguration_OpsGenie(t *testing.T) { } func TestAccConfigRSAlertConfiguration_VictorOps(t *testing.T) { - SkipTestExtCred(t) // Will skip because requires external credentials aka api key var ( resourceName = "mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - apiKey = os.Getenv("VICTOR_OPS_API_KEY") + apiKey = "11111111-1111-1111-1111-111111111111" alert = &matlas.AlertConfiguration{} ) From 18815e6a262fbf8cee2b12055296fb3e91cfbee8 Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Mon, 9 Oct 2023 15:29:06 +0200 Subject: [PATCH 03/10] extract dummy keys to common variables --- ...source_mongodbatlas_alert_configuration_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go index 73b975a7b1..f00201d228 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go @@ -364,12 +364,16 @@ func TestAccConfigRSAlertConfiguration_importConfigNotifications(t *testing.T) { }) } +// dummy keys used for credential values in third party notifications +const dummy32CharKey = "11111111111111111111111111111111" +const dummy36CharKey = "11111111-1111-1111-1111-111111111111" + // used for testing notification that does not define interval_min attribute func TestAccConfigRSAlertConfiguration_importPagerDuty(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - serviceKey = "dummykey111111111111111111111111" + serviceKey = dummy32CharKey alert = &matlas.AlertConfiguration{} ) @@ -400,7 +404,7 @@ func TestAccConfigRSAlertConfiguration_DataDog(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - ddAPIKey = "11111111111111111111111111111111" + ddAPIKey = dummy32CharKey ddRegion = "US" alert = &matlas.AlertConfiguration{} ) @@ -425,7 +429,7 @@ func TestAccConfigRSAlertConfiguration_PagerDuty(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - serviceKey = "dummykey111111111111111111111111" + serviceKey = dummy32CharKey alert = &matlas.AlertConfiguration{} ) @@ -449,7 +453,7 @@ func TestAccConfigRSAlertConfiguration_OpsGenie(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - apiKey = "11111111-1111-1111-1111-111111111111" + apiKey = dummy36CharKey alert = &matlas.AlertConfiguration{} ) @@ -473,7 +477,7 @@ func TestAccConfigRSAlertConfiguration_VictorOps(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - apiKey = "11111111-1111-1111-1111-111111111111" + apiKey = dummy36CharKey alert = &matlas.AlertConfiguration{} ) From 74093aadd70f0c15ed2ffd27970fad13ddd36006 Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Mon, 9 Oct 2023 16:17:20 +0200 Subject: [PATCH 04/10] remove usage of project id env variable in third party alert configuration tests --- ...e_mongodbatlas_alert_configuration_test.go | 23 +++-- ...e_mongodbatlas_alert_configuration_test.go | 93 ++++++++++++------- 2 files changed, 71 insertions(+), 45 deletions(-) diff --git a/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go b/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go index d0c119bf51..0760755fb0 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go @@ -105,17 +105,18 @@ func TestAccConfigDSAlertConfiguration_withPagerDuty(t *testing.T) { var ( alert = &matlas.AlertConfiguration{} dataSourceName = "data.mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - serviceKey = "dummykey111111111111111111111111" + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") + serviceKey = dummy32CharKey ) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProtoV6ProviderFactories: testAccProviderV6Factories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccDSMongoDBAtlasAlertConfigurationConfigWithPagerDuty(projectID, serviceKey, true), + Config: testAccDSMongoDBAtlasAlertConfigurationConfigWithPagerDuty(orgID, projectName, serviceKey, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(dataSourceName, alert), resource.TestCheckResourceAttrSet(dataSourceName, "project_id"), @@ -244,16 +245,20 @@ func testAccDSMongoDBAtlasAlertConfigurationWithOutputs(orgID, projectName, outp `, orgID, projectName, outputLabel) } -func testAccDSMongoDBAtlasAlertConfigurationConfigWithPagerDuty(projectID, serviceKey string, enabled bool) string { +func testAccDSMongoDBAtlasAlertConfigurationConfigWithPagerDuty(orgID, projectName, serviceKey string, enabled bool) string { return fmt.Sprintf(` +resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q +} resource "mongodbatlas_alert_configuration" "test" { - project_id = %[1]q + project_id = mongodbatlas_project.test.id event_type = "NO_PRIMARY" - enabled = "%[3]t" + enabled = "%[4]t" notification { type_name = "PAGER_DUTY" - service_key = %[2]q + service_key = %[3]q delay_min = 0 } } @@ -262,5 +267,5 @@ data "mongodbatlas_alert_configuration" "test" { project_id = "${mongodbatlas_alert_configuration.test.project_id}" alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}" } - `, projectID, serviceKey, enabled) + `, orgID, projectName, serviceKey, enabled) } diff --git a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go index f00201d228..754f85f5f4 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go @@ -372,7 +372,8 @@ const dummy36CharKey = "11111111-1111-1111-1111-111111111111" func TestAccConfigRSAlertConfiguration_importPagerDuty(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") serviceKey = dummy32CharKey alert = &matlas.AlertConfiguration{} ) @@ -383,7 +384,7 @@ func TestAccConfigRSAlertConfiguration_importPagerDuty(t *testing.T) { CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationPagerDutyConfig(projectID, serviceKey, true), + Config: testAccMongoDBAtlasAlertConfigurationPagerDutyConfig(orgID, projectName, serviceKey, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -403,19 +404,20 @@ func TestAccConfigRSAlertConfiguration_importPagerDuty(t *testing.T) { func TestAccConfigRSAlertConfiguration_DataDog(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") ddAPIKey = dummy32CharKey ddRegion = "US" alert = &matlas.AlertConfiguration{} ) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProtoV6ProviderFactories: testAccProviderV6Factories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationConfigWithDataDog(projectID, ddAPIKey, ddRegion, true), + Config: testAccMongoDBAtlasAlertConfigurationConfigWithDataDog(orgID, projectName, ddAPIKey, ddRegion, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -428,18 +430,19 @@ func TestAccConfigRSAlertConfiguration_DataDog(t *testing.T) { func TestAccConfigRSAlertConfiguration_PagerDuty(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") serviceKey = dummy32CharKey alert = &matlas.AlertConfiguration{} ) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProtoV6ProviderFactories: testAccProviderV6Factories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationPagerDutyConfig(projectID, serviceKey, true), + Config: testAccMongoDBAtlasAlertConfigurationPagerDutyConfig(orgID, projectName, serviceKey, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -452,18 +455,19 @@ func TestAccConfigRSAlertConfiguration_PagerDuty(t *testing.T) { func TestAccConfigRSAlertConfiguration_OpsGenie(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") apiKey = dummy36CharKey alert = &matlas.AlertConfiguration{} ) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProtoV6ProviderFactories: testAccProviderV6Factories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationOpsGenieConfig(projectID, apiKey, true), + Config: testAccMongoDBAtlasAlertConfigurationOpsGenieConfig(orgID, projectName, apiKey, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -476,18 +480,19 @@ func TestAccConfigRSAlertConfiguration_OpsGenie(t *testing.T) { func TestAccConfigRSAlertConfiguration_VictorOps(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") apiKey = dummy36CharKey alert = &matlas.AlertConfiguration{} ) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheckBasic(t) }, ProtoV6ProviderFactories: testAccProviderV6Factories, CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasAlertConfigurationVictorOpsConfig(projectID, apiKey, true), + Config: testAccMongoDBAtlasAlertConfigurationVictorOpsConfig(orgID, projectName, apiKey, true), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), resource.TestCheckResourceAttrSet(resourceName, "project_id"), @@ -775,19 +780,23 @@ func testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(orgID, proj `, orgID, projectName, enabled, threshold) } -func testAccMongoDBAtlasAlertConfigurationConfigWithDataDog(projectID, dataDogAPIKey, dataDogRegion string, enabled bool) string { +func testAccMongoDBAtlasAlertConfigurationConfigWithDataDog(orgID, projectName, dataDogAPIKey, dataDogRegion string, enabled bool) string { return fmt.Sprintf(` +resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q +} resource "mongodbatlas_third_party_integration" "atlas_datadog" { - project_id = "%[1]s" + project_id = mongodbatlas_project.test.id type = "DATADOG" - api_key = "%[3]s" - region = "%[4]s" + api_key = "%[4]s" + region = "%[5]s" } resource "mongodbatlas_alert_configuration" "test" { - project_id = "%[1]s" + project_id = mongodbatlas_project.test.id event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT" - enabled = %t + enabled = %[3]t notification { type_name = "GROUP" @@ -818,57 +827,69 @@ resource "mongodbatlas_alert_configuration" "test" { units = "HOURS" } } - `, projectID, enabled, dataDogAPIKey, dataDogRegion) + `, orgID, projectName, enabled, dataDogAPIKey, dataDogRegion) } -func testAccMongoDBAtlasAlertConfigurationPagerDutyConfig(projectID, serviceKey string, enabled bool) string { +func testAccMongoDBAtlasAlertConfigurationPagerDutyConfig(orgID, projectName, serviceKey string, enabled bool) string { return fmt.Sprintf(` +resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q +} resource "mongodbatlas_alert_configuration" "test" { - project_id = %[1]q + project_id = mongodbatlas_project.test.id event_type = "NO_PRIMARY" - enabled = "%[3]t" + enabled = "%[4]t" notification { type_name = "PAGER_DUTY" - service_key = %[2]q + service_key = %[3]q delay_min = 0 } } - `, projectID, serviceKey, enabled) + `, orgID, projectName, serviceKey, enabled) } -func testAccMongoDBAtlasAlertConfigurationOpsGenieConfig(projectID, apiKey string, enabled bool) string { +func testAccMongoDBAtlasAlertConfigurationOpsGenieConfig(orgID, projectName, apiKey string, enabled bool) string { return fmt.Sprintf(` +resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q +} resource "mongodbatlas_alert_configuration" "test" { - project_id = %[1]q + project_id = mongodbatlas_project.test.id event_type = "NO_PRIMARY" - enabled = "%[3]t" + enabled = "%[4]t" notification { type_name = "OPS_GENIE" - ops_genie_api_key = %[2]q + ops_genie_api_key = %[3]q ops_genie_region = "US" delay_min = 0 } } - `, projectID, apiKey, enabled) + `, orgID, projectName, apiKey, enabled) } -func testAccMongoDBAtlasAlertConfigurationVictorOpsConfig(projectID, apiKey string, enabled bool) string { +func testAccMongoDBAtlasAlertConfigurationVictorOpsConfig(orgID, projectName, apiKey string, enabled bool) string { return fmt.Sprintf(` +resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q +} resource "mongodbatlas_alert_configuration" "test" { - project_id = %[1]q + project_id = mongodbatlas_project.test.id event_type = "NO_PRIMARY" - enabled = "%[3]t" + enabled = "%[4]t" notification { type_name = "VICTOR_OPS" - victor_ops_api_key = %[2]q + victor_ops_api_key = %[3]q victor_ops_routing_key = "testing" delay_min = 0 } } - `, projectID, apiKey, enabled) + `, orgID, projectName, apiKey, enabled) } func testAccMongoDBAtlasAlertConfigurationConfigEmptyMetricThresholdConfig(orgID, projectName string, enabled bool) string { From 9086b7f90bf9c02df243235225a7a5b17bcf6bfe Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Fri, 6 Oct 2023 16:36:59 +0200 Subject: [PATCH 05/10] feat: supports new notifier_id attribute in alert configuration notifications --- examples/atlas-alert-configurations/README.md | 2 + ...source_mongodbatlas_alert_configuration.go | 7 +++ ...e_mongodbatlas_alert_configuration_test.go | 1 + ...source_mongodbatlas_alert_configuration.go | 10 +++ ...e_mongodbatlas_alert_configuration_test.go | 61 +++++++++++++++++++ .../docs/d/alert_configuration.html.markdown | 1 + .../docs/r/alert_configuration.html.markdown | 3 + 7 files changed, 85 insertions(+) diff --git a/examples/atlas-alert-configurations/README.md b/examples/atlas-alert-configurations/README.md index 06c53ac86c..7fea8356d3 100644 --- a/examples/atlas-alert-configurations/README.md +++ b/examples/atlas-alert-configurations/README.md @@ -14,6 +14,8 @@ chmod +x ./import-alerts.sh terraform apply ``` +**NOTE**: Third-party notifications will not contain their respective credentials as these are sensitive attributes. If you wish to perform updates on these notifications without providing the original credentials the corresponding `notifier_id` attribute must be provided instead. + ## Contingency Plans If unhappy with the resource file or imports, here are some things that can be done: diff --git a/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration.go b/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration.go index b998150eec..0d500ae3ac 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration.go @@ -201,6 +201,9 @@ var alertConfigDSSchemaAttributes = map[string]schema.Attribute{ "team_name": schema.StringAttribute{ Computed: true, }, + "notifier_id": schema.StringAttribute{ + Computed: true, + }, "type_name": schema.StringAttribute{ Computed: true, }, @@ -428,6 +431,10 @@ func convertNotificationToCtyValues(notification *admin.AlertsNotificationRootFo values["team_name"] = cty.StringVal(*notification.TeamName) } + if util.IsStringPresent(notification.NotifierId) { + values["notifier_id"] = cty.StringVal(*notification.NotifierId) + } + if util.IsStringPresent(notification.TypeName) { values["type_name"] = cty.StringVal(*notification.TypeName) } diff --git a/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go b/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go index 0760755fb0..dba879e3c9 100644 --- a/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/fw_data_source_mongodbatlas_alert_configuration_test.go @@ -30,6 +30,7 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) { testAccCheckMongoDBAtlasAlertConfigurationExists(dataSourceName, alert), resource.TestCheckResourceAttrSet(dataSourceName, "project_id"), resource.TestCheckResourceAttr(dataSourceName, "notification.#", "1"), + resource.TestCheckResourceAttrSet(dataSourceName, "notification.0.notifier_id"), resource.TestCheckResourceAttr(dataSourceName, "matcher.#", "1"), resource.TestCheckResourceAttr(dataSourceName, "metric_threshold_config.#", "1"), resource.TestCheckResourceAttr(dataSourceName, "threshold_config.#", "0"), diff --git a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go index 816a3326d1..18a486bc05 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go +++ b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration.go @@ -103,6 +103,7 @@ type tfNotificationModel struct { OpsGenieAPIKey types.String `tfsdk:"ops_genie_api_key"` TeamID types.String `tfsdk:"team_id"` TeamName types.String `tfsdk:"team_name"` + NotifierID types.String `tfsdk:"notifier_id"` TypeName types.String `tfsdk:"type_name"` ChannelName types.String `tfsdk:"channel_name"` VictorOpsAPIKey types.String `tfsdk:"victor_ops_api_key"` @@ -322,6 +323,10 @@ func (r *AlertConfigurationRS) Schema(ctx context.Context, req resource.SchemaRe stringplanmodifier.UseStateForUnknown(), }, }, + "notifier_id": schema.StringAttribute{ + Computed: true, + Optional: true, + }, "type_name": schema.StringAttribute{ Required: true, Validators: []validator.String{ @@ -581,6 +586,7 @@ func newNotificationList(tfNotificationSlice []tfNotificationModel) ([]matlas.No ServiceKey: value.ServiceKey.ValueString(), SMSEnabled: value.SMSEnabled.ValueBoolPointer(), TeamID: value.TeamID.ValueString(), + NotifierID: value.NotifierID.ValueString(), TypeName: value.TypeName.ValueString(), Username: value.Username.ValueString(), VictorOpsAPIKey: value.VictorOpsAPIKey.ValueString(), @@ -671,6 +677,7 @@ func newTFNotificationModelList(matlasSlice []matlas.Notification, currStateNoti TeamID: conversion.StringNullIfEmpty(value.TeamID), TypeName: conversion.StringNullIfEmpty(value.TypeName), Username: conversion.StringNullIfEmpty(value.Username), + NotifierID: types.StringValue(value.NotifierID), EmailEnabled: types.BoolValue(value.EmailEnabled != nil && *value.EmailEnabled), SMSEnabled: types.BoolValue(value.SMSEnabled != nil && *value.SMSEnabled), } @@ -723,6 +730,7 @@ func newTFNotificationModelList(matlasSlice []matlas.Notification, currStateNoti newState.Username = conversion.StringNullIfEmpty(value.Username) } + newState.NotifierID = types.StringValue(value.NotifierID) newState.IntervalMin = types.Int64Value(int64(value.IntervalMin)) newState.DelayMin = types.Int64Value(int64(*value.DelayMin)) newState.EmailEnabled = types.BoolValue(value.EmailEnabled != nil && *value.EmailEnabled) @@ -751,6 +759,7 @@ func newTFNotificationModelListV2(n []admin.AlertsNotificationRootForGroup, curr MobileNumber: conversion.StringPtrNullIfEmpty(value.MobileNumber), OpsGenieRegion: conversion.StringPtrNullIfEmpty(value.OpsGenieRegion), TeamID: conversion.StringPtrNullIfEmpty(value.TeamId), + NotifierID: types.StringPointerValue(value.NotifierId), TypeName: conversion.StringPtrNullIfEmpty(value.TypeName), Username: conversion.StringPtrNullIfEmpty(value.Username), EmailEnabled: types.BoolValue(value.EmailEnabled != nil && *value.EmailEnabled), @@ -805,6 +814,7 @@ func newTFNotificationModelListV2(n []admin.AlertsNotificationRootForGroup, curr newState.Username = conversion.StringPtrNullIfEmpty(value.Username) } + newState.NotifierID = types.StringPointerValue(value.NotifierId) newState.IntervalMin = types.Int64PointerValue(util.IntPtrToInt64Ptr(value.IntervalMin)) newState.DelayMin = types.Int64PointerValue(util.IntPtrToInt64Ptr(value.DelayMin)) newState.EmailEnabled = types.BoolValue(value.EmailEnabled != nil && *value.EmailEnabled) diff --git a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go index 754f85f5f4..18f676589e 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go @@ -401,6 +401,42 @@ func TestAccConfigRSAlertConfiguration_importPagerDuty(t *testing.T) { }) } +func TestAccConfigRSAlertConfiguration_UpdatePagerDutyWithNotifierId(t *testing.T) { + var ( + resourceName = "mongodbatlas_alert_configuration.test" + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") + serviceKey = dummy32CharKey + notifierID = "651dd9336afac13e1c112222" + alert = &matlas.AlertConfiguration{} + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, + ProtoV6ProviderFactories: testAccProviderV6Factories, + CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMongoDBAtlasAlertConfigurationPagerDutyNotifierIDConfig(orgID, projectName, notifierID, 10, &serviceKey), + Check: resource.ComposeTestCheckFunc( + testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), + resource.TestCheckResourceAttrSet(resourceName, "project_id"), + resource.TestCheckResourceAttr(resourceName, "notification.0.delay_min", "10"), + resource.TestCheckResourceAttr(resourceName, "notification.0.service_key", serviceKey), + ), + }, + { + Config: testAccMongoDBAtlasAlertConfigurationPagerDutyNotifierIDConfig(orgID, projectName, notifierID, 15, nil), + Check: resource.ComposeTestCheckFunc( + testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert), + resource.TestCheckResourceAttrSet(resourceName, "project_id"), + resource.TestCheckResourceAttr(resourceName, "notification.0.delay_min", "15"), + ), + }, + }, + }) +} + func TestAccConfigRSAlertConfiguration_DataDog(t *testing.T) { var ( resourceName = "mongodbatlas_alert_configuration.test" @@ -850,6 +886,31 @@ resource "mongodbatlas_alert_configuration" "test" { `, orgID, projectName, serviceKey, enabled) } +func testAccMongoDBAtlasAlertConfigurationPagerDutyNotifierIDConfig(orgID, projectName, notifierID string, delayMin int, serviceKey *string) string { + var serviceKeyString string + if serviceKey != nil { + serviceKeyString = fmt.Sprintf(`service_key = %q`, *serviceKey) + } + return fmt.Sprintf(` +resource "mongodbatlas_project" "test" { + name = %[2]q + org_id = %[1]q +} +resource "mongodbatlas_alert_configuration" "test" { + project_id = mongodbatlas_project.test.id + event_type = "NO_PRIMARY" + enabled = "true" + + notification { + type_name = "PAGER_DUTY" + notifier_id = %[3]q + %[4]s + delay_min = %[5]d + } +} + `, orgID, projectName, notifierID, serviceKeyString, delayMin) +} + func testAccMongoDBAtlasAlertConfigurationOpsGenieConfig(orgID, projectName, apiKey string, enabled bool) string { return fmt.Sprintf(` resource "mongodbatlas_project" "test" { diff --git a/website/docs/d/alert_configuration.html.markdown b/website/docs/d/alert_configuration.html.markdown index 752c6d31be..dc11e42f42 100644 --- a/website/docs/d/alert_configuration.html.markdown +++ b/website/docs/d/alert_configuration.html.markdown @@ -226,6 +226,7 @@ Notifications to send when an alert condition is detected. - `WEBHOOK` - `MICROSOFT_TEAMS` +* `notifier_id` - The notifier id is a system-generated unique identifier assigned to each notification method. This is needed when updating third-party notifications without requiring explicit authentication credentials. * `username` - Name of the Atlas user to which to send notifications. Only a user in the project that owns the alert configuration is allowed here. Required for the `USER` notifications type. * `victor_ops_api_key` - VictorOps API key. Required for the `VICTOR_OPS` notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key. * `victor_ops_routing_key` - VictorOps routing key. Optional for the `VICTOR_OPS` notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key. diff --git a/website/docs/r/alert_configuration.html.markdown b/website/docs/r/alert_configuration.html.markdown index 19b98701ff..8d0f6df545 100644 --- a/website/docs/r/alert_configuration.html.markdown +++ b/website/docs/r/alert_configuration.html.markdown @@ -226,6 +226,7 @@ List of notifications to send when an alert condition is detected. - `WEBHOOK` - `MICROSOFT_TEAMS` +* `notifier_id` - The notifier id is a system-generated unique identifier assigned to each notification method. This is needed when updating third-party notifications without requiring explicit authentication credentials. * `username` - Name of the Atlas user to which to send notifications. Only a user in the project that owns the alert configuration is allowed here. Required for the `USER` notifications type. * `victor_ops_api_key` - VictorOps API key. Required for the `VICTOR_OPS` notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key. * `victor_ops_routing_key` - VictorOps routing key. Optional for the `VICTOR_OPS` notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key. @@ -263,4 +264,6 @@ Alert Configuration can be imported using the `project_id-alert_configuration_id $ terraform import mongodbatlas_alert_configuration.test 5d0f1f74cf09a29120e123cd-5d0f1f74cf09a29120e1fscg ``` +**NOTE**: Third-party notifications will not contain their respective credentials as these are sensitive attributes. If you wish to perform updates on these notifications without providing the original credentials the corresponding `notifier_id` attribute must be provided instead. + For more information see: [MongoDB Atlas API Reference.](https://docs.atlas.mongodb.com/reference/api/alert-configurations/) From ead727acea8539cce1ca6a80ecc519bb48dbafba Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Mon, 9 Oct 2023 17:23:44 +0200 Subject: [PATCH 06/10] temprary change to use atlas go sdk version with changes --- go.mod | 2 +- go.sum | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 23a12ba852..3984031147 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/mwielbut/pointy v1.1.0 github.com/spf13/cast v1.5.1 github.com/zclconf/go-cty v1.14.0 - go.mongodb.org/atlas v0.33.0 + go.mongodb.org/atlas v0.33.1-0.20231004211218-011ec2beab4c go.mongodb.org/atlas-sdk/v20230201006 v20230201006.0.0 go.mongodb.org/realm v0.1.0 golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 diff --git a/go.sum b/go.sum index c3aa49476c..b36def31dd 100644 --- a/go.sum +++ b/go.sum @@ -647,6 +647,7 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= @@ -723,6 +724,8 @@ github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgK go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M= go.mongodb.org/atlas v0.33.0 h1:qJhkEuJufh7sVDVHorTF/D7G7naQ1EJAzqf1aV29JWs= go.mongodb.org/atlas v0.33.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg= +go.mongodb.org/atlas v0.33.1-0.20231004211218-011ec2beab4c h1:cEkC2k68XRkA4YWKsr2gLi6E7aPbPBDOwto5fmCcXVE= +go.mongodb.org/atlas v0.33.1-0.20231004211218-011ec2beab4c/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg= go.mongodb.org/atlas-sdk/v20230201006 v20230201006.0.0 h1:HaY0cmYAlqoC+7iRE0NTPEQyAr2nqdxE9gspMp8Pmyo= go.mongodb.org/atlas-sdk/v20230201006 v20230201006.0.0/go.mod h1:Lgqhl8h8m0iqTloSypmqt/Vi8ZIGvx3tXFuu07HPUyk= go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M= From 175b13c9498e79e5647be2c8e4dd05792016e6b5 Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Wed, 11 Oct 2023 15:26:44 +0200 Subject: [PATCH 07/10] docs: align documentation of alert config singular data source with plural data source --- .../docs/d/alert_configuration.html.markdown | 11 +- .../docs/d/alert_configurations.html.markdown | 121 +++++++++++++++++- .../docs/r/alert_configuration.html.markdown | 3 +- 3 files changed, 126 insertions(+), 9 deletions(-) diff --git a/website/docs/d/alert_configuration.html.markdown b/website/docs/d/alert_configuration.html.markdown index dc11e42f42..6135dc90e6 100644 --- a/website/docs/d/alert_configuration.html.markdown +++ b/website/docs/d/alert_configuration.html.markdown @@ -121,8 +121,12 @@ In addition to all arguments above, the following attributes are exported: * `updated` - Timestamp in ISO 8601 date and time format in UTC when this alert configuration was last updated. * `enabled` - If set to true, the alert configuration is enabled. If enabled is not exported it is set to false. * `event_type` - The type of event that will trigger an alert. +* `matcher` - Rules to apply when matching an object against this alert configuration. See [matchers](#matchers). +* `metric_threshold_config` - The threshold that causes an alert to be triggered. Required if `event_type_name` : `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD`. See [metric threshold config](#metric-threshold-config). +* `threshold_config` - Threshold that triggers an alert. Required if `event_type_name` is any value other than `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD`. See [threshold config](#threshold-config). +* `notifications` - List of notifications to send when an alert condition is detected. See [notifications](#notifications). - -> ***IMPORTANT:*** Event Type has many possible values. All current options at available at https://docs.atlas.mongodb.com/reference/api/alert-configurations-create-config/ Details for both conditional and metric based alerts can be found by selecting the tabs on the [alert config page](https://docs.atlas.mongodb.com/reference/api/alert-configurations-create-config/) and checking the latest eventTypeName options. + -> ***IMPORTANT:*** Event Type has many possible values. Details for both conditional and metric based alerts can be found by selecting the tabs on the [alert config page](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Alert-Configurations/operation/createAlertConfiguration) and checking the latest eventTypeName options. -> **NOTE:** If `event_type` is set to `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD`, the `metric_threshold_config` field must also be configured. @@ -163,7 +167,7 @@ Rules to apply when matching an object against this alert configuration. Only en - `CONFIG` - `MONGOS` -### Metric Threshold Config (`metric_threshold_config`) +### Metric Threshold Config The threshold that causes an alert to be triggered. Required if `event_type_name` : `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD`. * `metric_name` - Name of the metric to check. The full list being quite large, please refer to atlas docs [here for general metrics](https://docs.atlas.mongodb.com/reference/alert-host-metrics/#measurement-types) and [here for serverless metrics](https://www.mongodb.com/docs/atlas/reference/api/alert-configurations-create-config/#serverless-measurements) @@ -178,7 +182,7 @@ The threshold that causes an alert to be triggered. Required if `event_type_name Refer to the [MongoDB API Alert Configuration documentation](https://www.mongodb.com/docs/atlas/reference/api/alert-configurations-get-config/#request-body-parameters) for a list of accepted values. * `mode` - This must be set to AVERAGE. Atlas computes the current metric value as an average. -### Threshold Config (`threshold_config`) +### Threshold Config * `operator` - Operator to apply when checking the current metric value against the threshold value. Accepted values are: - `GREATER_THAN` @@ -233,7 +237,6 @@ Notifications to send when an alert condition is detected. * `webhook_secret` - Authentication secret for the `WEBHOOK` notifications type. * `webhook_url` - Target URL for the `WEBHOOK` notifications type. * `microsoft_teams_webhook_url` - Microsoft Teams channel incoming webhook URL. Required for the `MICROSOFT_TEAMS` notifications type. - * `roles` - Atlas role in current Project or Organization. Atlas returns this value if you set `type_name` to `ORG` or `GROUP`. See detailed information for arguments and attributes: [MongoDB API Alert Configuration](https://docs.atlas.mongodb.com/reference/api/alert-configurations-get-config/) \ No newline at end of file diff --git a/website/docs/d/alert_configurations.html.markdown b/website/docs/d/alert_configurations.html.markdown index 4a903d7ceb..bd9bc4fa2a 100644 --- a/website/docs/d/alert_configurations.html.markdown +++ b/website/docs/d/alert_configurations.html.markdown @@ -64,11 +64,124 @@ In addition to all arguments above, the following attributes are exported: * `updated` - Timestamp in ISO 8601 date and time format in UTC when this alert configuration was last updated. * `enabled` - If set to true, the alert configuration is enabled. If enabled is not exported it is set to false. * `event_type` - The type of event that will trigger an alert. -* `matcher` - Rules to apply when matching an object against this alert configuration -* `metric_threshold_config` - The threshold that causes an alert to be triggered. Required if `event_type_name` : `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD` -* `threshold_config` - Threshold that triggers an alert. Required if `event_type_name` is any value other than `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD`. -* `notifications` - List of notifications to send when an alert condition is detected. +* `matcher` - Rules to apply when matching an object against this alert configuration. See [matchers](#matchers). +* `metric_threshold_config` - The threshold that causes an alert to be triggered. Required if `event_type_name` : `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD`. See [metric threshold config](#metric-threshold-config). +* `threshold_config` - Threshold that triggers an alert. Required if `event_type_name` is any value other than `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD`. See [threshold config](#threshold-config). +* `notifications` - List of notifications to send when an alert condition is detected. See [notifications](#notifications). * `output` - Requested output string format for the alert configuration + -> ***IMPORTANT:*** Event Type has many possible values. Details for both conditional and metric based alerts can be found by selecting the tabs on the [alert config page](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Alert-Configurations/operation/createAlertConfiguration) and checking the latest eventTypeName options. + + -> **NOTE:** If `event_type` is set to `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD`, the `metric_threshold_config` field must also be configured. + +### Matchers +Rules to apply when matching an object against this alert configuration. Only entities that match all these rules are checked for an alert condition. You can filter using the matchers array only when the eventTypeName specifies an event for a host, replica set, or sharded cluster. + +* `field_name` - Name of the field in the target object to match on. + +| Host alerts | Replica set alerts | Sharded cluster alerts | +|:-------------- |:------------- |:------ | +| `TYPE_NAME` | `REPLICA_SET_NAME` | `CLUSTER_NAME` | +| `HOSTNAME` | `SHARD_NAME` | `SHARD_NAME` | +| `PORT` | `CLUSTER_NAME` | | +| `HOSTNAME_AND_PORT` | | | +| `REPLICA_SET_NAME` | | | + + + All other types of alerts do not support matchers. + +* `operator` - If omitted, the configuration is disabled. +* `value` - If omitted, the configuration is disabled. + + +* `operator` - The operator to test the field’s value. + Accepted values are: + - `EQUALS` + - `NOT_EQUALS` + - `CONTAINS` + - `NOT_CONTAINS` + - `STARTS_WITH` + - `ENDS_WITH` + - `REGEX` + +* `value` - Value to test with the specified operator. If `field_name` is set to TYPE_NAME, you can match on the following values: + - `PRIMARY` + - `SECONDARY` + - `STANDALONE` + - `CONFIG` + - `MONGOS` + +### Metric Threshold Config +The threshold that causes an alert to be triggered. Required if `event_type_name` : `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD`. + +* `metric_name` - Name of the metric to check. The full list being quite large, please refer to atlas docs [here for general metrics](https://docs.atlas.mongodb.com/reference/alert-host-metrics/#measurement-types) and [here for serverless metrics](https://www.mongodb.com/docs/atlas/reference/api/alert-configurations-create-config/#serverless-measurements) + +* `operator` - Operator to apply when checking the current metric value against the threshold value. + Accepted values are: + - `GREATER_THAN` + - `LESS_THAN` + +* `threshold` - Threshold value outside of which an alert will be triggered. +* `units` - The units for the threshold value. Depends on the type of metric. + Refer to the [MongoDB API Alert Configuration documentation](https://www.mongodb.com/docs/atlas/reference/api/alert-configurations-get-config/#request-body-parameters) for a list of accepted values. +* `mode` - This must be set to AVERAGE. Atlas computes the current metric value as an average. + +### Threshold Config +* `operator` - Operator to apply when checking the current metric value against the threshold value. + Accepted values are: + - `GREATER_THAN` + - `LESS_THAN` + +* `threshold` - Threshold value outside of which an alert will be triggered. +* `units` - The units for the threshold value. Depends on the type of metric. + Refer to the [MongoDB API Alert Configuration documentation](https://www.mongodb.com/docs/atlas/reference/api/alert-configurations-get-config/#request-body-parameters) for a list of accepted values. + +### Notifications +Notifications to send when an alert condition is detected. + +* `api_token` - Slack API token. Required for the SLACK notifications type. If the token later becomes invalid, Atlas sends an email to the project owner and eventually removes the token. +* `channel_name` - Slack channel name. Required for the SLACK notifications type. +* `datadog_api_key` - Datadog API Key. Found in the Datadog dashboard. Required for the DATADOG notifications type. +* `datadog_region` - Region that indicates which API URL to use. Accepted regions are: `US`, `EU`. The default Datadog region is US. +* `delay_min` - Number of minutes to wait after an alert condition is detected before sending out the first notification. +* `email_address` - Email address to which alert notifications are sent. Required for the EMAIL notifications type. +* `email_enabled` - Flag indicating email notifications should be sent. Atlas returns this value if `type_name` is set to `ORG`, `GROUP`, or `USER`. +* `flowdock_api_token` - The Flowdock personal API token. Required for the `FLOWDOCK` notifications type. If the token later becomes invalid, Atlas sends an email to the project owner and eventually removes the token. +* `flow_name` - Flowdock flow name in lower-case letters. Required for the `FLOWDOCK` notifications type +* `interval_min` - Number of minutes to wait between successive notifications for unacknowledged alerts that are not resolved. The minimum value is 5. +* `mobile_number` - Mobile number to which alert notifications are sent. Required for the SMS notifications type. +* `ops_genie_api_key` - Opsgenie API Key. Required for the `OPS_GENIE` notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the token. +* `ops_genie_region` - Region that indicates which API URL to use. Accepted regions are: `US` ,`EU`. The default Opsgenie region is US. +* `org_name` - Flowdock organization name in lower-case letters. This is the name that appears after www.flowdock.com/app/ in the URL string. Required for the FLOWDOCK notifications type. +* `service_key` - PagerDuty service key. Required for the PAGER_DUTY notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key. +* `sms_enabled` - Flag indicating text notifications should be sent. Atlas returns this value if `type_name` is set to `ORG`, `GROUP`, or `USER`. +* `team_id` - Unique identifier of a team. +* `team_name` - Label for the team that receives this notification. +* `type_name` - Type of alert notification. + Accepted values are: + - `DATADOG` + - `EMAIL` + - `FLOWDOCK` + - `GROUP` (Project) + - `OPS_GENIE` + - `ORG` + - `PAGER_DUTY` + - `SLACK` + - `SMS` + - `TEAM` + - `USER` + - `VICTOR_OPS` + - `WEBHOOK` + - `MICROSOFT_TEAMS` + +* `notifier_id` - The notifier id is a system-generated unique identifier assigned to each notification method. This is needed when updating third-party notifications without requiring explicit authentication credentials. +* `username` - Name of the Atlas user to which to send notifications. Only a user in the project that owns the alert configuration is allowed here. Required for the `USER` notifications type. +* `victor_ops_api_key` - VictorOps API key. Required for the `VICTOR_OPS` notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key. +* `victor_ops_routing_key` - VictorOps routing key. Optional for the `VICTOR_OPS` notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key. +* `webhook_secret` - Authentication secret for the `WEBHOOK` notifications type. +* `webhook_url` - Target URL for the `WEBHOOK` notifications type. +* `microsoft_teams_webhook_url` - Microsoft Teams channel incoming webhook URL. Required for the `MICROSOFT_TEAMS` notifications type. +* `roles` - Atlas role in current Project or Organization. Atlas returns this value if you set `type_name` to `ORG` or `GROUP`. + For more information see: [MongoDB Atlas API Reference.](https://docs.atlas.mongodb.com/reference/api/alert-configurations/) Or refer to the individual resource or data_source documentation on alert configuration. \ No newline at end of file diff --git a/website/docs/r/alert_configuration.html.markdown b/website/docs/r/alert_configuration.html.markdown index 8d0f6df545..5800be6c00 100644 --- a/website/docs/r/alert_configuration.html.markdown +++ b/website/docs/r/alert_configuration.html.markdown @@ -125,7 +125,8 @@ resource "mongodbatlas_alert_configuration" "test" { * `enabled` - It is not required, but If the attribute is omitted, by default will be false, and the configuration would be disabled. You must set true to enable the configuration. * `event_type` - (Required) The type of event that will trigger an alert. - -> ***IMPORTANT:*** Event Type has many possible values. All current options at available at https://docs.atlas.mongodb.com/reference/api/alert-configurations-create-config/ and https://www.mongodb.com/docs/atlas/reference/alert-conditions/ Details for both conditional and metric based alerts can be found by selecting the tabs on the [alert config page](https://docs.atlas.mongodb.com/reference/api/alert-configurations-create-config/) and checking the latest eventTypeName options. + -> ***IMPORTANT:*** Event Type has many possible values. Details for both conditional and metric based alerts can be found by selecting the tabs on the [alert config page](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Alert-Configurations/operation/createAlertConfiguration) and checking the latest eventTypeName options. + -> **NOTE:** If `event_type` is set to `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD`, the `metric_threshold_config` field must also be configured. From b75abdc286ce901fadd2ed2df268ee654474756e Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Wed, 11 Oct 2023 16:27:29 +0200 Subject: [PATCH 08/10] fix merge conflict resolution --- .../fw_resource_mongodbatlas_alert_configuration_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go index adb0874568..4ea87038be 100644 --- a/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go +++ b/mongodbatlas/fw_resource_mongodbatlas_alert_configuration_test.go @@ -896,12 +896,7 @@ resource "mongodbatlas_project" "test" { name = %[2]q org_id = %[1]q } -resource "mongodbatlas_project" "test" { - name = %[2]q - org_id = %[1]q -} resource "mongodbatlas_alert_configuration" "test" { - project_id = mongodbatlas_project.test.id project_id = mongodbatlas_project.test.id event_type = "NO_PRIMARY" enabled = "true" From 01c373c16da3b0f3dee25e5fd502940bbda96216 Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Wed, 11 Oct 2023 16:38:22 +0200 Subject: [PATCH 09/10] update atlas sdk to 0.34.0 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5f6ae22d0f..562e5c5fc5 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/mwielbut/pointy v1.1.0 github.com/spf13/cast v1.5.1 github.com/zclconf/go-cty v1.14.1 - go.mongodb.org/atlas v0.33.1-0.20231004211218-011ec2beab4c + go.mongodb.org/atlas v0.34.0 go.mongodb.org/atlas-sdk/v20231001001 v20231001001.0.0 go.mongodb.org/realm v0.1.0 golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 diff --git a/go.sum b/go.sum index 181777cd92..e5b105e784 100644 --- a/go.sum +++ b/go.sum @@ -721,8 +721,8 @@ github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRK github.com/zclconf/go-cty-yaml v1.0.2 h1:dNyg4QLTrv2IfJpm7Wtxi55ed5gLGOlPrZ6kMd51hY0= github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0= go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M= -go.mongodb.org/atlas v0.33.1-0.20231004211218-011ec2beab4c h1:cEkC2k68XRkA4YWKsr2gLi6E7aPbPBDOwto5fmCcXVE= -go.mongodb.org/atlas v0.33.1-0.20231004211218-011ec2beab4c/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg= +go.mongodb.org/atlas v0.34.0 h1:C6pDYjKWbjSZCsNoZpgNO6I5e/jH7OVwoQ0OXcoAFCg= +go.mongodb.org/atlas v0.34.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg= go.mongodb.org/atlas-sdk/v20231001001 v20231001001.0.0 h1:7hl8ap9WzQDcaAO3/FWYdUYee7+taWWpXA4T4bPv6IE= go.mongodb.org/atlas-sdk/v20231001001 v20231001001.0.0/go.mod h1:2DismEF/fnloT92wjCkA1hpbBGrjQ5fPNAbC48mkRD4= go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M= From 7eb3a3ead33536243c72f99873161541ede1186f Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Wed, 11 Oct 2023 17:03:06 +0200 Subject: [PATCH 10/10] addressing docs PR comments --- examples/atlas-alert-configurations/README.md | 2 +- website/docs/d/alert_configuration.html.markdown | 6 +++--- website/docs/d/alert_configurations.html.markdown | 6 +++--- website/docs/r/alert_configuration.html.markdown | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/atlas-alert-configurations/README.md b/examples/atlas-alert-configurations/README.md index 7fea8356d3..cf3606c509 100644 --- a/examples/atlas-alert-configurations/README.md +++ b/examples/atlas-alert-configurations/README.md @@ -14,7 +14,7 @@ chmod +x ./import-alerts.sh terraform apply ``` -**NOTE**: Third-party notifications will not contain their respective credentials as these are sensitive attributes. If you wish to perform updates on these notifications without providing the original credentials the corresponding `notifier_id` attribute must be provided instead. +**NOTE**: Third-party notifications will not contain their respective credentials as these are sensitive attributes. If you wish to perform updates on these notifications without providing the original credentials, the corresponding `notifier_id` attribute must be provided instead. ## Contingency Plans If unhappy with the resource file or imports, here are some things that can be done: diff --git a/website/docs/d/alert_configuration.html.markdown b/website/docs/d/alert_configuration.html.markdown index 6135dc90e6..a17ac63dea 100644 --- a/website/docs/d/alert_configuration.html.markdown +++ b/website/docs/d/alert_configuration.html.markdown @@ -172,7 +172,7 @@ The threshold that causes an alert to be triggered. Required if `event_type_name * `metric_name` - Name of the metric to check. The full list being quite large, please refer to atlas docs [here for general metrics](https://docs.atlas.mongodb.com/reference/alert-host-metrics/#measurement-types) and [here for serverless metrics](https://www.mongodb.com/docs/atlas/reference/api/alert-configurations-create-config/#serverless-measurements) -* `operator` - Operator to apply when checking the current metric value against the threshold value. +* `operator` - The operator to apply when checking the current metric value against the threshold value. Accepted values are: - `GREATER_THAN` - `LESS_THAN` @@ -183,7 +183,7 @@ The threshold that causes an alert to be triggered. Required if `event_type_name * `mode` - This must be set to AVERAGE. Atlas computes the current metric value as an average. ### Threshold Config -* `operator` - Operator to apply when checking the current metric value against the threshold value. +* `operator` - The operator to apply when checking the current metric value against the threshold value. Accepted values are: - `GREATER_THAN` - `LESS_THAN` @@ -203,7 +203,7 @@ Notifications to send when an alert condition is detected. * `email_address` - Email address to which alert notifications are sent. Required for the EMAIL notifications type. * `email_enabled` - Flag indicating email notifications should be sent. Atlas returns this value if `type_name` is set to `ORG`, `GROUP`, or `USER`. * `flowdock_api_token` - The Flowdock personal API token. Required for the `FLOWDOCK` notifications type. If the token later becomes invalid, Atlas sends an email to the project owner and eventually removes the token. -* `flow_name` - Flowdock flow name in lower-case letters. Required for the `FLOWDOCK` notifications type +* `flow_name` - Flowdock flow name in lower-case letters. Required for the `FLOWDOCK` notifications type. * `interval_min` - Number of minutes to wait between successive notifications for unacknowledged alerts that are not resolved. The minimum value is 5. * `mobile_number` - Mobile number to which alert notifications are sent. Required for the SMS notifications type. * `ops_genie_api_key` - Opsgenie API Key. Required for the `OPS_GENIE` notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the token. diff --git a/website/docs/d/alert_configurations.html.markdown b/website/docs/d/alert_configurations.html.markdown index bd9bc4fa2a..f88436da7a 100644 --- a/website/docs/d/alert_configurations.html.markdown +++ b/website/docs/d/alert_configurations.html.markdown @@ -116,7 +116,7 @@ The threshold that causes an alert to be triggered. Required if `event_type_name * `metric_name` - Name of the metric to check. The full list being quite large, please refer to atlas docs [here for general metrics](https://docs.atlas.mongodb.com/reference/alert-host-metrics/#measurement-types) and [here for serverless metrics](https://www.mongodb.com/docs/atlas/reference/api/alert-configurations-create-config/#serverless-measurements) -* `operator` - Operator to apply when checking the current metric value against the threshold value. +* `operator` - The operator to apply when checking the current metric value against the threshold value. Accepted values are: - `GREATER_THAN` - `LESS_THAN` @@ -127,7 +127,7 @@ The threshold that causes an alert to be triggered. Required if `event_type_name * `mode` - This must be set to AVERAGE. Atlas computes the current metric value as an average. ### Threshold Config -* `operator` - Operator to apply when checking the current metric value against the threshold value. +* `operator` - The operator to apply when checking the current metric value against the threshold value. Accepted values are: - `GREATER_THAN` - `LESS_THAN` @@ -147,7 +147,7 @@ Notifications to send when an alert condition is detected. * `email_address` - Email address to which alert notifications are sent. Required for the EMAIL notifications type. * `email_enabled` - Flag indicating email notifications should be sent. Atlas returns this value if `type_name` is set to `ORG`, `GROUP`, or `USER`. * `flowdock_api_token` - The Flowdock personal API token. Required for the `FLOWDOCK` notifications type. If the token later becomes invalid, Atlas sends an email to the project owner and eventually removes the token. -* `flow_name` - Flowdock flow name in lower-case letters. Required for the `FLOWDOCK` notifications type +* `flow_name` - Flowdock flow name in lower-case letters. Required for the `FLOWDOCK` notifications type. * `interval_min` - Number of minutes to wait between successive notifications for unacknowledged alerts that are not resolved. The minimum value is 5. * `mobile_number` - Mobile number to which alert notifications are sent. Required for the SMS notifications type. * `ops_genie_api_key` - Opsgenie API Key. Required for the `OPS_GENIE` notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the token. diff --git a/website/docs/r/alert_configuration.html.markdown b/website/docs/r/alert_configuration.html.markdown index 5800be6c00..4b49d65fe3 100644 --- a/website/docs/r/alert_configuration.html.markdown +++ b/website/docs/r/alert_configuration.html.markdown @@ -168,7 +168,7 @@ All other types of alerts do not support matchers. The threshold that causes an alert to be triggered. Required if `event_type_name` : `OUTSIDE_METRIC_THRESHOLD` or `OUTSIDE_SERVERLESS_METRIC_THRESHOLD` * `metric_name` - (Required) Name of the metric to check. The full list being quite large, please refer to atlas docs [here for general metrics](https://docs.atlas.mongodb.com/reference/alert-host-metrics/#measurement-types) and [here for serverless metrics](https://www.mongodb.com/docs/atlas/reference/api/alert-configurations-create-config/#serverless-measurements) -* `operator` - Operator to apply when checking the current metric value against the threshold value. +* `operator` - The operator to apply when checking the current metric value against the threshold value. Accepted values are: - `GREATER_THAN` - `LESS_THAN` @@ -180,7 +180,7 @@ The threshold that causes an alert to be triggered. Required if `event_type_name * `mode` - This must be set to AVERAGE. Atlas computes the current metric value as an average. ### Threshold Config (`threshold_config`) -* `operator` - Operator to apply when checking the current metric value against the threshold value. +* `operator` - The operator to apply when checking the current metric value against the threshold value. Accepted values are: - `GREATER_THAN` - `LESS_THAN` @@ -200,7 +200,7 @@ List of notifications to send when an alert condition is detected. * `email_address` - Email address to which alert notifications are sent. Required for the EMAIL notifications type. * `email_enabled` - Flag indicating email notifications should be sent. This flag is only valid if `type_name` is set to `ORG`, `GROUP`, or `USER`. * `flowdock_api_token` - The Flowdock personal API token. Required for the `FLOWDOCK` notifications type. If the token later becomes invalid, Atlas sends an email to the project owner and eventually removes the token. -* `flow_name` - Flowdock flow name in lower-case letters. Required for the `FLOWDOCK` notifications type +* `flow_name` - Flowdock flow name in lower-case letters. Required for the `FLOWDOCK` notifications type. * `interval_min` - Number of minutes to wait between successive notifications for unacknowledged alerts that are not resolved. The minimum value is 5. **NOTE** `PAGER_DUTY`, `VICTOR_OPS`, and `OPS_GENIE` notifications do not return this value. The notification interval must be configured and managed within each external service. * `mobile_number` - Mobile number to which alert notifications are sent. Required for the SMS notifications type. * `ops_genie_api_key` - Opsgenie API Key. Required for the `OPS_GENIE` notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the token. @@ -265,6 +265,6 @@ Alert Configuration can be imported using the `project_id-alert_configuration_id $ terraform import mongodbatlas_alert_configuration.test 5d0f1f74cf09a29120e123cd-5d0f1f74cf09a29120e1fscg ``` -**NOTE**: Third-party notifications will not contain their respective credentials as these are sensitive attributes. If you wish to perform updates on these notifications without providing the original credentials the corresponding `notifier_id` attribute must be provided instead. +**NOTE**: Third-party notifications will not contain their respective credentials as these are sensitive attributes. If you wish to perform updates on these notifications without providing the original credentials, the corresponding `notifier_id` attribute must be provided instead. For more information see: [MongoDB Atlas API Reference.](https://docs.atlas.mongodb.com/reference/api/alert-configurations/)