Skip to content

Commit

Permalink
INTMDB-373: Add new notification parameters to the mongodbatlas_alert…
Browse files Browse the repository at this point in the history
…_config resource (#877)

* Add support for MS Teams SDK webhook

* make fmt

* Update documentation add Webhook

* Update docs

* Update to v0.18
  • Loading branch information
martinstibbe authored Oct 26, 2022
1 parent 56885d9 commit 21fc5f0
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 47 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/mwielbut/pointy v1.1.0
github.com/spf13/cast v1.5.0
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f
go.mongodb.org/atlas v0.16.1-0.20220823081124-819fb5448bfe
go.mongodb.org/atlas v0.18.1-0.20221026132354-ca26a1fdb0a6
go.mongodb.org/realm v0.1.0
)

Expand Down Expand Up @@ -97,7 +97,7 @@ require (
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/openlyinc/pointy v1.1.2 // indirect
github.com/openlyinc/pointy v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/otp v1.3.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
github.com/openlyinc/pointy v1.1.2 h1:LywVV2BWC5Sp5v7FoP4bUD+2Yn5k0VNeRbU5vq9jUMY=
github.com/openlyinc/pointy v1.1.2/go.mod h1:w2Sytx+0FVuMKn37xpXIAyBNhFNBIJGR/v2m7ik1WtM=
github.com/openlyinc/pointy v1.2.0 h1:vbb/WoPbshyTH8j3/XYu3enlZfv+NHxAD15qTm1zbk0=
github.com/openlyinc/pointy v1.2.0/go.mod h1:JodZOTJoBNaAQHeU0F/SwA4PL0lg4pKF7fYFpX291P0=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
Expand Down Expand Up @@ -927,6 +929,10 @@ go.etcd.io/etcd v0.0.0-20200513171258-e048e166ab9c/go.mod h1:xCI7ZzBfRuGgBXyXO6y
go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M=
go.mongodb.org/atlas v0.16.1-0.20220823081124-819fb5448bfe h1:jmRFnzQejpiVo7xsPSCUYOqIzltc9Z95UuLr5fy5+qM=
go.mongodb.org/atlas v0.16.1-0.20220823081124-819fb5448bfe/go.mod h1:GUuW7/ZrHzCO0o47aiqhokN0N6i0GM3yraRyHIBTykU=
go.mongodb.org/atlas v0.16.1-0.20220922005646-8a86dd63e243 h1:KkZ900dLCu2U3D+qoY1y7m/zQRzqDE1+QWQbx7rh154=
go.mongodb.org/atlas v0.16.1-0.20220922005646-8a86dd63e243/go.mod h1:GUuW7/ZrHzCO0o47aiqhokN0N6i0GM3yraRyHIBTykU=
go.mongodb.org/atlas v0.18.1-0.20221026132354-ca26a1fdb0a6 h1:lGmbUUTcdfXt0O1QN2z65B3mAYrUXUerqj3RZWg7Aao=
go.mongodb.org/atlas v0.18.1-0.20221026132354-ca26a1fdb0a6/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M=
go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM=
go.mozilla.org/mozlog v0.0.0-20170222151521-4bb13139d403/go.mod h1:jHoPAGnDrCy6kaI2tAze5Prf0Nr0w/oNkROt2lw3n3o=
Expand Down
15 changes: 15 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_alert_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@ func dataSourceMongoDBAtlasAlertConfiguration() *schema.Resource {
Type: schema.TypeString,
},
},
"microsoft_teams_webhook_url": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"webhook_secret": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"webhook_url": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
},
},
},
Expand Down
111 changes: 66 additions & 45 deletions mongodbatlas/resource_mongodbatlas_alert_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func resourceMongoDBAtlasAlertConfiguration() *schema.Resource {
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"EMAIL", "SMS", pagerDuty, "SLACK",
"FLOWDOCK", "DATADOG", opsGenie, victorOps,
"WEBHOOK", "USER", "TEAM", "GROUP", "ORG"}, false),
"WEBHOOK", "USER", "TEAM", "GROUP", "ORG", "MICROSOFT_TEAMS"}, false),
},
"username": {
Type: schema.TypeString,
Expand All @@ -285,6 +285,21 @@ func resourceMongoDBAtlasAlertConfiguration() *schema.Resource {
Type: schema.TypeString,
},
},
"microsoft_teams_webhook_url": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"webhook_secret": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"webhook_url": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -685,28 +700,31 @@ func expandAlertConfigurationNotification(d *schema.ResourceData) ([]matlas.Noti
}
}
notifications[i] = matlas.Notification{
APIToken: cast.ToString(v["api_token"]),
ChannelName: cast.ToString(v["channel_name"]),
DatadogAPIKey: cast.ToString(v["datadog_api_key"]),
DatadogRegion: cast.ToString(v["datadog_region"]),
DelayMin: pointy.Int(v["delay_min"].(int)),
EmailAddress: cast.ToString(v["email_address"]),
EmailEnabled: pointy.Bool(v["email_enabled"].(bool)),
FlowdockAPIToken: cast.ToString(v["flowdock_api_token"]),
FlowName: cast.ToString(v["flow_name"]),
IntervalMin: cast.ToInt(v["interval_min"]),
MobileNumber: cast.ToString(v["mobile_number"]),
OpsGenieAPIKey: cast.ToString(v["ops_genie_api_key"]),
OpsGenieRegion: cast.ToString(v["ops_genie_region"]),
OrgName: cast.ToString(v["org_name"]),
ServiceKey: cast.ToString(v["service_key"]),
SMSEnabled: pointy.Bool(v["sms_enabled"].(bool)),
TeamID: cast.ToString(v["team_id"]),
TypeName: cast.ToString(v["type_name"]),
Username: cast.ToString(v["username"]),
VictorOpsAPIKey: cast.ToString(v["victor_ops_api_key"]),
VictorOpsRoutingKey: cast.ToString(v["victor_ops_routing_key"]),
Roles: cast.ToStringSlice(v["roles"]),
APIToken: cast.ToString(v["api_token"]),
ChannelName: cast.ToString(v["channel_name"]),
DatadogAPIKey: cast.ToString(v["datadog_api_key"]),
DatadogRegion: cast.ToString(v["datadog_region"]),
DelayMin: pointy.Int(v["delay_min"].(int)),
EmailAddress: cast.ToString(v["email_address"]),
EmailEnabled: pointy.Bool(v["email_enabled"].(bool)),
FlowdockAPIToken: cast.ToString(v["flowdock_api_token"]),
FlowName: cast.ToString(v["flow_name"]),
IntervalMin: cast.ToInt(v["interval_min"]),
MobileNumber: cast.ToString(v["mobile_number"]),
OpsGenieAPIKey: cast.ToString(v["ops_genie_api_key"]),
OpsGenieRegion: cast.ToString(v["ops_genie_region"]),
OrgName: cast.ToString(v["org_name"]),
ServiceKey: cast.ToString(v["service_key"]),
SMSEnabled: pointy.Bool(v["sms_enabled"].(bool)),
TeamID: cast.ToString(v["team_id"]),
TypeName: cast.ToString(v["type_name"]),
Username: cast.ToString(v["username"]),
VictorOpsAPIKey: cast.ToString(v["victor_ops_api_key"]),
VictorOpsRoutingKey: cast.ToString(v["victor_ops_routing_key"]),
Roles: cast.ToStringSlice(v["roles"]),
MicrosoftTeamsWebhookURL: cast.ToString(v["microsoft_teams_webhook_url"]),
WebhookSecret: cast.ToString(v["webhook_secret"]),
WebhookURL: cast.ToString(v["webhook_url"]),
}
}

Expand All @@ -718,28 +736,31 @@ func flattenAlertConfigurationNotifications(notifications []matlas.Notification)

for i := range notifications {
nts[i] = map[string]interface{}{
"api_token": notifications[i].APIToken,
"channel_name": notifications[i].ChannelName,
"datadog_api_key": notifications[i].DatadogAPIKey,
"datadog_region": notifications[i].DatadogRegion,
"delay_min": notifications[i].DelayMin,
"email_address": notifications[i].EmailAddress,
"email_enabled": notifications[i].EmailEnabled,
"flowdock_api_token": notifications[i].FlowdockAPIToken,
"flow_name": notifications[i].FlowName,
"interval_min": notifications[i].IntervalMin,
"mobile_number": notifications[i].MobileNumber,
"ops_genie_api_key": notifications[i].OpsGenieAPIKey,
"ops_genie_region": notifications[i].OpsGenieRegion,
"org_name": notifications[i].OrgName,
"service_key": notifications[i].ServiceKey,
"sms_enabled": notifications[i].SMSEnabled,
"team_id": notifications[i].TeamID,
"team_name": notifications[i].TeamName,
"type_name": notifications[i].TypeName,
"username": notifications[i].Username,
"victor_ops_api_key": notifications[i].VictorOpsAPIKey,
"victor_ops_routing_key": notifications[i].VictorOpsRoutingKey,
"api_token": notifications[i].APIToken,
"channel_name": notifications[i].ChannelName,
"datadog_api_key": notifications[i].DatadogAPIKey,
"datadog_region": notifications[i].DatadogRegion,
"delay_min": notifications[i].DelayMin,
"email_address": notifications[i].EmailAddress,
"email_enabled": notifications[i].EmailEnabled,
"flowdock_api_token": notifications[i].FlowdockAPIToken,
"flow_name": notifications[i].FlowName,
"interval_min": notifications[i].IntervalMin,
"mobile_number": notifications[i].MobileNumber,
"ops_genie_api_key": notifications[i].OpsGenieAPIKey,
"ops_genie_region": notifications[i].OpsGenieRegion,
"org_name": notifications[i].OrgName,
"service_key": notifications[i].ServiceKey,
"sms_enabled": notifications[i].SMSEnabled,
"team_id": notifications[i].TeamID,
"team_name": notifications[i].TeamName,
"type_name": notifications[i].TypeName,
"username": notifications[i].Username,
"victor_ops_api_key": notifications[i].VictorOpsAPIKey,
"victor_ops_routing_key": notifications[i].VictorOpsRoutingKey,
"microsoft_teams_webhook_url": notifications[i].MicrosoftTeamsWebhookURL,
"webhook_secret": notifications[i].WebhookSecret,
"webhook_url": notifications[i].WebhookURL,
}

// We need to validate it due to the datasource haven't the roles attribute
Expand Down
4 changes: 4 additions & 0 deletions website/docs/d/alert_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,14 @@ Notifications to send when an alert condition is detected.
- `USER`
- `VICTOR_OPS`
- `WEBHOOK`
- `MICROSOFT_TEAMS`

* `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`.

Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/alert_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,14 @@ List of notifications to send when an alert condition is detected.
- `USER`
- `VICTOR_OPS`
- `WEBHOOK`
- `MICROSOFT_TEAMS`

* `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` - Optional authentication secret for the `WEBHOOK` notifications type.
* `webhook_url` - Target URL for the `WEBHOOK` notifications type.
* `microsoft_teams_webhook_url` - Microsoft Teams Webhook Uniform Resource Locator (URL) that MongoDB Cloud needs to send this notification via Microsoft Teams. Required if `type_name` is `MICROSOFT_TEAMS`. If the URL later becomes invalid, MongoDB Cloud sends an email to the project owners. If the key remains invalid, MongoDB Cloud removes it.
* `roles` - Optional. One or more roles that receive the configured alert. If you include this field, Atlas sends alerts only to users assigned the roles you specify in the array. If you omit this field, Atlas sends alerts to users assigned any role. This parameter is only valid if `type_name` is set to `ORG`, `GROUP`, or `USER`.
Accepted values are:

Expand Down

0 comments on commit 21fc5f0

Please sign in to comment.