Skip to content

Commit f8be7e2

Browse files
authored
fix: Updates integration_id in mongodbatlas_alert_configuration resource to be Optional+Computed (#2603)
1 parent 8132300 commit f8be7e2

File tree

6 files changed

+113
-31
lines changed

6 files changed

+113
-31
lines changed

.changelog/2603.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:note
2+
resource/mongodbatlas_alert_configuration: Updates `notification.#.integration_id` to be Optional & Computed
3+
```

docs/guides/1.20.0-upgrade-guide.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ The Terraform MongoDB Atlas Provider version 1.20.0 has a number of new and exci
1919
- data-source/mongodbatlas_data_lake_pipeline_run
2020
- data-source/mongodbatlas_data_lake_pipeline_runs
2121

22+
**Breaking Changes:**
23+
- `mongodbatlas_alert_configuration` resource attribute `notification.#.integration_id` may have a computed value due to recent updates in the Atlas API [Alert Configuration](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Alert-Configurations/operation/getAlertConfiguration). Due to this, MongoDB Atlas Provider versions **1.16.0 to 1.19.0** may experience non-empty plans if you are using this resource with an integration set for the notifications without an explicitly set `integration_id`. For more details, see [#2603](https://github.com/mongodb/terraform-provider-mongodbatlas/pull/2603).
24+
25+
These users should either:
26+
27+
- Upgrade to the latest MongoDB Atlas Terraform Provider (1.20.0) to avoid the non-empty plan, or
28+
- Update Terraform configurations to include the `integration_id` returned in the non-empty plan as:
29+
```
30+
notification {
31+
type_name = "DATADOG"
32+
integration_id = "xxxxxxxxxxxxxxxxxxxxxxxx" # add integration_id shown in the plan to your configuration
33+
datadog_api_key = mongodbatlas_third_party_integration.atlas_datadog.api_key
34+
datadog_region = mongodbatlas_third_party_integration.atlas_datadog.region
35+
interval_min = 6
36+
}
37+
```
38+
39+
Note: Applying the non-empty plan will be a no-op but users will still get the non-empty plan even after applying unless one of the above solutions are adopted.
40+
41+
2242
## New Terraform MongoDB Atlas modules
2343
You can now leverage our [Terraform Modules](https://registry.terraform.io/namespaces/terraform-mongodbatlas-modules) to easily get started with MongoDB Atlas and critical features like [Push-based log export](https://registry.terraform.io/modules/terraform-mongodbatlas-modules/push-based-log-export/mongodbatlas/latest), [Private Endpoints](https://registry.terraform.io/modules/terraform-mongodbatlas-modules/private-endpoint/mongodbatlas/latest), etc.
2444

internal/service/alertconfiguration/model_alert_configuration.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import (
44
"fmt"
55
"strings"
66

7+
"go.mongodb.org/atlas-sdk/v20240805004/admin"
8+
79
"github.com/hashicorp/terraform-plugin-framework/types"
10+
811
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
9-
"go.mongodb.org/atlas-sdk/v20240805004/admin"
1012
)
1113

1214
func NewNotificationList(list []TfNotificationModel) (*[]admin.AlertsNotificationRootForGroup, error) {
@@ -46,10 +48,8 @@ func NewNotificationList(list []TfNotificationModel) (*[]admin.AlertsNotificatio
4648
MicrosoftTeamsWebhookUrl: n.MicrosoftTeamsWebhookURL.ValueStringPointer(),
4749
WebhookSecret: n.WebhookSecret.ValueStringPointer(),
4850
WebhookUrl: n.WebhookURL.ValueStringPointer(),
49-
IntegrationId: n.IntegrationID.ValueStringPointer(),
50-
}
51-
if !n.NotifierID.IsUnknown() {
52-
notifications[i].NotifierId = n.NotifierID.ValueStringPointer()
51+
IntegrationId: conversion.StringPtr(n.IntegrationID.ValueString()),
52+
NotifierId: conversion.StringPtr(n.NotifierID.ValueString()),
5353
}
5454
}
5555
return &notifications, nil

internal/service/alertconfiguration/resource_alert_configuration.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"reflect"
77
"strings"
88

9+
"go.mongodb.org/atlas-sdk/v20240805004/admin"
10+
911
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
1012
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1113
"github.com/hashicorp/terraform-plugin-framework/path"
@@ -18,9 +20,9 @@ import (
1820
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1921
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
2022
"github.com/hashicorp/terraform-plugin-framework/types"
23+
2124
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
2225
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
23-
"go.mongodb.org/atlas-sdk/v20240805004/admin"
2426
)
2527

2628
const (
@@ -324,6 +326,7 @@ func (r *alertConfigurationRS) Schema(ctx context.Context, req resource.SchemaRe
324326
},
325327
"integration_id": schema.StringAttribute{
326328
Optional: true,
329+
Computed: true,
327330
},
328331
"type_name": schema.StringAttribute{
329332
Required: true,

internal/service/alertconfiguration/resource_alert_configuration_migration_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
7+
78
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
89
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
910
)
@@ -142,3 +143,8 @@ func TestMigConfigRSAlertConfiguration_withEmptyOptionalAttributes(t *testing.T)
142143
},
143144
})
144145
}
146+
147+
func TestMigConfigRSAlertConfiguration_withDataDog(t *testing.T) {
148+
mig.SkipIfVersionBelow(t, "1.20.0")
149+
mig.CreateAndRunTest(t, datadogTestCase(t))
150+
}

internal/service/alertconfiguration/resource_alert_configuration_test.go

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1111
"github.com/hashicorp/terraform-plugin-testing/terraform"
12+
1213
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
1314
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration"
1415
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
@@ -367,28 +368,67 @@ func TestAccConfigRSAlertConfiguration_updatePagerDutyWithNotifierId(t *testing.
367368
}
368369

369370
func TestAccConfigRSAlertConfiguration_withDataDog(t *testing.T) {
371+
resource.ParallelTest(t, *datadogTestCase(t))
372+
}
373+
374+
func datadogTestCase(t *testing.T) *resource.TestCase {
375+
t.Helper()
376+
370377
proxyPort := replay.SetupReplayProxy(t)
371378

372379
var (
373380
projectID = replay.ManageProjectID(t, acc.ProjectIDExecution)
374381
ddAPIKey = dummy32CharKey
375382
ddRegion = "US"
383+
384+
groupNotificationMap = map[string]string{
385+
"type_name": "GROUP",
386+
"interval_min": "5",
387+
"delay_min": "0",
388+
}
389+
390+
ddNotificationMap = map[string]string{
391+
"type_name": "DATADOG",
392+
"interval_min": "5",
393+
"delay_min": "0",
394+
"datadog_api_key": ddAPIKey,
395+
"datadog_region": ddRegion,
396+
}
397+
398+
ddNotificationUpdatedMap = map[string]string{
399+
"type_name": "DATADOG",
400+
"interval_min": "6",
401+
"delay_min": "0",
402+
"datadog_api_key": ddAPIKey,
403+
"datadog_region": ddRegion,
404+
}
376405
)
377406

378-
resource.ParallelTest(t, resource.TestCase{
407+
return &resource.TestCase{
379408
PreCheck: func() { acc.PreCheckBasic(t) },
380409
ProtoV6ProviderFactories: acc.TestAccProviderV6FactoriesWithProxy(proxyPort),
381410
CheckDestroy: checkDestroyUsingProxy(proxyPort),
382411
Steps: []resource.TestStep{
383412
{
384-
Config: configWithDataDog(projectID, ddAPIKey, ddRegion, true),
413+
Config: configWithDataDog(projectID, ddAPIKey, ddRegion, true, ddNotificationMap, groupNotificationMap),
385414
Check: resource.ComposeAggregateTestCheckFunc(
386415
checkExistsUsingProxy(proxyPort, resourceName),
387416
resource.TestCheckResourceAttr(resourceName, "project_id", projectID),
417+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "notification.*", groupNotificationMap),
418+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "notification.*", ddNotificationMap),
419+
),
420+
},
421+
{
422+
Config: configWithDataDog(projectID, ddAPIKey, ddRegion, true, ddNotificationUpdatedMap, groupNotificationMap),
423+
Check: resource.ComposeAggregateTestCheckFunc(
424+
checkExistsUsingProxy(proxyPort, resourceName),
425+
resource.TestCheckResourceAttr(resourceName, "project_id", projectID),
426+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "notification.*", groupNotificationMap),
427+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "notification.*", ddNotificationUpdatedMap),
388428
),
389429
},
390430
},
391-
})
431+
}
392432
}
393433

394434
func TestAccConfigRSAlertConfiguration_withPagerDuty(t *testing.T) {
@@ -412,11 +452,13 @@ func TestAccConfigRSAlertConfiguration_withPagerDuty(t *testing.T) {
412452
),
413453
},
414454
{
415-
ResourceName: resourceName,
416-
ImportStateIdFunc: importStateProjectIDFunc(resourceName),
417-
ImportState: true,
418-
ImportStateVerify: true,
419-
ImportStateVerifyIgnore: []string{"updated", "notification.0.service_key"}, // service key is not returned by api in import operation
455+
ResourceName: resourceName,
456+
ImportStateIdFunc: importStateProjectIDFunc(resourceName),
457+
ImportState: true,
458+
ImportStateVerify: true,
459+
// service key is not returned by api in import operation
460+
// integration_id is not returned during Create
461+
ImportStateVerifyIgnore: []string{"updated", "notification.0.service_key", "notification.0.integration_id"},
420462
},
421463
},
422464
})
@@ -736,7 +778,28 @@ func configWithThresholdUpdated(projectID string, enabled bool, threshold float6
736778
`, projectID, enabled, threshold)
737779
}
738780

739-
func configWithDataDog(projectID, dataDogAPIKey, dataDogRegion string, enabled bool) string {
781+
func configWithDataDog(projectID, dataDogAPIKey, dataDogRegion string, enabled bool, ddNotificationMap, groupNotificationMap map[string]string) string {
782+
ddNotificationBlock := fmt.Sprintf(`
783+
notification {
784+
type_name = %[1]q
785+
datadog_api_key = mongodbatlas_third_party_integration.atlas_datadog.api_key
786+
datadog_region = mongodbatlas_third_party_integration.atlas_datadog.region
787+
interval_min = %[2]v
788+
delay_min = %[3]v
789+
}
790+
`, ddNotificationMap["type_name"], ddNotificationMap["interval_min"], ddNotificationMap["delay_min"])
791+
792+
groupNotificationBlock := fmt.Sprintf(`
793+
notification {
794+
type_name = %[1]q
795+
interval_min = %[2]v
796+
delay_min = %[3]v
797+
sms_enabled = false
798+
email_enabled = true
799+
roles = ["GROUP_OWNER"]
800+
}
801+
`, groupNotificationMap["type_name"], groupNotificationMap["interval_min"], groupNotificationMap["delay_min"])
802+
740803
return fmt.Sprintf(`
741804
resource "mongodbatlas_third_party_integration" "atlas_datadog" {
742805
project_id = %[1]q
@@ -750,22 +813,9 @@ func configWithDataDog(projectID, dataDogAPIKey, dataDogRegion string, enabled b
750813
event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT"
751814
enabled = %[4]t
752815
753-
notification {
754-
type_name = "GROUP"
755-
interval_min = 5
756-
delay_min = 0
757-
sms_enabled = false
758-
email_enabled = true
759-
roles = ["GROUP_OWNER"]
760-
}
816+
%[5]s
761817
762-
notification {
763-
type_name = "DATADOG"
764-
datadog_api_key = mongodbatlas_third_party_integration.atlas_datadog.api_key
765-
datadog_region = mongodbatlas_third_party_integration.atlas_datadog.region
766-
interval_min = 5
767-
delay_min = 0
768-
}
818+
%[6]s
769819
770820
matcher {
771821
field_name = "REPLICA_SET_NAME"
@@ -779,7 +829,7 @@ func configWithDataDog(projectID, dataDogAPIKey, dataDogRegion string, enabled b
779829
units = "HOURS"
780830
}
781831
}
782-
`, projectID, dataDogAPIKey, dataDogRegion, enabled)
832+
`, projectID, dataDogAPIKey, dataDogRegion, enabled, groupNotificationBlock, ddNotificationBlock)
783833
}
784834

785835
func configWithPagerDuty(projectID, serviceKey string, enabled bool) string {

0 commit comments

Comments
 (0)