From 5a738375f84fed8ebc97b5d6b107e679891e3356 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Tue, 29 Mar 2022 20:59:06 -0500 Subject: [PATCH 01/14] INTMDB-311: Feature Add: Promethus and Microsoft Team to the Third Party Integration Settings --- ...e_mongodbatlas_third_party_integrations.go | 62 ++++++++++++++----- ...ce_mongodbatlas_third_party_integration.go | 46 +++++++++++--- 2 files changed, 85 insertions(+), 23 deletions(-) diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go index 313a46efbd..5f2d5a12cd 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go @@ -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 @@ -166,6 +172,30 @@ func schemaToIntegration(in *schema.ResourceData) (out *matlas.ThirdPartyIntegra out.Secret = secret.(string) } + if secret, ok := in.GetOk("secret"); ok { + 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 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 } diff --git a/mongodbatlas/resource_mongodbatlas_third_party_integration.go b/mongodbatlas/resource_mongodbatlas_third_party_integration.go index bbb10a27c4..a805210a38 100644 --- a/mongodbatlas/resource_mongodbatlas_third_party_integration.go +++ b/mongodbatlas/resource_mongodbatlas_third_party_integration.go @@ -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 { @@ -120,6 +124,34 @@ func resourceMongoDBAtlasThirdPartyIntegration() *schema.Resource { Optional: true, Sensitive: 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, + }, }, } } From e3b0cd236aeb83aeaa71252eea97038d78f768d4 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Tue, 29 Mar 2022 21:33:41 -0500 Subject: [PATCH 02/14] Update documentation add additional schema values --- ...ce_mongodbatlas_third_party_integration.go | 28 ++++++++++++++++ ...e_mongodbatlas_third_party_integrations.go | 32 ++++++++++++++++--- .../docs/d/third_party_integration.markdown | 10 ++++++ .../docs/d/third_party_integrations.markdown | 8 +++++ 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integration.go b/mongodbatlas/data_source_mongodbatlas_third_party_integration.go index cc73a1a0cb..1ecc75906b 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integration.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integration.go @@ -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, + }, }, } } diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go index 5f2d5a12cd..ba13816965 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go @@ -172,10 +172,6 @@ func schemaToIntegration(in *schema.ResourceData) (out *matlas.ThirdPartyIntegra out.Secret = secret.(string) } - if secret, ok := in.GetOk("secret"); ok { - out.Secret = secret.(string) - } - if name, ok := in.GetOk("name"); ok { out.Name = name.(string) } @@ -184,6 +180,10 @@ func schemaToIntegration(in *schema.ResourceData) (out *matlas.ThirdPartyIntegra 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) } @@ -259,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) + } } diff --git a/website/docs/d/third_party_integration.markdown b/website/docs/d/third_party_integration.markdown index 2e15e9f2a4..320e60b5f7 100644 --- a/website/docs/d/third_party_integration.markdown +++ b/website/docs/d/third_party_integration.markdown @@ -40,6 +40,8 @@ data "mongodbatlas_third_party_integration" "test" { * VICTOR_OPS * FLOWDOCK * WEBHOOK + * MICROSOFT_TEAMS + * PROMETHEUS ## Attributes Reference @@ -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. \ No newline at end of file diff --git a/website/docs/d/third_party_integrations.markdown b/website/docs/d/third_party_integrations.markdown index e2f019c7c8..bfa79b993a 100644 --- a/website/docs/d/third_party_integrations.markdown +++ b/website/docs/d/third_party_integrations.markdown @@ -77,5 +77,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-all/) Documentation for more information. \ No newline at end of file From 1dca67959754674146431f756a8bdab83427ea38 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Tue, 29 Mar 2022 22:00:03 -0500 Subject: [PATCH 03/14] Map to temporary branch for testing --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 37da04e378..2571382bf5 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 8b7d343091..e66cc516e8 100644 --- a/go.sum +++ b/go.sum @@ -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= From 06b35e7f2eb768c5b35235cf361f8a240f9b1528 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Tue, 29 Mar 2022 22:04:48 -0500 Subject: [PATCH 04/14] Fix Lint --- .../data_source_mongodbatlas_third_party_integrations.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go index ba13816965..74c8095f7f 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go @@ -176,8 +176,8 @@ func schemaToIntegration(in *schema.ResourceData) (out *matlas.ThirdPartyIntegra out.Name = name.(string) } - if microsoftTeamsWebhookUrl, ok := in.GetOk("microsoft_teams_webhook_url"); ok { - out.MicrosoftTeamsWebhookURL = microsoftTeamsWebhookUrl.(string) + if microsoftTeamsWebhookURL, ok := in.GetOk("microsoft_teams_webhook_url"); ok { + out.MicrosoftTeamsWebhookURL = microsoftTeamsWebhookURL.(string) } if userName, ok := in.GetOk("user_name"); ok { From c21a5091387ccd855003058ab92dc2c20e7737d7 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Sun, 3 Apr 2022 15:25:49 -0500 Subject: [PATCH 05/14] Add boolean field for Prometheus enabled --- go.mod | 2 +- go.sum | 2 ++ .../data_source_mongodbatlas_third_party_integrations.go | 9 +++++++-- .../resource_mongodbatlas_third_party_integration.go | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 2571382bf5..3d0d8f9c58 100644 --- a/go.mod +++ b/go.mod @@ -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.20220330015822-18ef33419ce7 + go.mongodb.org/atlas v0.15.1-0.20220403193624-86b34ba344cd go.mongodb.org/realm v0.1.0 ) diff --git a/go.sum b/go.sum index e66cc516e8..4e9515a1e7 100644 --- a/go.sum +++ b/go.sum @@ -1223,6 +1223,8 @@ go.mongodb.org/atlas v0.15.1-0.20220215171307-4b760c3c624f h1:IvKkFdSSBLC5kqB1X8 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/atlas v0.15.1-0.20220403193624-86b34ba344cd h1:JzkNgRp8xLbm16DJP28+oGf0P765Nl2Xp8yERZ8O/y0= +go.mongodb.org/atlas v0.15.1-0.20220403193624-86b34ba344cd/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= diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go index 74c8095f7f..a110050a8c 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go @@ -83,6 +83,7 @@ func integrationToSchema(integration *matlas.ThirdPartyIntegration) map[string]i "name": integration.Secret, "microsoft_teams_webhook_url": integration.MicrosoftTeamsWebhookURL, "user_name": integration.UserName, + "password": integration.Password, "service_duscovery": integration.ServiceDiscovery, "scheme": integration.Scheme, "enabled": integration.Enabled, @@ -184,6 +185,10 @@ func schemaToIntegration(in *schema.ResourceData) (out *matlas.ThirdPartyIntegra out.UserName = userName.(string) } + if password, ok := in.GetOk("password"); ok { + out.Password = password.(string) + } + if serviceDiscovery, ok := in.GetOk("service_discovery"); ok { out.ServiceDiscovery = serviceDiscovery.(string) } @@ -193,7 +198,7 @@ func schemaToIntegration(in *schema.ResourceData) (out *matlas.ThirdPartyIntegra } if enabled, ok := in.GetOk("enabled"); ok { - out.Enabled = enabled.(string) + out.Enabled = enabled.(bool) } return out @@ -281,6 +286,6 @@ func updateIntegrationFromSchema(d *schema.ResourceData, integration *matlas.Thi } if d.HasChange("enabled") { - integration.Enabled = d.Get("enabled").(string) + integration.Enabled = d.Get("enabled").(bool) } } diff --git a/mongodbatlas/resource_mongodbatlas_third_party_integration.go b/mongodbatlas/resource_mongodbatlas_third_party_integration.go index a805210a38..886bf0cd3f 100644 --- a/mongodbatlas/resource_mongodbatlas_third_party_integration.go +++ b/mongodbatlas/resource_mongodbatlas_third_party_integration.go @@ -149,7 +149,7 @@ func resourceMongoDBAtlasThirdPartyIntegration() *schema.Resource { Optional: true, }, "enabled": { - Type: schema.TypeString, + Type: schema.TypeBool, Optional: true, }, }, From 4a72c83897d96fa9fe3ece3a85361209fc4f17cb Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Mon, 11 Apr 2022 07:38:53 -0500 Subject: [PATCH 06/14] Remove Name from Teams integration --- ...rce_mongodbatlas_third_party_integrations.go | 17 ++++++----------- ...urce_mongodbatlas_third_party_integration.go | 10 +++++----- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go index a110050a8c..471f9ac366 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go @@ -79,12 +79,11 @@ func integrationToSchema(integration *matlas.ThirdPartyIntegration) map[string]i "flow_name": integration.FlowName, "org_name": integration.OrgName, "url": integration.URL, - "secret": integration.Name, - "name": integration.Secret, + "secret": integration.Secret, "microsoft_teams_webhook_url": integration.MicrosoftTeamsWebhookURL, "user_name": integration.UserName, "password": integration.Password, - "service_duscovery": integration.ServiceDiscovery, + "service_discovery": integration.ServiceDiscovery, "scheme": integration.Scheme, "enabled": integration.Enabled, } @@ -173,10 +172,6 @@ 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) } @@ -265,10 +260,6 @@ func updateIntegrationFromSchema(d *schema.ResourceData, integration *matlas.Thi 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) } @@ -277,6 +268,10 @@ func updateIntegrationFromSchema(d *schema.ResourceData, integration *matlas.Thi integration.UserName = d.Get("user_name").(string) } + if d.HasChange("password") { + integration.Password = d.Get("password").(string) + } + if d.HasChange("service_discovery") { integration.ServiceDiscovery = d.Get("service_discovery").(string) } diff --git a/mongodbatlas/resource_mongodbatlas_third_party_integration.go b/mongodbatlas/resource_mongodbatlas_third_party_integration.go index 886bf0cd3f..2ec5bf57eb 100644 --- a/mongodbatlas/resource_mongodbatlas_third_party_integration.go +++ b/mongodbatlas/resource_mongodbatlas_third_party_integration.go @@ -31,8 +31,8 @@ var requiredPerType = map[string][]string{ "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"}, + "MICROSOFT_TEAMS": {"microsoft_teams_webhook_url"}, + "PROMETHEUS": {"user_name", "password", "service_discovery", "scheme", "enabled"}, } func resourceMongoDBAtlasThirdPartyIntegration() *schema.Resource { @@ -124,17 +124,17 @@ func resourceMongoDBAtlasThirdPartyIntegration() *schema.Resource { Optional: true, Sensitive: true, }, - "name": { + "microsoft_teams_webhook_url": { Type: schema.TypeString, Sensitive: true, Optional: true, }, - "microsoft_teams_webhook_url": { + "user_name": { Type: schema.TypeString, Sensitive: true, Optional: true, }, - "user_name": { + "password": { Type: schema.TypeString, Sensitive: true, Optional: true, From e9eb45d3dbc75fe18605f9b1688da3810fd6649c Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Thu, 14 Apr 2022 20:24:15 -0500 Subject: [PATCH 07/14] Remove extra Name field from Teams integration type add examples --- .../.gitignore | 5 + .../Readme.md | 108 ++++++++++++++++++ .../atlas_cluster.tf | 24 ++++ .../database_user.tf | 19 +++ .../ip_access_list.tf | 8 ++ .../project.tf | 7 ++ .../provider.tf | 4 + .../thirdy-party-integration.tf | 15 +++ .../variables.tf | 51 +++++++++ .../versions.tf | 9 ++ ...ce_mongodbatlas_third_party_integration.go | 5 - ...ngodbatlas_third_party_integration_test.go | 39 +++++++ .../docs/d/third_party_integration.markdown | 2 +- 13 files changed, 290 insertions(+), 6 deletions(-) create mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/.gitignore create mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/Readme.md create mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/atlas_cluster.tf create mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/database_user.tf create mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/ip_access_list.tf create mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/project.tf create mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/provider.tf create mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf create mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/variables.tf create mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/versions.tf diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/.gitignore b/examples/MongoDB-Atlas-Third-Party-Integration/.gitignore new file mode 100644 index 0000000000..819a7c364a --- /dev/null +++ b/examples/MongoDB-Atlas-Third-Party-Integration/.gitignore @@ -0,0 +1,5 @@ +iatlaspl.code-workspace +terraform.tfvars +.terraform/ +*.tfstate* + diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/Readme.md b/examples/MongoDB-Atlas-Third-Party-Integration/Readme.md new file mode 100644 index 0000000000..4e0fdb38fd --- /dev/null +++ b/examples/MongoDB-Atlas-Third-Party-Integration/Readme.md @@ -0,0 +1,108 @@ +# Example - A basic example to start with the MongoDB Atlas and Terraform + +This project aims to provide a very straight-forward example of setting up Terraform with MongoDB Atlas. This will create the following resources in MongoDB Atlas: + +- Atlas Project +- MongoDB Cluster - M10 +- Database User +- IP Access List + +You can refer to the MongoDB Atlas documentation to know about the region names used in MongoDB Atlas respective to the Cloud Provider's region name. +[Amazon Web Services (AWS)](https://docs.atlas.mongodb.com/reference/amazon-aws/#amazon-aws) +[Google Cloud Platform (GCP)](https://docs.atlas.mongodb.com/reference/google-gcp/#google-gcp) +[Microsoft Azure](https://docs.atlas.mongodb.com/reference/microsoft-azure/#microsoft-azure) + +## Dependencies + +* Terraform v0.13 or greater +* A MongoDB Atlas account +* provider.mongodbatlas: version = "~> 0.9.1" + +## Usage + +**1\. Ensure your MongoDB Atlas credentials are set up.** + +This can be done using environment variables: + +```bash +export MONGODB_ATLAS_PUBLIC_KEY="xxxx" +export MONGODB_ATLAS_PRIVATE_KEY="xxxx" +``` + +... or follow as in the `variables.tf` file and create **terraform.tfvars** file with all the variable values and make sure **not to commit it**. + + +> **IMPORTANT** Hard-coding your MongoDB Atlas programmatic API key pair into a Terraform configuration is not recommended. Consider the risks, especially the inadvertent submission of a configuration file containing secrets to a public repository. + + +**2\. Review the Terraform plan.** + +Execute the below command and ensure you are happy with the plan. + +``` bash +$ terraform plan +``` + +This project currently creates the below deployments: + +- Atlas Project +- MongoDB cluster - M10 +- Database User +- IP Access list + +**3\. Execute the Terraform apply.** + +Now execute the plan to provision the MongoDB Atlas resources. + +``` bash +$ terraform apply +``` + +**4\. Destroy the resources.** + +Once you are finished your testing, ensure you destroy the resources to avoid unnecessary charges. + +``` bash +$ terraform destroy +``` + +**Important Point** + +You can fetch the connection string as per the use case by following the MongoDB Atlas documentation on [Connect to your cluster](https://docs.atlas.mongodb.com/tutorial/connect-to-your-cluster/index.html). + +Or to fetch the connection string using terraform follow the below steps: + +```hcl +output "atlasclusterstring" { + value = mongodbatlas_cluster.cluster.connection_strings +} +``` +**Outputs:** +```hcl +atlasclusterstring = [ + { + "aws_private_link" = { + "vpce-0ebb76559e8affc96" = "mongodb://pl-0-us-east-1.za3fb.mongodb.net:1024,pl-0-us-east-1.za3fb.mongodb.net:1025,pl-0-us-east-1.za3fb.mongodb.net:1026/?ssl=true&authSource=admin&replicaSet=atlas-d177ke-shard-0" + } + "aws_private_link_srv" = { + "vpce-0ebb76559e8affc96" = "mongodb+srv://mongodb-atlas-pl-0.za3fb.mongodb.net" + } + "private" = "" + "private_srv" = "" + "standard" = "mongodb://mongodb-atlas-shard-00-00.za3fb.mongodb.net:27017,mongodb-atlas-shard-00-01.za3fb.mongodb.net:27017,mongodb-atlas-shard-00-02.za3fb.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-d177ke-shard-0" + "standard_srv" = "mongodb+srv://mongodb-atlas.za3fb.mongodb.net" + }, +] +``` + +To fetch a particular connection string, use the **lookup()** function of terraform as below: + +``` +output "plstring" { + value = lookup(mongodbatlas_cluster.cluster.connection_strings[0].aws_private_link_srv, aws_vpc_endpoint.ptfe_service.id) +} +``` +**Output:** +``` +plstring = mongodb+srv://cluster-atlas-pl-0.za3fb.mongodb.net +``` diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/atlas_cluster.tf b/examples/MongoDB-Atlas-Third-Party-Integration/atlas_cluster.tf new file mode 100644 index 0000000000..f07552a47c --- /dev/null +++ b/examples/MongoDB-Atlas-Third-Party-Integration/atlas_cluster.tf @@ -0,0 +1,24 @@ +resource "mongodbatlas_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + mongo_db_major_version = var.mongodbversion + cluster_type = "REPLICASET" + replication_specs { + num_shards = 1 + regions_config { + region_name = var.region + electable_nodes = 3 + priority = 7 + read_only_nodes = 0 + } + } + # Provider Settings "block" + cloud_backup = true + auto_scaling_disk_gb_enabled = true + provider_name = var.cloud_provider + provider_instance_size_name = "M10" +} +output "connection_strings" { + value = mongodbatlas_cluster.cluster.connection_strings[0].standard_srv +} + diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/database_user.tf b/examples/MongoDB-Atlas-Third-Party-Integration/database_user.tf new file mode 100644 index 0000000000..15e2f3ff9e --- /dev/null +++ b/examples/MongoDB-Atlas-Third-Party-Integration/database_user.tf @@ -0,0 +1,19 @@ +# DATABASE USER [Configure Database Users](https://docs.atlas.mongodb.com/security-add-mongodb-users/) +resource "mongodbatlas_database_user" "user" { + username = var.dbuser + password = var.dbuser_password + project_id = mongodbatlas_project.project.id + auth_database_name = "admin" + + roles { + role_name = "readWrite" + database_name = var.database_name # The database name and collection name need not exist in the cluster before creating the user. + } + labels { + key = "Name" + value = "DB User1" + } +} +output "user1" { + value = mongodbatlas_database_user.user.username +} diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/ip_access_list.tf b/examples/MongoDB-Atlas-Third-Party-Integration/ip_access_list.tf new file mode 100644 index 0000000000..0e4701b2f1 --- /dev/null +++ b/examples/MongoDB-Atlas-Third-Party-Integration/ip_access_list.tf @@ -0,0 +1,8 @@ +resource "mongodbatlas_project_ip_access_list" "ip" { + project_id = mongodbatlas_project.project.id + ip_address = var.ip_address + comment = "IP Address for accessing the cluster" +} +output "ipaccesslist" { + value = mongodbatlas_project_ip_access_list.ip.ip_address +} diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/project.tf b/examples/MongoDB-Atlas-Third-Party-Integration/project.tf new file mode 100644 index 0000000000..30e0719097 --- /dev/null +++ b/examples/MongoDB-Atlas-Third-Party-Integration/project.tf @@ -0,0 +1,7 @@ +resource "mongodbatlas_project" "project" { + name = var.project_name + org_id = var.org_id +} +output "project_name" { + value = mongodbatlas_project.project.name +} diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/provider.tf b/examples/MongoDB-Atlas-Third-Party-Integration/provider.tf new file mode 100644 index 0000000000..18c430e061 --- /dev/null +++ b/examples/MongoDB-Atlas-Third-Party-Integration/provider.tf @@ -0,0 +1,4 @@ +provider "mongodbatlas" { + public_key = var.public_key + private_key = var.private_key +} diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf b/examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf new file mode 100644 index 0000000000..2a7d6d5d15 --- /dev/null +++ b/examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf @@ -0,0 +1,15 @@ +resource "mongodbatlas_third_party_integration" "test_msteams" { + project_id = mongodbatlas_project.project.id + type = "MICROSOFT_TEAMS" + microsoft_teams_webhook_url = "https://mongodb0.webhook.office.com/webhookb2/97142c7c-15e8-47de-9a7a-355183e89a68@c96563a8-841b-4ef9-af16-33548de0c958/IncomingWebhook/c0337c212d1f41149d754e9f4e0229b6/fa477bb6-9b05-473a-be3e-1157d9633ee8" +} + +resource "mongodbatlas_third_party_integration" "test_prometheus" { + project_id = mongodbatlas_project.project.id + type = "PROMETHEUS" + user_name = "prom_user_621952567c87684fd69b0101" + password = "KeQvcbkBhrNeuhVE" + service_discovery = "file" + scheme = "https" + enabled = true +} diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/variables.tf b/examples/MongoDB-Atlas-Third-Party-Integration/variables.tf new file mode 100644 index 0000000000..4307ced129 --- /dev/null +++ b/examples/MongoDB-Atlas-Third-Party-Integration/variables.tf @@ -0,0 +1,51 @@ +variable "public_key" { + type = string + description = "Public Programmatic API key to authenticate to Atlas" +} +variable "private_key" { + type = string + description = "Private Programmatic API key to authenticate to Atlas" +} +variable "org_id" { + type = string + description = "MongoDB Organization ID" +} +variable "project_name" { + type = string + description = "The MongoDB Atlas Project Name" +} +variable "cluster_name" { + type = string + description = "The MongoDB Atlas Cluster Name" +} +variable "cloud_provider" { + type = string + description = "The cloud provider to use, must be AWS, GCP or AZURE" +} +variable "region" { + type = string + description = "MongoDB Atlas Cluster Region, must be a region for the provider given" +} +variable "mongodbversion" { + type = string + description = "The Major MongoDB Version" +} +variable "dbuser" { + type = string + description = "MongoDB Atlas Database User Name" +} +variable "dbuser_password" { + type = string + description = "MongoDB Atlas Database User Password" +} +variable "database_name" { + type = string + description = "The database in the cluster to limit the database user to, the database does not have to exist yet" +} +variable "ip_address" { + type = string + description = "The IP address that the cluster will be accessed from, can also be a CIDR range or AWS security group" +} + + + diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf b/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf new file mode 100644 index 0000000000..1ec3e5dab5 --- /dev/null +++ b/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + version = "1.3.2" + } + } + required_version = ">= 0.13" +} diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integration.go b/mongodbatlas/data_source_mongodbatlas_third_party_integration.go index 1ecc75906b..30caadc47d 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integration.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integration.go @@ -105,11 +105,6 @@ 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, diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go b/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go index 325452194e..4273308129 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go @@ -84,6 +84,27 @@ const ( url = "%[4]s" } ` + + MICROSOFT_TEAMS = ` + resource "mongodbatlas_third_party_integration" "%[1]s" { + project_id = "%[2]s" + type = "%[3]s" + microsoft_teams_webhook_url = "%[4]s" + } + ` + + PROMETHEUS = ` + resource "mongodbatlas_third_party_integration" "%[1]s" { + project_id = "%[2]s" + type = "%[3]s" + user_name = "%[4]s" + password = "%[5]s" + service_discovery = "%[6]s" + scheme = "%[7]s" + enabled = "%[8]s" + } + ` + alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" numeric = "0123456789" alphaNum = alphabet + numeric @@ -202,6 +223,24 @@ func testAccMongoDBAtlasThirdPartyIntegrationResourceConfig(config *thirdPartyCo config.Integration.Type, config.Integration.URL, ) + case "MICROSOFT_TEAMS": + return fmt.Sprintf(WEBHOOK, + config.Name, + config.ProjectID, + config.Integration.Type, + config.Integration.MicrosoftTeamsWebhookURL, + ) + case "PROMETHEUS": + return fmt.Sprintf(WEBHOOK, + config.Name, + config.ProjectID, + config.Integration.Type, + config.Integration.UserName, + config.Integration.Password, + config.Integration.ServiceDiscovery, + config.Integration.Scheme, + config.Integration.Enabled, + ) default: return fmt.Sprintf(Unknown3rdParty, config.Name, diff --git a/website/docs/d/third_party_integration.markdown b/website/docs/d/third_party_integration.markdown index 320e60b5f7..5b996f6e63 100644 --- a/website/docs/d/third_party_integration.markdown +++ b/website/docs/d/third_party_integration.markdown @@ -77,10 +77,10 @@ Additional values based on Type * `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. + * `password` - Your Prometheus password. * `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. From a4852d116a31d59a435011cae8235acc05889364 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Thu, 14 Apr 2022 20:24:49 -0500 Subject: [PATCH 08/14] Terraform fmt --- .../thirdy-party-integration.tf | 20 +++++++++---------- .../versions.tf | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf b/examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf index 2a7d6d5d15..51be95d466 100644 --- a/examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf +++ b/examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf @@ -1,15 +1,15 @@ resource "mongodbatlas_third_party_integration" "test_msteams" { - project_id = mongodbatlas_project.project.id - type = "MICROSOFT_TEAMS" - microsoft_teams_webhook_url = "https://mongodb0.webhook.office.com/webhookb2/97142c7c-15e8-47de-9a7a-355183e89a68@c96563a8-841b-4ef9-af16-33548de0c958/IncomingWebhook/c0337c212d1f41149d754e9f4e0229b6/fa477bb6-9b05-473a-be3e-1157d9633ee8" + project_id = mongodbatlas_project.project.id + type = "MICROSOFT_TEAMS" + microsoft_teams_webhook_url = "https://mongodb0.webhook.office.com/webhookb2/97142c7c-15e8-47de-9a7a-355183e89a68@c96563a8-841b-4ef9-af16-33548de0c958/IncomingWebhook/c0337c212d1f41149d754e9f4e0229b6/fa477bb6-9b05-473a-be3e-1157d9633ee8" } resource "mongodbatlas_third_party_integration" "test_prometheus" { - project_id = mongodbatlas_project.project.id - type = "PROMETHEUS" - user_name = "prom_user_621952567c87684fd69b0101" - password = "KeQvcbkBhrNeuhVE" - service_discovery = "file" - scheme = "https" - enabled = true + project_id = mongodbatlas_project.project.id + type = "PROMETHEUS" + user_name = "prom_user_621952567c87684fd69b0101" + password = "KeQvcbkBhrNeuhVE" + service_discovery = "file" + scheme = "https" + enabled = true } diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf b/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf index 1ec3e5dab5..6658b2f840 100644 --- a/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf +++ b/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf @@ -1,8 +1,8 @@ terraform { required_providers { mongodbatlas = { - source = "mongodb/mongodbatlas" - version = "1.3.2" + source = "mongodb/mongodbatlas" + version = "1.3.2" } } required_version = ">= 0.13" From dcef03f367202734e7cfc23cfcde748ccefe5abc Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Thu, 14 Apr 2022 21:19:31 -0500 Subject: [PATCH 09/14] Correct version --- examples/MongoDB-Atlas-Third-Party-Integration/versions.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf b/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf index 6658b2f840..e40bf33745 100644 --- a/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf +++ b/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf @@ -2,7 +2,6 @@ terraform { required_providers { mongodbatlas = { source = "mongodb/mongodbatlas" - version = "1.3.2" } } required_version = ">= 0.13" From 3818110a2a200c3820a8d151b085d368adea43eb Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Thu, 14 Apr 2022 21:31:17 -0500 Subject: [PATCH 10/14] Fix lint issue --- .../data_source_mongodbatlas_third_party_integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go b/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go index 4273308129..7b4643057c 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integration_test.go @@ -85,7 +85,7 @@ const ( } ` - MICROSOFT_TEAMS = ` + MICROSOFTTEAMS = ` resource "mongodbatlas_third_party_integration" "%[1]s" { project_id = "%[2]s" type = "%[3]s" @@ -223,7 +223,7 @@ func testAccMongoDBAtlasThirdPartyIntegrationResourceConfig(config *thirdPartyCo config.Integration.Type, config.Integration.URL, ) - case "MICROSOFT_TEAMS": + case "MICROSOFTTEAMS": return fmt.Sprintf(WEBHOOK, config.Name, config.ProjectID, From 8e84efc0776635eab7ded0ceb4126cd17e12451d Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Thu, 14 Apr 2022 21:37:55 -0500 Subject: [PATCH 11/14] terraform fmt example --- examples/MongoDB-Atlas-Third-Party-Integration/versions.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf b/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf index e40bf33745..d55e59c63d 100644 --- a/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf +++ b/examples/MongoDB-Atlas-Third-Party-Integration/versions.tf @@ -1,7 +1,7 @@ terraform { required_providers { mongodbatlas = { - source = "mongodb/mongodbatlas" + source = "mongodb/mongodbatlas" } } required_version = ">= 0.13" From 1983c815bc723bb8256950974ece4b7a6b0a65a8 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Fri, 15 Apr 2022 08:43:07 -0500 Subject: [PATCH 12/14] Update third party integration resource enabled to boolean --- .../data_source_mongodbatlas_third_party_integration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integration.go b/mongodbatlas/data_source_mongodbatlas_third_party_integration.go index 30caadc47d..1279463632 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integration.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integration.go @@ -125,7 +125,7 @@ func thirdPartyIntegrationSchema() *schema.Resource { Optional: true, }, "enabled": { - Type: schema.TypeString, + Type: schema.TypeBool, Optional: true, }, }, From 869e20704d1102bdeed3466ce3ecd329eea16ab3 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Mon, 18 Apr 2022 11:49:54 -0500 Subject: [PATCH 13/14] Rename example file --- .../{thirdy-party-integration.tf => third-party-integration.tf} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/MongoDB-Atlas-Third-Party-Integration/{thirdy-party-integration.tf => third-party-integration.tf} (77%) diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf b/examples/MongoDB-Atlas-Third-Party-Integration/third-party-integration.tf similarity index 77% rename from examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf rename to examples/MongoDB-Atlas-Third-Party-Integration/third-party-integration.tf index 51be95d466..331167a0a5 100644 --- a/examples/MongoDB-Atlas-Third-Party-Integration/thirdy-party-integration.tf +++ b/examples/MongoDB-Atlas-Third-Party-Integration/third-party-integration.tf @@ -1,7 +1,7 @@ resource "mongodbatlas_third_party_integration" "test_msteams" { project_id = mongodbatlas_project.project.id type = "MICROSOFT_TEAMS" - microsoft_teams_webhook_url = "https://mongodb0.webhook.office.com/webhookb2/97142c7c-15e8-47de-9a7a-355183e89a68@c96563a8-841b-4ef9-af16-33548de0c958/IncomingWebhook/c0337c212d1f41149d754e9f4e0229b6/fa477bb6-9b05-473a-be3e-1157d9633ee8" + microsoft_teams_webhook_url = "https://mongodb0.webhook.office.com/webhookb2/zfd-15e8-47de-9a7a-355183e89a68@thi-841b-4ef9-af16-33548de0c958/IncomingWebhook/xyz" } resource "mongodbatlas_third_party_integration" "test_prometheus" { From ee05fffd73f01887856694881df6ec81ebb1abf7 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Fri, 22 Apr 2022 09:53:34 -0500 Subject: [PATCH 14/14] Simplify example to integration only Doc updates password optional field --- .../Readme.md | 62 ++++--------------- .../atlas_cluster.tf | 24 ------- .../database_user.tf | 19 ------ .../ip_access_list.tf | 8 --- .../third-party-integration.tf | 6 +- .../variables.tf | 38 +++--------- ...e_mongodbatlas_third_party_integrations.go | 2 +- .../docs/r/third_party_integration.markdown | 8 +++ 8 files changed, 32 insertions(+), 135 deletions(-) delete mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/atlas_cluster.tf delete mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/database_user.tf delete mode 100644 examples/MongoDB-Atlas-Third-Party-Integration/ip_access_list.tf diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/Readme.md b/examples/MongoDB-Atlas-Third-Party-Integration/Readme.md index 4e0fdb38fd..21bbfb4398 100644 --- a/examples/MongoDB-Atlas-Third-Party-Integration/Readme.md +++ b/examples/MongoDB-Atlas-Third-Party-Integration/Readme.md @@ -1,16 +1,17 @@ -# Example - A basic example to start with the MongoDB Atlas and Terraform +# Example - A basic example configuring MongoDB Atlas Third Party Integrations and Terraform This project aims to provide a very straight-forward example of setting up Terraform with MongoDB Atlas. This will create the following resources in MongoDB Atlas: - Atlas Project -- MongoDB Cluster - M10 -- Database User -- IP Access List +- Microst Teams Third Party Integration +- Prometheus Third Party Integration -You can refer to the MongoDB Atlas documentation to know about the region names used in MongoDB Atlas respective to the Cloud Provider's region name. -[Amazon Web Services (AWS)](https://docs.atlas.mongodb.com/reference/amazon-aws/#amazon-aws) -[Google Cloud Platform (GCP)](https://docs.atlas.mongodb.com/reference/google-gcp/#google-gcp) -[Microsoft Azure](https://docs.atlas.mongodb.com/reference/microsoft-azure/#microsoft-azure) + +You can refer to the MongoDB Atlas documentation to know about the parameters that support Third Party Integrations. + +[Prometheus](https://www.mongodb.com/docs/atlas/tutorial/prometheus-integration/#std-label-httpsd-prometheus-config) + +[Microsoft Teams](https://www.mongodb.com/docs/atlas/tutorial/integrate-msft-teams/) ## Dependencies @@ -46,9 +47,8 @@ $ terraform plan This project currently creates the below deployments: - Atlas Project -- MongoDB cluster - M10 -- Database User -- IP Access list +- Microst Teams Third Party Integration +- Prometheus Third Party Integration **3\. Execute the Terraform apply.** @@ -66,43 +66,3 @@ Once you are finished your testing, ensure you destroy the resources to avoid un $ terraform destroy ``` -**Important Point** - -You can fetch the connection string as per the use case by following the MongoDB Atlas documentation on [Connect to your cluster](https://docs.atlas.mongodb.com/tutorial/connect-to-your-cluster/index.html). - -Or to fetch the connection string using terraform follow the below steps: - -```hcl -output "atlasclusterstring" { - value = mongodbatlas_cluster.cluster.connection_strings -} -``` -**Outputs:** -```hcl -atlasclusterstring = [ - { - "aws_private_link" = { - "vpce-0ebb76559e8affc96" = "mongodb://pl-0-us-east-1.za3fb.mongodb.net:1024,pl-0-us-east-1.za3fb.mongodb.net:1025,pl-0-us-east-1.za3fb.mongodb.net:1026/?ssl=true&authSource=admin&replicaSet=atlas-d177ke-shard-0" - } - "aws_private_link_srv" = { - "vpce-0ebb76559e8affc96" = "mongodb+srv://mongodb-atlas-pl-0.za3fb.mongodb.net" - } - "private" = "" - "private_srv" = "" - "standard" = "mongodb://mongodb-atlas-shard-00-00.za3fb.mongodb.net:27017,mongodb-atlas-shard-00-01.za3fb.mongodb.net:27017,mongodb-atlas-shard-00-02.za3fb.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-d177ke-shard-0" - "standard_srv" = "mongodb+srv://mongodb-atlas.za3fb.mongodb.net" - }, -] -``` - -To fetch a particular connection string, use the **lookup()** function of terraform as below: - -``` -output "plstring" { - value = lookup(mongodbatlas_cluster.cluster.connection_strings[0].aws_private_link_srv, aws_vpc_endpoint.ptfe_service.id) -} -``` -**Output:** -``` -plstring = mongodb+srv://cluster-atlas-pl-0.za3fb.mongodb.net -``` diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/atlas_cluster.tf b/examples/MongoDB-Atlas-Third-Party-Integration/atlas_cluster.tf deleted file mode 100644 index f07552a47c..0000000000 --- a/examples/MongoDB-Atlas-Third-Party-Integration/atlas_cluster.tf +++ /dev/null @@ -1,24 +0,0 @@ -resource "mongodbatlas_cluster" "cluster" { - project_id = mongodbatlas_project.project.id - name = var.cluster_name - mongo_db_major_version = var.mongodbversion - cluster_type = "REPLICASET" - replication_specs { - num_shards = 1 - regions_config { - region_name = var.region - electable_nodes = 3 - priority = 7 - read_only_nodes = 0 - } - } - # Provider Settings "block" - cloud_backup = true - auto_scaling_disk_gb_enabled = true - provider_name = var.cloud_provider - provider_instance_size_name = "M10" -} -output "connection_strings" { - value = mongodbatlas_cluster.cluster.connection_strings[0].standard_srv -} - diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/database_user.tf b/examples/MongoDB-Atlas-Third-Party-Integration/database_user.tf deleted file mode 100644 index 15e2f3ff9e..0000000000 --- a/examples/MongoDB-Atlas-Third-Party-Integration/database_user.tf +++ /dev/null @@ -1,19 +0,0 @@ -# DATABASE USER [Configure Database Users](https://docs.atlas.mongodb.com/security-add-mongodb-users/) -resource "mongodbatlas_database_user" "user" { - username = var.dbuser - password = var.dbuser_password - project_id = mongodbatlas_project.project.id - auth_database_name = "admin" - - roles { - role_name = "readWrite" - database_name = var.database_name # The database name and collection name need not exist in the cluster before creating the user. - } - labels { - key = "Name" - value = "DB User1" - } -} -output "user1" { - value = mongodbatlas_database_user.user.username -} diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/ip_access_list.tf b/examples/MongoDB-Atlas-Third-Party-Integration/ip_access_list.tf deleted file mode 100644 index 0e4701b2f1..0000000000 --- a/examples/MongoDB-Atlas-Third-Party-Integration/ip_access_list.tf +++ /dev/null @@ -1,8 +0,0 @@ -resource "mongodbatlas_project_ip_access_list" "ip" { - project_id = mongodbatlas_project.project.id - ip_address = var.ip_address - comment = "IP Address for accessing the cluster" -} -output "ipaccesslist" { - value = mongodbatlas_project_ip_access_list.ip.ip_address -} diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/third-party-integration.tf b/examples/MongoDB-Atlas-Third-Party-Integration/third-party-integration.tf index 331167a0a5..5688208c28 100644 --- a/examples/MongoDB-Atlas-Third-Party-Integration/third-party-integration.tf +++ b/examples/MongoDB-Atlas-Third-Party-Integration/third-party-integration.tf @@ -1,14 +1,14 @@ resource "mongodbatlas_third_party_integration" "test_msteams" { project_id = mongodbatlas_project.project.id type = "MICROSOFT_TEAMS" - microsoft_teams_webhook_url = "https://mongodb0.webhook.office.com/webhookb2/zfd-15e8-47de-9a7a-355183e89a68@thi-841b-4ef9-af16-33548de0c958/IncomingWebhook/xyz" + microsoft_teams_webhook_url = var.microsoft_teams_webhook_url } resource "mongodbatlas_third_party_integration" "test_prometheus" { project_id = mongodbatlas_project.project.id type = "PROMETHEUS" - user_name = "prom_user_621952567c87684fd69b0101" - password = "KeQvcbkBhrNeuhVE" + user_name = var.user_name + password = var.password service_discovery = "file" scheme = "https" enabled = true diff --git a/examples/MongoDB-Atlas-Third-Party-Integration/variables.tf b/examples/MongoDB-Atlas-Third-Party-Integration/variables.tf index 4307ced129..26c6d31da6 100644 --- a/examples/MongoDB-Atlas-Third-Party-Integration/variables.tf +++ b/examples/MongoDB-Atlas-Third-Party-Integration/variables.tf @@ -14,38 +14,18 @@ variable "project_name" { type = string description = "The MongoDB Atlas Project Name" } -variable "cluster_name" { +variable "user_name" { type = string - description = "The MongoDB Atlas Cluster Name" + description = "The Prometheus User Name" + default = "puser" } -variable "cloud_provider" { +variable "password" { type = string - description = "The cloud provider to use, must be AWS, GCP or AZURE" + description = "The Prometheus Password" + default = "ppassword" } -variable "region" { +variable "microsoft_teams_webhook_url" { type = string - description = "MongoDB Atlas Cluster Region, must be a region for the provider given" + description = "The Microsoft Teams Webhook URL" + default = "https://yourcompany.webhook.office.com/webhookb2/zzz@yyy/IncomingWebhook/xyz" } -variable "mongodbversion" { - type = string - description = "The Major MongoDB Version" -} -variable "dbuser" { - type = string - description = "MongoDB Atlas Database User Name" -} -variable "dbuser_password" { - type = string - description = "MongoDB Atlas Database User Password" -} -variable "database_name" { - type = string - description = "The database in the cluster to limit the database user to, the database does not have to exist yet" -} -variable "ip_address" { - type = string - description = "The IP address that the cluster will be accessed from, can also be a CIDR range or AWS security group" -} - - - diff --git a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go index 471f9ac366..2f693be83f 100644 --- a/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go +++ b/mongodbatlas/data_source_mongodbatlas_third_party_integrations.go @@ -91,7 +91,7 @@ func integrationToSchema(integration *matlas.ThirdPartyIntegration) map[string]i // removing optional empty values, terraform complains about unexpected values even though they're empty optionals := []string{"license_key", "account_id", "write_token", "read_token", "api_key", "region", "service_key", "api_token", - "team_name", "channel_name", "flow_name", "org_name", "url", "secret"} + "team_name", "channel_name", "flow_name", "org_name", "url", "secret", "password"} for _, attr := range optionals { if val, ok := out[attr]; ok { diff --git a/website/docs/r/third_party_integration.markdown b/website/docs/r/third_party_integration.markdown index 91bffaea08..cd6911a28b 100644 --- a/website/docs/r/third_party_integration.markdown +++ b/website/docs/r/third_party_integration.markdown @@ -70,6 +70,14 @@ Additional values based on Type * `WEBHOOK` * `url` - Your webhook URL. * `secret` - An optional field for your webhook secret. +* `MICROSOFT_TEAMS` + * `microsoft_teams_webhook_url` - Your Microsoft Teams incoming webhook URL. + * `PROMETHEUS` + * `user_name` - Your Prometheus username. + * `password` - Your Prometheus password. + * `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. ## Attributes Reference