diff --git a/.changelog/2216.txt b/.changelog/2216.txt new file mode 100644 index 0000000000..b568dc27b4 --- /dev/null +++ b/.changelog/2216.txt @@ -0,0 +1,11 @@ +```release-note:note +resource/mongodbatlas_third_party_integration: Deprecates `scheme` attribute as it is not being used +``` + +```release-note:note +data-source/mongodbatlas_third_party_integration: Deprecates `scheme` attribute as it is not being used +``` + +```release-note:note +data-source/mongodbatlas_third_party_integrations: Deprecates `scheme` attribute as it is not being used +``` diff --git a/internal/service/thirdpartyintegration/data_source_third_party_integration.go b/internal/service/thirdpartyintegration/data_source_third_party_integration.go index f9422a7e2b..5789757ab8 100644 --- a/internal/service/thirdpartyintegration/data_source_third_party_integration.go +++ b/internal/service/thirdpartyintegration/data_source_third_party_integration.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -95,8 +96,9 @@ func thirdPartyIntegrationSchema() *schema.Resource { Optional: true, }, "scheme": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + Deprecated: fmt.Sprintf(constant.DeprecationParamByVersion, "1.18.0"), }, "enabled": { Type: schema.TypeBool, @@ -110,9 +112,9 @@ func dataSourceMongoDBAtlasThirdPartyIntegrationRead(ctx context.Context, d *sch projectID := d.Get("project_id").(string) queryType := d.Get("type").(string) - conn := meta.(*config.MongoDBClient).Atlas + connV2 := meta.(*config.MongoDBClient).AtlasV2 - integration, _, err := conn.Integrations.Get(ctx, projectID, queryType) + integration, _, err := connV2.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(ctx, projectID, queryType).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error getting third party integration for type %s %w", queryType, err)) diff --git a/internal/service/thirdpartyintegration/data_source_third_party_integrations.go b/internal/service/thirdpartyintegration/data_source_third_party_integrations.go index 2de9f00a48..a6c9daed2f 100644 --- a/internal/service/thirdpartyintegration/data_source_third_party_integrations.go +++ b/internal/service/thirdpartyintegration/data_source_third_party_integrations.go @@ -7,8 +7,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - matlas "go.mongodb.org/atlas/mongodbatlas" + "go.mongodb.org/atlas-sdk/v20231115012/admin" ) func PluralDataSource() *schema.Resource { @@ -29,10 +30,10 @@ func PluralDataSource() *schema.Resource { } func dataSourceMongoDBAtlasThirdPartyIntegrationsRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - conn := meta.(*config.MongoDBClient).Atlas + connV2 := meta.(*config.MongoDBClient).AtlasV2 projectID := d.Get("project_id").(string) - integrations, _, err := conn.Integrations.List(ctx, projectID) + integrations, _, err := connV2.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(ctx, projectID).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error getting third party integration list: %s", err)) @@ -47,15 +48,16 @@ func dataSourceMongoDBAtlasThirdPartyIntegrationsRead(ctx context.Context, d *sc return nil } -func flattenIntegrations(d *schema.ResourceData, integrations *matlas.ThirdPartyIntegrations, projectID string) (list []map[string]any) { - if len(integrations.Results) == 0 { +func flattenIntegrations(d *schema.ResourceData, integrations *admin.PaginatedIntegration, projectID string) (list []map[string]any) { + results := integrations.GetResults() + if len(results) == 0 { return } - list = make([]map[string]any, 0, len(integrations.Results)) + list = make([]map[string]any, 0, len(results)) - for _, integration := range integrations.Results { - service := integrationToSchema(d, integration) + for i := range results { + service := integrationToSchema(d, &results[i]) service["project_id"] = projectID list = append(list, service) } @@ -63,46 +65,45 @@ func flattenIntegrations(d *schema.ResourceData, integrations *matlas.ThirdParty return } -func integrationToSchema(d *schema.ResourceData, integration *matlas.ThirdPartyIntegration) map[string]any { +func integrationToSchema(d *schema.ResourceData, integration *admin.ThirdPartyIntegration) map[string]any { integrationSchema := schemaToIntegration(d) - if integrationSchema.APIKey == "" { - integrationSchema.APIKey = integration.APIKey + if integrationSchema.ApiKey == nil { + integrationSchema.ApiKey = integration.ApiKey } - if integrationSchema.ServiceKey == "" { + if integrationSchema.ServiceKey == nil { integrationSchema.ServiceKey = integration.ServiceKey } - if integrationSchema.APIToken == "" { - integrationSchema.APIToken = integration.APIToken + if integrationSchema.ApiToken == nil { + integrationSchema.ApiToken = integration.ApiToken } - if integrationSchema.RoutingKey == "" { + if integrationSchema.RoutingKey == nil { integrationSchema.RoutingKey = integration.RoutingKey } - if integrationSchema.Secret == "" { + if integrationSchema.Secret == nil { integrationSchema.Secret = integration.Secret } - if integrationSchema.Password == "" { + if integrationSchema.Password == nil { integrationSchema.Password = integration.Password } - if integrationSchema.URL == "" { - integrationSchema.URL = integration.URL + if integrationSchema.Url == nil { + integrationSchema.Url = integration.Url } out := map[string]any{ "type": integration.Type, - "api_key": integrationSchema.APIKey, + "api_key": integrationSchema.ApiKey, "region": integration.Region, "service_key": integrationSchema.ServiceKey, "team_name": integration.TeamName, "channel_name": integration.ChannelName, "routing_key": integration.RoutingKey, - "url": integrationSchema.URL, + "url": integrationSchema.Url, "secret": integrationSchema.Secret, - "microsoft_teams_webhook_url": integrationSchema.MicrosoftTeamsWebhookURL, - "user_name": integration.UserName, + "microsoft_teams_webhook_url": integrationSchema.MicrosoftTeamsWebhookUrl, + "user_name": integration.Username, "password": integrationSchema.Password, "service_discovery": integration.ServiceDiscovery, - "scheme": integration.Scheme, "enabled": integration.Enabled, } @@ -112,8 +113,8 @@ func integrationToSchema(d *schema.ResourceData, integration *matlas.ThirdPartyI for _, attr := range optionals { if val, ok := out[attr]; ok { - strval, okT := val.(string) - if okT && strval == "" { + stringPtr, okT := val.(*string) + if okT && !conversion.IsStringPresent(stringPtr) { delete(out, attr) } } @@ -122,124 +123,116 @@ func integrationToSchema(d *schema.ResourceData, integration *matlas.ThirdPartyI return out } -func schemaToIntegration(in *schema.ResourceData) (out *matlas.ThirdPartyIntegration) { - out = &matlas.ThirdPartyIntegration{} +func schemaToIntegration(in *schema.ResourceData) (out *admin.ThirdPartyIntegration) { + out = &admin.ThirdPartyIntegration{} if _type, ok := in.GetOk("type"); ok { - out.Type = _type.(string) + out.Type = admin.PtrString(_type.(string)) } if apiKey, ok := in.GetOk("api_key"); ok { - out.APIKey = apiKey.(string) + out.ApiKey = admin.PtrString(apiKey.(string)) } if region, ok := in.GetOk("region"); ok { - out.Region = region.(string) + out.Region = admin.PtrString(region.(string)) } if serviceKey, ok := in.GetOk("service_key"); ok { - out.ServiceKey = serviceKey.(string) + out.ServiceKey = admin.PtrString(serviceKey.(string)) } if teamName, ok := in.GetOk("team_name"); ok { - out.TeamName = teamName.(string) + out.TeamName = admin.PtrString(teamName.(string)) } if channelName, ok := in.GetOk("channel_name"); ok { - out.ChannelName = channelName.(string) + out.ChannelName = admin.PtrString(channelName.(string)) } if routingKey, ok := in.GetOk("routing_key"); ok { - out.RoutingKey = routingKey.(string) + out.RoutingKey = admin.PtrString(routingKey.(string)) } if url, ok := in.GetOk("url"); ok { - out.URL = url.(string) + out.Url = admin.PtrString(url.(string)) } if secret, ok := in.GetOk("secret"); ok { - out.Secret = secret.(string) + out.Secret = admin.PtrString(secret.(string)) } if microsoftTeamsWebhookURL, ok := in.GetOk("microsoft_teams_webhook_url"); ok { - out.MicrosoftTeamsWebhookURL = microsoftTeamsWebhookURL.(string) + out.MicrosoftTeamsWebhookUrl = admin.PtrString(microsoftTeamsWebhookURL.(string)) } if userName, ok := in.GetOk("user_name"); ok { - out.UserName = userName.(string) + out.Username = admin.PtrString(userName.(string)) } if password, ok := in.GetOk("password"); ok { - out.Password = password.(string) + out.Password = admin.PtrString(password.(string)) } if serviceDiscovery, ok := in.GetOk("service_discovery"); ok { - out.ServiceDiscovery = serviceDiscovery.(string) - } - - if scheme, ok := in.GetOk("scheme"); ok { - out.Scheme = scheme.(string) + out.ServiceDiscovery = admin.PtrString(serviceDiscovery.(string)) } if enabled, ok := in.GetOk("enabled"); ok { - out.Enabled = enabled.(bool) + out.Enabled = admin.PtrBool(enabled.(bool)) } return out } -func updateIntegrationFromSchema(d *schema.ResourceData, integration *matlas.ThirdPartyIntegration) { - integration.APIKey = d.Get("api_key").(string) +func updateIntegrationFromSchema(d *schema.ResourceData, integration *admin.ThirdPartyIntegration) { + integration.ApiKey = conversion.StringPtr(d.Get("api_key").(string)) if d.HasChange("region") { - integration.Region = d.Get("region").(string) + integration.Region = conversion.StringPtr(d.Get("region").(string)) } if d.HasChange("service_key") { - integration.ServiceKey = d.Get("service_key").(string) + integration.ServiceKey = conversion.StringPtr(d.Get("service_key").(string)) } if d.HasChange("team_name") { - integration.TeamName = d.Get("team_name").(string) + integration.TeamName = conversion.StringPtr(d.Get("team_name").(string)) } if d.HasChange("channel_name") { - integration.ChannelName = d.Get("channel_name").(string) + integration.ChannelName = conversion.StringPtr(d.Get("channel_name").(string)) } if d.HasChange("routing_key") { - integration.RoutingKey = d.Get("routing_key").(string) + integration.RoutingKey = conversion.StringPtr(d.Get("routing_key").(string)) } if d.HasChange("url") { - integration.URL = d.Get("url").(string) + integration.Url = conversion.StringPtr(d.Get("url").(string)) } if d.HasChange("secret") { - integration.Secret = d.Get("secret").(string) + integration.Secret = conversion.StringPtr(d.Get("secret").(string)) } if d.HasChange("microsoft_teams_webhook_url") { - integration.MicrosoftTeamsWebhookURL = d.Get("microsoft_teams_webhook_url").(string) + integration.MicrosoftTeamsWebhookUrl = conversion.StringPtr(d.Get("microsoft_teams_webhook_url").(string)) } if d.HasChange("user_name") { - integration.UserName = d.Get("user_name").(string) + integration.Username = conversion.StringPtr(d.Get("user_name").(string)) } if d.HasChange("password") { - integration.Password = d.Get("password").(string) + integration.Password = conversion.StringPtr(d.Get("password").(string)) } if d.HasChange("service_discovery") { - integration.ServiceDiscovery = d.Get("service_discovery").(string) - } - - if d.HasChange("scheme") { - integration.Scheme = d.Get("scheme").(string) + integration.ServiceDiscovery = conversion.StringPtr(d.Get("service_discovery").(string)) } if d.HasChange("enabled") { - integration.Enabled = d.Get("enabled").(bool) + integration.Enabled = admin.PtrBool(d.Get("enabled").(bool)) } } diff --git a/internal/service/thirdpartyintegration/resource_third_party_integration.go b/internal/service/thirdpartyintegration/resource_third_party_integration.go index 40d275c582..5f00566e8d 100644 --- a/internal/service/thirdpartyintegration/resource_third_party_integration.go +++ b/internal/service/thirdpartyintegration/resource_third_party_integration.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -30,7 +31,7 @@ var requiredPerType = map[string][]string{ "VICTOR_OPS": {"api_key"}, "WEBHOOK": {"url"}, "MICROSOFT_TEAMS": {"microsoft_teams_webhook_url"}, - "PROMETHEUS": {"user_name", "password", "service_discovery", "scheme", "enabled"}, + "PROMETHEUS": {"user_name", "password", "service_discovery", "enabled"}, } func Resource() *schema.Resource { @@ -122,9 +123,10 @@ func Resource() *schema.Resource { Sensitive: true, }, "scheme": { - Type: schema.TypeString, - Computed: true, - Optional: true, + Type: schema.TypeString, + Computed: true, + Optional: true, + Deprecated: fmt.Sprintf(constant.DeprecationParamByVersion, "1.18.0"), }, "enabled": { Type: schema.TypeBool, @@ -136,7 +138,7 @@ func Resource() *schema.Resource { } func resourceMongoDBAtlasThirdPartyIntegrationCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - conn := meta.(*config.MongoDBClient).Atlas + connV2 := meta.(*config.MongoDBClient).AtlasV2 projectID := d.Get("project_id").(string) integrationType := d.Get("type").(string) @@ -153,7 +155,7 @@ func resourceMongoDBAtlasThirdPartyIntegrationCreate(ctx context.Context, d *sch requestBody := schemaToIntegration(d) - _, _, err := conn.Integrations.Create(ctx, projectID, integrationType, requestBody) + _, _, err := connV2.ThirdPartyIntegrationsApi.CreateThirdPartyIntegration(ctx, integrationType, projectID, requestBody).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error creating third party integration %s", err)) @@ -169,13 +171,13 @@ func resourceMongoDBAtlasThirdPartyIntegrationCreate(ctx context.Context, d *sch } func resourceMongoDBAtlasThirdPartyIntegrationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - conn := meta.(*config.MongoDBClient).Atlas + connV2 := meta.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) projectID := ids["project_id"] integrationType := ids["type"] - integration, resp, err := conn.Integrations.Get(context.Background(), projectID, integrationType) + integration, resp, err := connV2.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(ctx, projectID, integrationType).Execute() if err != nil { if resp != nil && resp.StatusCode == http.StatusNotFound { d.SetId("") @@ -202,13 +204,13 @@ func resourceMongoDBAtlasThirdPartyIntegrationRead(ctx context.Context, d *schem } func resourceMongoDBAtlasThirdPartyIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - conn := meta.(*config.MongoDBClient).Atlas + connV2 := meta.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) projectID := ids["project_id"] integrationType := ids["type"] - integration, _, err := conn.Integrations.Get(ctx, projectID, integrationType) + integration, _, err := connV2.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(ctx, projectID, integrationType).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error getting third party integration resource info %s %w", integrationType, err)) @@ -218,7 +220,7 @@ func resourceMongoDBAtlasThirdPartyIntegrationUpdate(ctx context.Context, d *sch updateIntegrationFromSchema(d, integration) - _, _, err = conn.Integrations.Replace(ctx, projectID, integrationType, integration) + _, _, err = connV2.ThirdPartyIntegrationsApi.UpdateThirdPartyIntegration(ctx, integrationType, projectID, integration).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error updating third party integration type `%s` (%s): %w", integrationType, d.Id(), err)) diff --git a/internal/service/thirdpartyintegration/resource_third_party_integration_test.go b/internal/service/thirdpartyintegration/resource_third_party_integration_test.go index 18974dd577..3d008a5f1c 100644 --- a/internal/service/thirdpartyintegration/resource_third_party_integration_test.go +++ b/internal/service/thirdpartyintegration/resource_third_party_integration_test.go @@ -231,7 +231,6 @@ func prometheusTest(tb testing.TB) *resource.TestCase { resource.TestCheckResourceAttr(dataSourceName, "type", intType), resource.TestCheckResourceAttr(dataSourceName, "user_name", username), resource.TestCheckResourceAttr(dataSourceName, "service_discovery", serviceDiscovery), - resource.TestCheckResourceAttr(dataSourceName, "scheme", scheme), ), }, { diff --git a/website/docs/d/third_party_integration.markdown b/website/docs/d/third_party_integration.markdown index 5688ccb476..85f2567224 100644 --- a/website/docs/d/third_party_integration.markdown +++ b/website/docs/d/third_party_integration.markdown @@ -70,7 +70,7 @@ Additional values based on Type * `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. + * `scheme` - Your Prometheus protocol scheme configured for requests. **Note** This attribute is deprecated as it is not being used. * `enabled` - Whether your cluster has Prometheus enabled. See [MongoDB Atlas API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Third-Party-Integrations/operation/createThirdPartyIntegration) Documentation for more information. diff --git a/website/docs/d/third_party_integrations.markdown b/website/docs/d/third_party_integrations.markdown index 0d8f499c3f..716fbb0a24 100644 --- a/website/docs/d/third_party_integrations.markdown +++ b/website/docs/d/third_party_integrations.markdown @@ -82,7 +82,7 @@ Additional values based on Type * `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. + * `scheme` - Your Prometheus protocol scheme configured for requests. **Note** This attribute is deprecated as it is not being used. * `enabled` - Whether your cluster has Prometheus enabled. -See [MongoDB Atlas API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Third-Party-Integrations/operation/createThirdPartyIntegration) Documentation for more information. \ No newline at end of file +See [MongoDB Atlas API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Third-Party-Integrations/operation/createThirdPartyIntegration) Documentation for more information. diff --git a/website/docs/guides/1.16.0-upgrade-guide.html.markdown b/website/docs/guides/1.16.0-upgrade-guide.html.markdown index 8e845923a9..9702d35a43 100644 --- a/website/docs/guides/1.16.0-upgrade-guide.html.markdown +++ b/website/docs/guides/1.16.0-upgrade-guide.html.markdown @@ -33,6 +33,8 @@ More info can be found in the [previous upgrade guide](https://registry.terrafor - `mongodbatlas_teams` data source has been deprecated in favor of `mongodbatlas_team` which has the same implementation. This aligns the name of the resource with the implementation which fetches a single team. This also enables implementing a plural data source in the future under the name `mongodbatlas_teams`. +- `scheme` attribute has been deprecated in `mongodbatlas_third_party_integration` resource and data sources as its value is not being used. + ### Helpful Links * [Report bugs](https://github.com/mongodb/terraform-provider-mongodbatlas/issues) diff --git a/website/docs/r/third_party_integration.markdown b/website/docs/r/third_party_integration.markdown index 29fa672bbd..a428cda664 100644 --- a/website/docs/r/third_party_integration.markdown +++ b/website/docs/r/third_party_integration.markdown @@ -66,7 +66,7 @@ resource "mongodbatlas_third_party_integration" "test_datadog" { * `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. + * `scheme` - Your Prometheus protocol scheme configured for requests. **Note:** This attribute is deprecated as it is not being used. * `enabled` - Whether your cluster has Prometheus enabled. ## Attributes Reference