Skip to content

Commit

Permalink
add new attribute in schema, convertion functions, and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinBettati committed Apr 25, 2024
1 parent 42f6cf6 commit 58f6c3b
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 30 deletions.
11 changes: 11 additions & 0 deletions .changelog/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/mongodbatlas_alert_configuration: Adds `integration_id` attribute
```

```release-note:enhancement
data-source/mongodbatlas_alert_configuration: Adds `integration_id` attribute
```

```release-note:enhancement
data-source/mongodbatlas_alert_configurations: Adds `integration_id` attribute
```
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ var alertConfigDSSchemaAttributes = map[string]schema.Attribute{
"notifier_id": schema.StringAttribute{
Computed: true,
},
"integration_id": schema.StringAttribute{
Computed: true,
},
"type_name": schema.StringAttribute{
Computed: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func NewNotificationList(list []TfNotificationModel) (*[]admin.AlertsNotificatio
MicrosoftTeamsWebhookUrl: n.MicrosoftTeamsWebhookURL.ValueStringPointer(),
WebhookSecret: n.WebhookSecret.ValueStringPointer(),
WebhookUrl: n.WebhookURL.ValueStringPointer(),
IntegrationId: n.IntegrationID.ValueStringPointer(),
}
if !n.NotifierID.IsUnknown() {
notifications[i].NotifierId = n.NotifierID.ValueStringPointer()
Expand Down Expand Up @@ -127,6 +128,7 @@ func NewTFNotificationModelList(n []admin.AlertsNotificationRootForGroup, currSt
OpsGenieRegion: conversion.StringPtrNullIfEmpty(value.OpsGenieRegion),
TeamID: conversion.StringPtrNullIfEmpty(value.TeamId),
NotifierID: types.StringPointerValue(value.NotifierId),
IntegrationID: types.StringPointerValue(value.IntegrationId),
TypeName: conversion.StringPtrNullIfEmpty(value.TypeName),
Username: conversion.StringPtrNullIfEmpty(value.Username),
EmailEnabled: types.BoolValue(value.EmailEnabled != nil && *value.EmailEnabled),
Expand All @@ -153,6 +155,7 @@ func NewTFNotificationModelList(n []admin.AlertsNotificationRootForGroup, currSt
WebhookSecret: conversion.StringNullIfEmpty(currState.WebhookSecret.ValueString()),
MicrosoftTeamsWebhookURL: conversion.StringNullIfEmpty(currState.MicrosoftTeamsWebhookURL.ValueString()),
NotifierID: types.StringPointerValue(value.NotifierId),
IntegrationID: types.StringPointerValue(value.IntegrationId),
IntervalMin: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(value.IntervalMin)),
DelayMin: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(value.DelayMin)),
EmailEnabled: types.BoolValue(value.EmailEnabled != nil && *value.EmailEnabled),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
threshold float64 = 99.0
units string = "RAW"
mode string = "AVERAGE"
integrationID string = "fake-intregration-id"
)

var (
Expand All @@ -39,14 +40,15 @@ func TestNotificationSDKToTFModel(t *testing.T) {
name: "Complete SDK response",
SDKResp: &[]admin.AlertsNotificationRootForGroup{
{
TypeName: admin.PtrString(group),
IntervalMin: admin.PtrInt(intervalMin),
DelayMin: admin.PtrInt(delayMin),
SmsEnabled: admin.PtrBool(disabled),
EmailEnabled: admin.PtrBool(enabled),
ChannelName: admin.PtrString("#channel"),
Roles: &roles,
ApiToken: admin.PtrString("newApiToken"),
TypeName: admin.PtrString(group),
IntervalMin: admin.PtrInt(intervalMin),
DelayMin: admin.PtrInt(delayMin),
SmsEnabled: admin.PtrBool(disabled),
EmailEnabled: admin.PtrBool(enabled),
ChannelName: admin.PtrString("#channel"),
Roles: &roles,
ApiToken: admin.PtrString("newApiToken"),
IntegrationId: admin.PtrString(integrationID),
},
},
currentStateNotifications: []alertconfiguration.TfNotificationModel{
Expand All @@ -62,14 +64,15 @@ func TestNotificationSDKToTFModel(t *testing.T) {
},
expectedTFModel: []alertconfiguration.TfNotificationModel{
{
TypeName: types.StringValue(group),
IntervalMin: types.Int64Value(int64(intervalMin)),
DelayMin: types.Int64Value(int64(delayMin)),
SMSEnabled: types.BoolValue(disabled),
EmailEnabled: types.BoolValue(enabled),
ChannelName: types.StringNull(),
APIToken: types.StringValue("apiToken"),
Roles: roles,
TypeName: types.StringValue(group),
IntervalMin: types.Int64Value(int64(intervalMin)),
DelayMin: types.Int64Value(int64(delayMin)),
SMSEnabled: types.BoolValue(disabled),
EmailEnabled: types.BoolValue(enabled),
ChannelName: types.StringNull(),
APIToken: types.StringValue("apiToken"),
Roles: roles,
IntegrationID: types.StringValue(integrationID),
},
},
},
Expand Down Expand Up @@ -265,22 +268,24 @@ func TestNotificationTFModelToSDK(t *testing.T) {
name: "Complete TF model",
tfModel: []alertconfiguration.TfNotificationModel{
{
TypeName: types.StringValue(group),
IntervalMin: types.Int64Value(int64(intervalMin)),
DelayMin: types.Int64Value(int64(delayMin)),
SMSEnabled: types.BoolValue(disabled),
EmailEnabled: types.BoolValue(enabled),
Roles: roles,
TypeName: types.StringValue(group),
IntervalMin: types.Int64Value(int64(intervalMin)),
DelayMin: types.Int64Value(int64(delayMin)),
SMSEnabled: types.BoolValue(disabled),
EmailEnabled: types.BoolValue(enabled),
Roles: roles,
IntegrationID: types.StringValue(integrationID),
},
},
expectedSDKReq: &[]admin.AlertsNotificationRootForGroup{
{
TypeName: admin.PtrString(group),
IntervalMin: admin.PtrInt(intervalMin),
DelayMin: admin.PtrInt(delayMin),
SmsEnabled: admin.PtrBool(disabled),
EmailEnabled: admin.PtrBool(enabled),
Roles: &roles,
TypeName: admin.PtrString(group),
IntervalMin: admin.PtrInt(intervalMin),
DelayMin: admin.PtrInt(delayMin),
SmsEnabled: admin.PtrBool(disabled),
EmailEnabled: admin.PtrBool(enabled),
Roles: &roles,
IntegrationId: admin.PtrString(integrationID),
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type TfNotificationModel struct {
TeamID types.String `tfsdk:"team_id"`
TeamName types.String `tfsdk:"team_name"`
NotifierID types.String `tfsdk:"notifier_id"`
IntegrationID types.String `tfsdk:"integration_id"`
TypeName types.String `tfsdk:"type_name"`
ChannelName types.String `tfsdk:"channel_name"`
VictorOpsAPIKey types.String `tfsdk:"victor_ops_api_key"`
Expand Down Expand Up @@ -321,6 +322,9 @@ func (r *alertConfigurationRS) Schema(ctx context.Context, req resource.SchemaRe
Computed: true,
Optional: true,
},
"integration_id": schema.StringAttribute{
Optional: true,
},
"type_name": schema.StringAttribute{
Required: true,
Validators: []validator.String{
Expand Down
3 changes: 2 additions & 1 deletion website/docs/d/alert_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Notifications to send when an alert condition is detected.
- `WEBHOOK`
- `MICROSOFT_TEAMS`

* `integration_id` - The id of the associated integration, the credentials of which to use for requests.
* `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.
Expand All @@ -235,4 +236,4 @@ Notifications to send when an alert condition is detected.
* `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/)
See detailed information for arguments and attributes: [MongoDB API Alert Configuration](https://docs.atlas.mongodb.com/reference/api/alert-configurations-get-config/)
3 changes: 2 additions & 1 deletion website/docs/d/alert_configurations.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Notifications to send when an alert condition is detected.
- `WEBHOOK`
- `MICROSOFT_TEAMS`

* `integration_id` - The id of the associated integration, the credentials of which to use for requests.
* `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.
Expand All @@ -180,4 +181,4 @@ Notifications to send when an alert condition is detected.
* `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.
Or refer to the individual resource or data_source documentation on alert configuration.
1 change: 1 addition & 0 deletions website/docs/d/third_party_integration.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resource "mongodbatlas_third_party_integration" "test_datadog" {
data "mongodbatlas_third_party_integration" "test" {
project_id = mongodbatlas_third_party_integration.test_datadog.project_id
type = "DATADOG"
}
```

Expand Down
17 changes: 17 additions & 0 deletions website/docs/r/alert_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ resource "mongodbatlas_alert_configuration" "test" {
}
```

### Create third party notification using credentials from existing third party integration


```terraform
resource "mongodbatlas_alert_configuration" "test" {
project_id = "PROJECT ID"
enabled = true
event_type = "USERS_WITHOUT_MULTI_FACTOR_AUTH"
notification {
type_name = "PAGER_DUTY"
integration_id = "THIRD PARTY INTEGRATION ID"
}
}
```

## Argument Reference

* `project_id` - (Required) The ID of the project where the alert configuration will create.
Expand Down Expand Up @@ -223,6 +239,7 @@ List of notifications to send when an alert condition is detected.
- `WEBHOOK`
- `MICROSOFT_TEAMS`

* `integration_id` - The id of the associated integration, the credentials of which to use for requests.
* `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.
Expand Down

0 comments on commit 58f6c3b

Please sign in to comment.