Skip to content

Commit 0d43548

Browse files
authored
feat: Adds support for skip_default_alerts_settings in mongodbatlas_organization resource & data sources (#2933)
1 parent 6532731 commit 0d43548

File tree

9 files changed

+144
-44
lines changed

9 files changed

+144
-44
lines changed

.changelog/2933.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_organization: Adds support for `skip_default_alerts_settings` setting
3+
```
4+
5+
```release-note:enhancement
6+
data-source/mongodbatlas_organization: Adds support for `skip_default_alerts_settings` setting
7+
```
8+
9+
```release-note:enhancement
10+
data-source/mongodbatlas_organizations: Adds support for `skip_default_alerts_settings` setting
11+
```

docs/data-sources/organization.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ In addition to all arguments above, the following attributes are exported:
2727
* `multi_factor_auth_required` - (Optional) Flag that indicates whether to require users to set up Multi-Factor Authentication (MFA) before accessing the specified organization. To learn more, see: https://www.mongodb.com/docs/atlas/security-multi-factor-authentication/.
2828
* `restrict_employee_access` - (Optional) Flag that indicates whether to block MongoDB Support from accessing Atlas infrastructure for any deployment in the specified organization without explicit permission. Once this setting is turned on, you can grant MongoDB Support a 24-hour bypass access to the Atlas deployment to resolve support issues. To learn more, see: https://www.mongodb.com/docs/atlas/security-restrict-support-access/.
2929
* `gen_ai_features_enabled` - (Optional) Flag that indicates whether this organization has access to generative AI features. This setting only applies to Atlas Commercial and defaults to `true`. With this setting on, Project Owners may be able to enable or disable individual AI features at the project level. To learn more, see https://www.mongodb.com/docs/generative-ai-faq/.
30+
* `skip_default_alerts_settings` - (Optional) Flag that indicates whether to prevent Atlas from automatically creating organization-level alerts not explicitly managed through Terraform. Defaults to `true`.
3031

32+
~> **NOTE:**
33+
- *If you created an organization with our Terraform provider version >=1.30.0, this field will be set to `true` by default.*
34+
- *If you have an existing organization created with our Terraform provider version <1.30.0, this field might be `false`, which is the [API default value](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Organizations/operation/createOrganization). To prevent creation of future default alerts, you can explicitly set this to `true` using the [`mongodbatlas_organization`](../resources/organization.md) resource.*
3135

3236
See [MongoDB Atlas API - Organization](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Organizations/operation/getOrganization) Documentation for more information.

docs/data-sources/organizations.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ data "mongodbatlas_organizations" "test" {
3232
* `multi_factor_auth_required` - (Optional) Flag that indicates whether to require users to set up Multi-Factor Authentication (MFA) before accessing the specified organization. To learn more, see: https://www.mongodb.com/docs/atlas/security-multi-factor-authentication/.
3333
* `restrict_employee_access` - (Optional) Flag that indicates whether to block MongoDB Support from accessing Atlas infrastructure for any deployment in the specified organization without explicit permission. Once this setting is turned on, you can grant MongoDB Support a 24-hour bypass access to the Atlas deployment to resolve support issues. To learn more, see: https://www.mongodb.com/docs/atlas/security-restrict-support-access/.
3434
* `gen_ai_features_enabled` - (Optional) Flag that indicates whether this organization has access to generative AI features. This setting only applies to Atlas Commercial and defaults to `true`. With this setting on, Project Owners may be able to enable or disable individual AI features at the project level. To learn more, see https://www.mongodb.com/docs/generative-ai-faq/.
35-
35+
* `skip_default_alerts_settings` - (Optional) Flag that indicates whether to prevent Atlas from automatically creating organization-level alerts not explicitly managed through Terraform. Defaults to `true`.
36+
37+
~> **NOTE:**
38+
- *If you created an organization with our Terraform provider version >=1.30.0, this field will be set to `true` by default.*
39+
- *If you have an existing organization created with our Terraform provider version <1.30.0, this field might be `false`, which is the [API default value](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Organizations/operation/createOrganization). To prevent creation of future default alerts, you can explicitly set this to `true` using the [`mongodbatlas_organization`](../resources/organization.md) resource.*
40+
3641
See [MongoDB Atlas API - Organizations](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Organizations/operation/listOrganizations) Documentation for more information.

docs/resources/organization.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ resource "mongodbatlas_organization" "test" {
3333
* `multi_factor_auth_required` - (Optional) Flag that indicates whether to require users to set up Multi-Factor Authentication (MFA) before accessing the specified organization. To learn more, see: https://www.mongodb.com/docs/atlas/security-multi-factor-authentication/.
3434
* `restrict_employee_access` - (Optional) Flag that indicates whether to block MongoDB Support from accessing Atlas infrastructure for any deployment in the specified organization without explicit permission. Once this setting is turned on, you can grant MongoDB Support a 24-hour bypass access to the Atlas deployment to resolve support issues. To learn more, see: https://www.mongodb.com/docs/atlas/security-restrict-support-access/.
3535
* `gen_ai_features_enabled` - (Optional) Flag that indicates whether this organization has access to generative AI features. This setting only applies to Atlas Commercial and defaults to `true`. With this setting on, Project Owners may be able to enable or disable individual AI features at the project level. To learn more, see https://www.mongodb.com/docs/generative-ai-faq/.
36+
* `skip_default_alerts_settings` - (Optional) Flag that indicates whether to prevent Atlas from automatically creating organization-level alerts not explicitly managed through Terraform. Defaults to `true`.
37+
38+
~> **NOTE:**
39+
- *If you are creating an organization with our Terraform provider version >=1.30.0, this field will be set to `true` by default.*
40+
- *If you have an existing organization created with our Terraform provider version <1.30.0, this field might be `false`, which is the [API default value](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Organizations/operation/createOrganization). To prevent creation of future default alerts, you can explicitly set this to `true`.*
41+
3642

3743
## Attributes Reference
3844

internal/service/organization/data_source_organization.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func DataSource() *schema.Resource {
5959
Type: schema.TypeBool,
6060
Computed: true,
6161
},
62+
"skip_default_alerts_settings": {
63+
Type: schema.TypeBool,
64+
Computed: true,
65+
},
6266
},
6367
}
6468
}
@@ -77,6 +81,10 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
7781
return diag.FromErr(fmt.Errorf("error setting `name`: %s", err))
7882
}
7983

84+
if err := d.Set("skip_default_alerts_settings", organization.GetSkipDefaultAlertsSettings()); err != nil {
85+
return diag.Errorf("error setting `skip_default_alerts_settings`: %s", err)
86+
}
87+
8088
if err := d.Set("is_deleted", organization.GetIsDeleted()); err != nil {
8189
return diag.FromErr(fmt.Errorf("error setting `is_deleted`: %s", err))
8290
}

internal/service/organization/data_source_organizations.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func PluralDataSource() *schema.Resource {
7979
Type: schema.TypeBool,
8080
Computed: true,
8181
},
82+
"skip_default_alerts_settings": {
83+
Type: schema.TypeBool,
84+
Computed: true,
85+
},
8286
},
8387
},
8488
},
@@ -135,14 +139,15 @@ func flattenOrganizations(ctx context.Context, conn *admin.APIClient, organizati
135139
return nil, fmt.Errorf("error getting organization settings (orgID: %s, org Name: %s): %s", organization.GetId(), organization.GetName(), err)
136140
}
137141
results[k] = map[string]any{
138-
"id": organization.Id,
139-
"name": organization.Name,
140-
"is_deleted": organization.IsDeleted,
141-
"links": conversion.FlattenLinks(organization.GetLinks()),
142-
"api_access_list_required": settings.ApiAccessListRequired,
143-
"multi_factor_auth_required": settings.MultiFactorAuthRequired,
144-
"restrict_employee_access": settings.RestrictEmployeeAccess,
145-
"gen_ai_features_enabled": settings.GenAIFeaturesEnabled,
142+
"id": organization.Id,
143+
"name": organization.Name,
144+
"skip_default_alerts_settings": organization.SkipDefaultAlertsSettings,
145+
"is_deleted": organization.IsDeleted,
146+
"links": conversion.FlattenLinks(organization.GetLinks()),
147+
"api_access_list_required": settings.ApiAccessListRequired,
148+
"multi_factor_auth_required": settings.MultiFactorAuthRequired,
149+
"restrict_employee_access": settings.RestrictEmployeeAccess,
150+
"gen_ai_features_enabled": settings.GenAIFeaturesEnabled,
146151
}
147152
}
148153
return results, nil

internal/service/organization/resource_organization.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ func Resource() *schema.Resource {
8282
Optional: true,
8383
Default: true,
8484
},
85+
// skip_default_alerts_settings defaults to `true` to prevent Atlas from automatically creating organization-level alerts not explicitly managed through Terraform.
86+
// Note that this deviates from the API default of `false` for this attribute.
87+
"skip_default_alerts_settings": {
88+
Type: schema.TypeBool,
89+
Optional: true,
90+
Computed: true,
91+
},
8592
},
8693
}
8794
}
@@ -173,6 +180,9 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di
173180
if err := d.Set("name", organization.Name); err != nil {
174181
return diag.Errorf("error setting `name` for organization (%s): %s", *organization.Id, err)
175182
}
183+
if err := d.Set("skip_default_alerts_settings", organization.SkipDefaultAlertsSettings); err != nil {
184+
return diag.Errorf("error setting `skip_default_alerts_settings` for organization (%s): %s", orgID, err)
185+
}
176186

177187
settings, _, err := conn.OrganizationsApi.GetOrganizationSettings(ctx, orgID).Execute()
178188
if err != nil {
@@ -213,8 +223,12 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.
213223
orgID := ids["org_id"]
214224

215225
updateRequest := new(admin.AtlasOrganization)
216-
if d.HasChange("name") {
226+
227+
if d.HasChange("name") ||
228+
d.HasChange("skip_default_alerts_settings") {
217229
updateRequest.Name = d.Get("name").(string)
230+
updateRequest.SkipDefaultAlertsSettings = conversion.Pointer(d.Get("skip_default_alerts_settings").(bool))
231+
218232
_, _, err := conn.OrganizationsApi.UpdateOrganization(ctx, orgID, updateRequest).Execute()
219233
if err != nil {
220234
return diag.FromErr(fmt.Errorf("error updating Organization name: %s", err))
@@ -254,9 +268,18 @@ func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.
254268
}
255269

256270
func newCreateOrganizationRequest(d *schema.ResourceData) *admin.CreateOrganizationRequest {
271+
// skip_default_alerts_settings defaults to `true` to prevent Atlas from automatically creating organization-level alerts not explicitly managed through Terraform.
272+
// Note that this deviates from the API default of `false` for this attribute.
273+
skipDefaultAlertsSettings := true
274+
275+
if v, ok := d.GetOkExists("skip_default_alerts_settings"); ok {
276+
skipDefaultAlertsSettings = v.(bool)
277+
}
278+
257279
createRequest := &admin.CreateOrganizationRequest{
258-
Name: d.Get("name").(string),
259-
OrgOwnerId: conversion.Pointer(d.Get("org_owner_id").(string)),
280+
Name: d.Get("name").(string),
281+
OrgOwnerId: conversion.Pointer(d.Get("org_owner_id").(string)),
282+
SkipDefaultAlertsSettings: conversion.Pointer(skipDefaultAlertsSettings),
260283

261284
ApiKey: &admin.CreateAtlasOrganizationApiKey{
262285
Roles: conversion.ExpandStringList(d.Get("role_names").(*schema.Set).List()),

internal/service/organization/resource_organization_migration_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestMigConfigRSOrganization_Basic(t *testing.T) {
1919
name = acc.RandomName()
2020
description = "test Key for Acceptance tests"
2121
roleName = "ORG_OWNER"
22-
config = configBasic(orgOwnerID, name, description, roleName)
22+
config = configBasic(orgOwnerID, name, description, roleName, false, nil)
2323
)
2424

2525
resource.Test(t, resource.TestCase{
@@ -29,7 +29,6 @@ func TestMigConfigRSOrganization_Basic(t *testing.T) {
2929
Config: config,
3030
Check: resource.ComposeAggregateTestCheckFunc(
3131
resource.TestCheckResourceAttrSet(resourceName, "org_id"),
32-
resource.TestCheckResourceAttrSet(resourceName, "description"),
3332
resource.TestCheckResourceAttr(resourceName, "description", description),
3433
),
3534
},

0 commit comments

Comments
 (0)