Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTMDB-311: Feature Add: Prometheus and Microsoft Team to the Third Party Integration Settings #706

Merged
merged 14 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ require (
github.com/mwielbut/pointy v1.1.0
github.com/spf13/cast v1.4.1
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f
go.mongodb.org/atlas v0.15.1-0.20220215171307-4b760c3c624f
go.mongodb.org/atlas v0.15.1-0.20220330015822-18ef33419ce7
go.mongodb.org/realm v0.1.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,8 @@ go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsX
go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M=
go.mongodb.org/atlas v0.15.1-0.20220215171307-4b760c3c624f h1:IvKkFdSSBLC5kqB1X87vn8CRAI7eXoMSK7u2lG+WUg8=
go.mongodb.org/atlas v0.15.1-0.20220215171307-4b760c3c624f/go.mod h1:lQhRHIxc6jQHEK3/q9WLu/SdBkPj2fQYhjLGUF6Z3U8=
go.mongodb.org/atlas v0.15.1-0.20220330015822-18ef33419ce7 h1:nJjUIAkZMJ07WCYDlvqnZPPfOkGUdKJj1m9nPOggibw=
go.mongodb.org/atlas v0.15.1-0.20220330015822-18ef33419ce7/go.mod h1:lQhRHIxc6jQHEK3/q9WLu/SdBkPj2fQYhjLGUF6Z3U8=
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
28 changes: 28 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_third_party_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,34 @@ func thirdPartyIntegrationSchema() *schema.Resource {
Sensitive: true,
Computed: true,
},
"name": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"microsoft_teams_webhook_url": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"user_name": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"service_discovery": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"scheme": {
Type: schema.TypeString,
Optional: true,
},
"enabled": {
Type: schema.TypeString,
Optional: true,
},
andreaangiolillo marked this conversation as resolved.
Show resolved Hide resolved
},
}
}
Expand Down
86 changes: 70 additions & 16 deletions mongodbatlas/data_source_mongodbatlas_third_party_integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,28 @@ func flattenIntegrations(integrations *matlas.ThirdPartyIntegrations, projectID

func integrationToSchema(integration *matlas.ThirdPartyIntegration) map[string]interface{} {
out := map[string]interface{}{
"type": integration.Type,
"license_key": integration.LicenseKey,
"account_id": integration.AccountID,
"write_token": integration.WriteToken,
"read_token": integration.ReadToken,
"api_key": integration.APIKey,
"region": integration.Region,
"service_key": integration.ServiceKey,
"api_token": integration.APIToken,
"team_name": integration.TeamName,
"channel_name": integration.ChannelName,
"routing_key": integration.RoutingKey,
"flow_name": integration.FlowName,
"org_name": integration.OrgName,
"url": integration.URL,
"secret": integration.Secret,
"type": integration.Type,
"license_key": integration.LicenseKey,
"account_id": integration.AccountID,
"write_token": integration.WriteToken,
"read_token": integration.ReadToken,
"api_key": integration.APIKey,
"region": integration.Region,
"service_key": integration.ServiceKey,
"api_token": integration.APIToken,
"team_name": integration.TeamName,
"channel_name": integration.ChannelName,
"routing_key": integration.RoutingKey,
"flow_name": integration.FlowName,
"org_name": integration.OrgName,
"url": integration.URL,
"secret": integration.Name,
"name": integration.Secret,
"microsoft_teams_webhook_url": integration.MicrosoftTeamsWebhookURL,
"user_name": integration.UserName,
"service_duscovery": integration.ServiceDiscovery,
"scheme": integration.Scheme,
"enabled": integration.Enabled,
}

// removing optional empty values, terraform complains about unexpected values even though they're empty
Expand Down Expand Up @@ -166,6 +172,30 @@ func schemaToIntegration(in *schema.ResourceData) (out *matlas.ThirdPartyIntegra
out.Secret = secret.(string)
}

if name, ok := in.GetOk("name"); ok {
out.Name = name.(string)
}

if microsoftTeamsWebhookURL, ok := in.GetOk("microsoft_teams_webhook_url"); ok {
out.MicrosoftTeamsWebhookURL = microsoftTeamsWebhookURL.(string)
}

if userName, ok := in.GetOk("user_name"); ok {
out.UserName = userName.(string)
}

if serviceDiscovery, ok := in.GetOk("service_discovery"); ok {
out.ServiceDiscovery = serviceDiscovery.(string)
}

if scheme, ok := in.GetOk("scheme"); ok {
out.Scheme = scheme.(string)
}

if enabled, ok := in.GetOk("enabled"); ok {
out.Enabled = enabled.(string)
}

return out
}

Expand Down Expand Up @@ -229,4 +259,28 @@ func updateIntegrationFromSchema(d *schema.ResourceData, integration *matlas.Thi
if d.HasChange("secret") {
integration.Secret = d.Get("secret").(string)
}

if d.HasChange("name") {
integration.Name = d.Get("name").(string)
}

if d.HasChange("microsoft_teams_webhook_url") {
integration.MicrosoftTeamsWebhookURL = d.Get("microsoft_teams_webhook_url").(string)
}

if d.HasChange("user_name") {
integration.UserName = d.Get("user_name").(string)
}

if d.HasChange("service_discovery") {
integration.ServiceDiscovery = d.Get("service_discovery").(string)
}

if d.HasChange("scheme") {
integration.Scheme = d.Get("scheme").(string)
}

if d.HasChange("enabled") {
integration.Enabled = d.Get("enabled").(string)
}
}
46 changes: 39 additions & 7 deletions mongodbatlas/resource_mongodbatlas_third_party_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ var integrationTypes = []string{
"VICTOR_OPS",
"FLOWDOCK",
"WEBHOOK",
"MICROSOFT_TEAMS",
"PROMETHEUS",
}

var requiredPerType = map[string][]string{
"PAGER_DUTY": {"service_key"},
"DATADOG": {"api_key", "region"},
"NEW_RELIC": {"license_key", "account_id", "write_token", "read_token"},
"OPS_GENIE": {"api_key", "region"},
"VICTOR_OPS": {"api_key"},
"FLOWDOCK": {"flow_name", "api_token", "org_name"},
"WEBHOOK": {"url"},
"PAGER_DUTY": {"service_key"},
"DATADOG": {"api_key", "region"},
"NEW_RELIC": {"license_key", "account_id", "write_token", "read_token"},
"OPS_GENIE": {"api_key", "region"},
"VICTOR_OPS": {"api_key"},
"FLOWDOCK": {"flow_name", "api_token", "org_name"},
"WEBHOOK": {"url"},
"MICROSOFT_TEAMS": {"name", "microsoft_teams_webhook_url"},
"PROMETHEUS": {"user_name", "service_discovery", "scheme", "enabled"},
}

func resourceMongoDBAtlasThirdPartyIntegration() *schema.Resource {
Expand Down Expand Up @@ -120,6 +124,34 @@ func resourceMongoDBAtlasThirdPartyIntegration() *schema.Resource {
Optional: true,
Sensitive: true,
},
"name": {
Type: schema.TypeString,
Sensitive: true,
andreaangiolillo marked this conversation as resolved.
Show resolved Hide resolved
Optional: true,
},
"microsoft_teams_webhook_url": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"user_name": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"service_discovery": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
},
"scheme": {
Type: schema.TypeString,
Optional: true,
},
"enabled": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand Down
10 changes: 10 additions & 0 deletions website/docs/d/third_party_integration.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ data "mongodbatlas_third_party_integration" "test" {
* VICTOR_OPS
* FLOWDOCK
* WEBHOOK
* MICROSOFT_TEAMS
* PROMETHEUS


## Attributes Reference
Expand Down Expand Up @@ -74,5 +76,13 @@ Additional values based on Type
* `WEBHOOK`
* `url` - Your webhook URL.
* `secret` - An optional field for your webhook secret.
* `MICROSOFT_TEAMS`
* `name` - Your Microsoft Teams incoming webhook name.
* `microsoft_teams_webhook_url` - Your Microsoft Teams incoming webhook URL.
* `PROMETHEUS`
* `user_name` - Your Prometheus username.
* `service_discovery` - Indicates which service discovery method is used, either file or http.
* `scheme` - Your Prometheus protocol scheme configured for requests.
* `enabled` - Whether your cluster has Prometheus enabled.

See [MongoDB Atlas API](https://docs.atlas.mongodb.com/reference/api/third-party-integration-settings-get-one/) Documentation for more information.
8 changes: 8 additions & 0 deletions website/docs/d/third_party_integrations.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,13 @@ Additional values based on Type
* `WEBHOOK`
* `url` - Your webhook URL.
* `secret` - An optional field for your webhook secret.
* `MICROSOFT_TEAMS`
andreaangiolillo marked this conversation as resolved.
Show resolved Hide resolved
* `name` - Your Microsoft Teams incoming webhook name.
* `microsoft_teams_webhook_url` - Your Microsoft Teams incoming webhook URL.
* `PROMETHEUS`
* `user_name` - Your Prometheus username.
* `service_discovery` - Indicates which service discovery method is used, either file or http.
* `scheme` - Your Prometheus protocol scheme configured for requests.
* `enabled` - Whether your cluster has Prometheus enabled.

See [MongoDB Atlas API](https://docs.atlas.mongodb.com/reference/api/third-party-integration-settings-get-all/) Documentation for more information.