Skip to content

Commit

Permalink
fix: HELP: Error: The terraform-provider-mongodbatlas_v1.11.0 plugin …
Browse files Browse the repository at this point in the history
…crashed (#1419)
  • Loading branch information
andreaangiolillo committed Aug 28, 2023
1 parent d782983 commit 623dcdc
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
12 changes: 9 additions & 3 deletions mongodbatlas/resource_mongodbatlas_alert_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/mwielbut/pointy"
"github.com/spf13/cast"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
matlas "go.mongodb.org/atlas/mongodbatlas"
)

Expand Down Expand Up @@ -515,8 +514,11 @@ func expandAlertConfigurationMatchers(d *schema.ResourceData) []matlas.Matcher {

if m, ok := d.GetOk("matcher"); ok {
for _, value := range m.([]interface{}) {
v := value.(map[string]interface{})
if value == nil {
break
}

v := value.(map[string]interface{})
matchers = append(matchers, matlas.Matcher{
FieldName: v["field_name"].(string),
Operator: v["operator"].(string),
Expand Down Expand Up @@ -610,6 +612,10 @@ func expandAlertConfigurationThresholdConfig(d *schema.ResourceData) *matlas.Thr
vL := value.([]interface{})

if len(vL) > 0 {
if vL[0] == nil {
return nil
}

v := vL[0].(map[string]interface{})

return &matlas.Threshold{
Expand Down
69 changes: 69 additions & 0 deletions mongodbatlas/resource_mongodbatlas_alert_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ func TestAccConfigRSAlertConfiguration_EmptyMetricThresholdConfig(t *testing.T)
})
}

func TestAccConfigRSAlertConfiguration_EmptyMatcherMetricThresholdConfig(t *testing.T) {
var (
resourceName = "mongodbatlas_alert_configuration.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
alert = &matlas.AlertConfiguration{}
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckBasic(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasAlertConfigurationConfigEmptyMatcherMetricThresholdConfig(orgID, projectName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasAlertConfigurationExists(resourceName, alert),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "notification.#", "1"),
),
ExpectNonEmptyPlan: true,
},
},
})
}
func TestAccConfigRSAlertConfiguration_Notifications(t *testing.T) {
var (
resourceName = "mongodbatlas_alert_configuration.test"
Expand Down Expand Up @@ -808,3 +833,47 @@ resource "mongodbatlas_alert_configuration" "test" {
}
`, orgID, projectName, enabled)
}

func testAccMongoDBAtlasAlertConfigurationConfigEmptyMatcherMetricThresholdConfig(orgID, projectName 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 = mongodbatlas_project.test.id
event_type = "CLUSTER_MONGOS_IS_MISSING"
enabled = "%[3]t"
notification {
type_name = "GROUP"
interval_min = 60
delay_min = 0
sms_enabled = true
email_enabled = false
roles = ["GROUP_OWNER"]
}
matcher {
field_name = ""
operator = null
value = ""
}
metric_threshold_config {
metric_name = ""
operator = null
threshold = null
units = null
mode = ""
}
threshold_config {
operator = null
threshold = null
units = null
}
}
`, orgID, projectName, enabled)
}

0 comments on commit 623dcdc

Please sign in to comment.