diff --git a/internal/service/privatelinkendpointserviceserverless/data_source_privatelink_endpoint_service_serverless.go b/internal/service/privatelinkendpointserviceserverless/data_source_privatelink_endpoint_service_serverless.go index 8ceda84e6d..8a7331f7b3 100644 --- a/internal/service/privatelinkendpointserviceserverless/data_source_privatelink_endpoint_service_serverless.go +++ b/internal/service/privatelinkendpointserviceserverless/data_source_privatelink_endpoint_service_serverless.go @@ -13,7 +13,7 @@ import ( func DataSource() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceMongoDBAtlasPrivateEndpointServiceServerlessLinkRead, + ReadContext: dataSourceRead, Schema: map[string]*schema.Schema{ "project_id": { Type: schema.TypeString, @@ -62,48 +62,43 @@ func DataSource() *schema.Resource { } } -func dataSourceMongoDBAtlasPrivateEndpointServiceServerlessLinkRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - // Get client connection. - conn := meta.(*config.MongoDBClient).Atlas +func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { + connV2 := meta.(*config.MongoDBClient).AtlasV2 projectID := d.Get("project_id").(string) instanceName := d.Get("instance_name").(string) endpointID := d.Get("endpoint_id").(string) - serviceEndpoint, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + serviceEndpoint, _, err := connV2.ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(ctx, projectID, instanceName, endpointID).Execute() if err != nil { return diag.FromErr(fmt.Errorf(privatelinkendpointservice.ErrorServiceEndpointRead, endpointID, err)) } - if err := d.Set("error_message", serviceEndpoint.ErrorMessage); err != nil { + if err := d.Set("error_message", serviceEndpoint.GetErrorMessage()); err != nil { return diag.FromErr(fmt.Errorf(privatelinkendpointservice.ErrorEndpointSetting, "error_message", endpointID, err)) } - if err := d.Set("status", serviceEndpoint.Status); err != nil { + if err := d.Set("status", serviceEndpoint.GetStatus()); err != nil { return diag.FromErr(fmt.Errorf(privatelinkendpointservice.ErrorEndpointSetting, "status", endpointID, err)) } - if err := d.Set("comment", serviceEndpoint.Comment); err != nil { + if err := d.Set("comment", serviceEndpoint.GetComment()); err != nil { return diag.FromErr(fmt.Errorf(privatelinkendpointservice.ErrorEndpointSetting, "comment", endpointID, err)) } - if err := d.Set("error_message", serviceEndpoint.ErrorMessage); err != nil { - return diag.FromErr(fmt.Errorf(privatelinkendpointservice.ErrorEndpointSetting, "error_message", endpointID, err)) - } - - if err := d.Set("endpoint_service_name", serviceEndpoint.EndpointServiceName); err != nil { + if err := d.Set("endpoint_service_name", serviceEndpoint.GetEndpointServiceName()); err != nil { return diag.FromErr(fmt.Errorf(privatelinkendpointservice.ErrorEndpointSetting, "endpoint_service_name", endpointID, err)) } - if err := d.Set("cloud_provider_endpoint_id", serviceEndpoint.CloudProviderEndpointID); err != nil { + if err := d.Set("cloud_provider_endpoint_id", serviceEndpoint.GetCloudProviderEndpointId()); err != nil { return diag.FromErr(fmt.Errorf(privatelinkendpointservice.ErrorEndpointSetting, "cloud_provider_endpoint_id", endpointID, err)) } - if err := d.Set("private_link_service_resource_id", serviceEndpoint.PrivateLinkServiceResourceID); err != nil { + if err := d.Set("private_link_service_resource_id", serviceEndpoint.GetPrivateLinkServiceResourceId()); err != nil { return diag.FromErr(fmt.Errorf(privatelinkendpointservice.ErrorEndpointSetting, "private_link_service_resource_id", endpointID, err)) } - if err := d.Set("private_endpoint_ip_address", serviceEndpoint.PrivateEndpointIPAddress); err != nil { + if err := d.Set("private_endpoint_ip_address", serviceEndpoint.GetPrivateEndpointIpAddress()); err != nil { return diag.FromErr(fmt.Errorf(privatelinkendpointservice.ErrorEndpointSetting, "private_endpoint_ip_address", endpointID, err)) } diff --git a/internal/service/privatelinkendpointserviceserverless/data_source_privatelink_endpoints_service_serverless.go b/internal/service/privatelinkendpointserviceserverless/data_source_privatelink_endpoints_service_serverless.go index d0d7c1be5d..6f4175bcb9 100644 --- a/internal/service/privatelinkendpointserviceserverless/data_source_privatelink_endpoints_service_serverless.go +++ b/internal/service/privatelinkendpointserviceserverless/data_source_privatelink_endpoints_service_serverless.go @@ -2,17 +2,19 @@ package privatelinkendpointserviceserverless import ( "context" + "fmt" "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/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - matlas "go.mongodb.org/atlas/mongodbatlas" + "go.mongodb.org/atlas-sdk/v20231115006/admin" ) func PluralDataSource() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceMongoDBAtlasPrivateLinkEndpointsServiceServerlessRead, + ReadContext: dataSourcePluralRead, Schema: map[string]*schema.Schema{ "project_id": { Type: schema.TypeString, @@ -24,12 +26,14 @@ func PluralDataSource() *schema.Resource { ForceNew: true, }, "page_num": { - Type: schema.TypeInt, - Optional: true, + Deprecated: fmt.Sprintf(constant.DeprecationParamByVersion, "1.17.0"), + Type: schema.TypeInt, + Optional: true, }, "items_per_page": { - Type: schema.TypeInt, - Optional: true, + Deprecated: fmt.Sprintf(constant.DeprecationParamByVersion, "1.17.0"), + Type: schema.TypeInt, + Optional: true, }, "results": { Type: schema.TypeList, @@ -76,18 +80,12 @@ func PluralDataSource() *schema.Resource { } } -func dataSourceMongoDBAtlasPrivateLinkEndpointsServiceServerlessRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - // Get client connection. - conn := meta.(*config.MongoDBClient).Atlas +func dataSourcePluralRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { + connV2 := meta.(*config.MongoDBClient).AtlasV2 projectID := d.Get("project_id").(string) instanceName := d.Get("instance_name").(string) - options := &matlas.ListOptions{ - PageNum: d.Get("page_num").(int), - ItemsPerPage: d.Get("items_per_page").(int), - } - - privateLinkEndpoints, _, err := conn.ServerlessPrivateEndpoints.List(ctx, projectID, instanceName, options) + privateLinkEndpoints, _, err := connV2.ServerlessPrivateEndpointsApi.ListServerlessPrivateEndpoints(ctx, projectID, instanceName).Execute() if err != nil { return diag.Errorf("error getting Serverless PrivateLink Endpoints Information: %s", err) } @@ -101,25 +99,23 @@ func dataSourceMongoDBAtlasPrivateLinkEndpointsServiceServerlessRead(ctx context return nil } -func flattenServerlessPrivateLinkEndpoints(privateLinks []matlas.ServerlessPrivateEndpointConnection) []map[string]any { - var results []map[string]any - +func flattenServerlessPrivateLinkEndpoints(privateLinks []admin.ServerlessTenantEndpoint) []map[string]any { if len(privateLinks) == 0 { - return results + return nil } - results = make([]map[string]any, len(privateLinks)) + results := make([]map[string]any, len(privateLinks)) for k := range privateLinks { results[k] = map[string]any{ - "endpoint_id": privateLinks[k].ID, - "endpoint_service_name": privateLinks[k].EndpointServiceName, - "cloud_provider_endpoint_id": privateLinks[k].CloudProviderEndpointID, - "private_link_service_resource_id": privateLinks[k].PrivateLinkServiceResourceID, - "private_endpoint_ip_address": privateLinks[k].PrivateEndpointIPAddress, - "comment": privateLinks[k].Comment, - "error_message": privateLinks[k].ErrorMessage, - "status": privateLinks[k].Status, + "endpoint_id": privateLinks[k].GetId(), + "endpoint_service_name": privateLinks[k].GetEndpointServiceName(), + "cloud_provider_endpoint_id": privateLinks[k].GetCloudProviderEndpointId(), + "private_link_service_resource_id": privateLinks[k].GetPrivateLinkServiceResourceId(), + "private_endpoint_ip_address": privateLinks[k].GetPrivateEndpointIpAddress(), + "comment": privateLinks[k].GetComment(), + "error_message": privateLinks[k].GetErrorMessage(), + "status": privateLinks[k].GetStatus(), } } diff --git a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go index d22cd3d6d0..af19336347 100644 --- a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go +++ b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "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/v20231115006/admin" ) const ( @@ -25,11 +25,11 @@ const ( func Resource() *schema.Resource { return &schema.Resource{ - CreateWithoutTimeout: resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessCreate, - ReadWithoutTimeout: resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessRead, - DeleteWithoutTimeout: resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessDelete, + CreateWithoutTimeout: resourceCreate, + ReadWithoutTimeout: resourceRead, + DeleteWithoutTimeout: resourceDelete, Importer: &schema.ResourceImporter{ - StateContext: resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessImportState, + StateContext: resourceImport, }, Schema: map[string]*schema.Schema{ "project_id": { @@ -86,28 +86,25 @@ func Resource() *schema.Resource { } } -func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - // Get client connection. - conn := meta.(*config.MongoDBClient).Atlas +func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { + connV2 := meta.(*config.MongoDBClient).AtlasV2 projectID := d.Get("project_id").(string) instanceName := d.Get("instance_name").(string) endpointID := d.Get("endpoint_id").(string) - privateLink, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + _, _, err := connV2.ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(ctx, projectID, instanceName, endpointID).Execute() if err != nil { return diag.Errorf("error getting Serverless PrivateLink Endpoint Information: %s", err) } - privateLink.Comment = d.Get("comment").(string) - privateLink.CloudProviderEndpointID = d.Get("cloud_provider_endpoint_id").(string) - privateLink.ProviderName = d.Get("provider_name").(string) - privateLink.PrivateLinkServiceResourceID = "" - privateLink.PrivateEndpointIPAddress = d.Get("private_endpoint_ip_address").(string) - privateLink.ID = "" - privateLink.Status = "" - privateLink.EndpointServiceName = "" + updateRequest := admin.ServerlessTenantEndpointUpdate{ + Comment: conversion.StringPtr(d.Get("comment").(string)), + ProviderName: d.Get("provider_name").(string), + CloudProviderEndpointId: conversion.StringPtr(d.Get("cloud_provider_endpoint_id").(string)), + PrivateEndpointIpAddress: conversion.StringPtr(d.Get("private_endpoint_ip_address").(string)), + } - endPoint, _, err := conn.ServerlessPrivateEndpoints.Update(ctx, projectID, instanceName, endpointID, privateLink) + endPoint, _, err := connV2.ServerlessPrivateEndpointsApi.UpdateServerlessPrivateEndpoint(ctx, projectID, instanceName, endpointID, &updateRequest).Execute() if err != nil { return diag.Errorf(ErrorServerlessServiceEndpointAdd, endpointID, err) } @@ -115,12 +112,12 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessCreate(ctx context. stateConf := &retry.StateChangeConf{ Pending: []string{"RESERVATION_REQUESTED", "INITIATING", "DELETING"}, Target: []string{"RESERVED", "FAILED", "DELETED", "AVAILABLE"}, - Refresh: resourceServiceEndpointServerlessRefreshFunc(ctx, conn, projectID, instanceName, endpointID), + Refresh: resourceRefreshFunc(ctx, connV2, projectID, instanceName, endpointID), Timeout: d.Timeout(schema.TimeoutCreate), MinTimeout: 5 * time.Second, Delay: 5 * time.Minute, } - // Wait, catching any errors + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return diag.FromErr(fmt.Errorf(ErrorServerlessServiceEndpointAdd, endpointID, err)) @@ -129,7 +126,7 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessCreate(ctx context. clusterConf := &retry.StateChangeConf{ Pending: []string{"REPEATING", "PENDING"}, Target: []string{"IDLE", "DELETED"}, - Refresh: resourceServerlessInstanceListRefreshFunc(ctx, projectID, conn), + Refresh: resourceListRefreshFunc(ctx, projectID, connV2), Timeout: d.Timeout(schema.TimeoutCreate), MinTimeout: 5 * time.Second, Delay: 5 * time.Minute, @@ -143,35 +140,32 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessCreate(ctx context. d.SetId(conversion.EncodeStateID(map[string]string{ "project_id": projectID, "instance_name": instanceName, - "endpoint_id": endPoint.ID, + "endpoint_id": endPoint.GetId(), })) - return resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessRead(ctx, d, meta) + return resourceRead(ctx, d, meta) } -func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - // Get client connection. - conn := meta.(*config.MongoDBClient).Atlas +func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { + connV2 := meta.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) projectID := ids["project_id"] instanceName := ids["instance_name"] endpointID := ids["endpoint_id"] - privateLinkResponse, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + privateLinkResponse, _, err := connV2.ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(ctx, projectID, instanceName, endpointID).Execute() if err != nil { - // case 404 - // deleted in the backend case + // case 404: deleted in the backend case if strings.Contains(err.Error(), "404") || strings.Contains(err.Error(), "400") { d.SetId("") return nil } - return diag.Errorf("error getting Serverless private link endpoint information: %s", err) } - privateLinkResponse.ProviderName = d.Get("provider_name").(string) + privateLinkResponse.ProviderName = conversion.StringPtr(d.Get("provider_name").(string)) - if err := d.Set("endpoint_id", privateLinkResponse.ID); err != nil { + if err := d.Set("endpoint_id", privateLinkResponse.GetId()); err != nil { return diag.Errorf("error setting `endpoint_id` for endpoint_id (%s): %s", d.Id(), err) } @@ -179,50 +173,47 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessRead(ctx context.Co return diag.Errorf("error setting `instance Name` for endpoint_id (%s): %s", d.Id(), err) } - if err := d.Set("comment", privateLinkResponse.Comment); err != nil { + if err := d.Set("comment", privateLinkResponse.GetComment()); err != nil { return diag.Errorf("error setting `comment` for endpoint_id (%s): %s", d.Id(), err) } - if err := d.Set("provider_name", privateLinkResponse.ProviderName); err != nil { + if err := d.Set("provider_name", privateLinkResponse.GetProviderName()); err != nil { return diag.Errorf("error setting `provider_name` for endpoint_id (%s): %s", d.Id(), err) } - if err := d.Set("status", privateLinkResponse.Status); err != nil { + if err := d.Set("status", privateLinkResponse.GetStatus()); err != nil { return diag.Errorf("error setting `status` for endpoint_id (%s): %s", d.Id(), err) } - if err := d.Set("cloud_provider_endpoint_id", privateLinkResponse.CloudProviderEndpointID); err != nil { + if err := d.Set("cloud_provider_endpoint_id", privateLinkResponse.GetCloudProviderEndpointId()); err != nil { return diag.Errorf("error setting `cloud_provider_endpoint_id` for endpoint_id (%s): %s", d.Id(), err) } - if err := d.Set("private_link_service_resource_id", privateLinkResponse.PrivateLinkServiceResourceID); err != nil { + if err := d.Set("private_link_service_resource_id", privateLinkResponse.GetPrivateLinkServiceResourceId()); err != nil { return diag.Errorf("error setting `private_link_service_resource_id` for endpoint_id (%s): %s", d.Id(), err) } - if err := d.Set("private_endpoint_ip_address", privateLinkResponse.PrivateEndpointIPAddress); err != nil { + if err := d.Set("private_endpoint_ip_address", privateLinkResponse.GetPrivateEndpointIpAddress()); err != nil { return diag.Errorf("error setting `private_endpoint_ip_address` for endpoint_id (%s): %s", d.Id(), err) } return nil } -func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - // Get client connection. - conn := meta.(*config.MongoDBClient).Atlas +func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { + connV2 := meta.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) projectID := ids["project_id"] instanceName := ids["instance_name"] endpointID := ids["endpoint_id"] - _, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + _, _, err := connV2.ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(ctx, projectID, instanceName, endpointID).Execute() if err != nil { - // case 404 - // deleted in the backend case + // case 404: deleted in the backend case if strings.Contains(err.Error(), "404") || strings.Contains(err.Error(), "400") { d.SetId("") return nil } - return diag.Errorf(errorServerlessServiceEndpointDelete, endpointID, err) } @@ -231,8 +222,8 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessDelete(ctx context. return nil } -func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { - conn := meta.(*config.MongoDBClient).Atlas +func resourceImport(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { + connV2 := meta.(*config.MongoDBClient).AtlasV2 parts := strings.SplitN(d.Id(), "--", 3) if len(parts) != 3 { @@ -243,7 +234,7 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessImportState(ctx con instanceName := parts[1] endpointID := parts[2] - privateLinkResponse, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + privateLinkResponse, _, err := connV2.ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(ctx, projectID, instanceName, endpointID).Execute() if err != nil { return nil, fmt.Errorf("couldn't import serverless private link endpoint (%s) in projectID (%s) , error: %s", endpointID, projectID, err) } @@ -260,7 +251,7 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessImportState(ctx con log.Printf("[WARN] Error setting instance_name for (%s): %s", endpointID, err) } - if privateLinkResponse.PrivateLinkServiceResourceID != "" { + if privateLinkResponse.GetPrivateLinkServiceResourceId() != "" { if err := d.Set("provider_name", "AZURE"); err != nil { log.Printf("[WARN] Error setting provider_name for (%s): %s", endpointID, err) } @@ -279,34 +270,35 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessImportState(ctx con return []*schema.ResourceData{d}, nil } -func resourceServiceEndpointServerlessRefreshFunc(ctx context.Context, client *matlas.Client, projectID, instanceName, endpointServiceID string) retry.StateRefreshFunc { +func resourceRefreshFunc(ctx context.Context, client *admin.APIClient, projectID, instanceName, endpointServiceID string) retry.StateRefreshFunc { return func() (any, string, error) { - i, resp, err := client.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointServiceID) + serverlessTenantEndpoint, resp, err := client.ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(ctx, projectID, instanceName, endpointServiceID).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 || resp.Response.StatusCode == 400 { + if resp != nil && resp.StatusCode == 404 || resp.StatusCode == 400 { return "", "DELETED", nil } return nil, "", err } - if i.Status != "AVAILABLE" { - return "", i.Status, nil + if serverlessTenantEndpoint.GetStatus() != "AVAILABLE" { + return "", serverlessTenantEndpoint.GetStatus(), nil } + resultStatus := serverlessTenantEndpoint.GetStatus() - return i, i.Status, nil + return serverlessTenantEndpoint, resultStatus, nil } } -func resourceServerlessInstanceListRefreshFunc(ctx context.Context, projectID string, client *matlas.Client) retry.StateRefreshFunc { +func resourceListRefreshFunc(ctx context.Context, projectID string, client *admin.APIClient) retry.StateRefreshFunc { return func() (any, string, error) { - c, resp, err := client.ServerlessInstances.List(ctx, projectID, nil) + serverlessInstances, resp, err := client.ServerlessInstancesApi.ListServerlessInstances(ctx, projectID).Execute() if err != nil && strings.Contains(err.Error(), "reset by peer") { return nil, "REPEATING", nil } - if err != nil && c == nil && resp == nil { + if err != nil && serverlessInstances == nil && resp == nil { return nil, "", err } else if err != nil { if resp.StatusCode == 404 { @@ -318,12 +310,12 @@ func resourceServerlessInstanceListRefreshFunc(ctx context.Context, projectID st return nil, "", err } - for i := range c.Results { - if c.Results[i].StateName != "IDLE" { - return c.Results[i], "PENDING", nil + for i := range serverlessInstances.GetResults() { + if serverlessInstances.GetResults()[i].GetStateName() != "IDLE" { + return serverlessInstances.GetResults()[i], "PENDING", nil } } - return c, "IDLE", nil + return serverlessInstances, "IDLE", nil } } diff --git a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_migration_test.go b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_migration_test.go new file mode 100644 index 0000000000..0c6c259e02 --- /dev/null +++ b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_migration_test.go @@ -0,0 +1,40 @@ +package privatelinkendpointserviceserverless_test + +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig" +) + +func TestAccMigrationServerlessPrivateLinkEndpointService_basic(t *testing.T) { + var ( + resourceName = "mongodbatlas_privatelink_endpoint_service_serverless.test" + datasourceName = "data.mongodbatlas_privatelink_endpoint_service_serverless.test" + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc-serverless") + instanceName = acctest.RandomWithPrefix("test-acc-serverless") + commentOrigin = "this is a comment for serverless private link endpoint" + config = configBasic(orgID, projectName, instanceName, commentOrigin) + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { mig.PreCheckBasic(t) }, + CheckDestroy: checkDestroy, + Steps: []resource.TestStep{ + { + ExternalProviders: mig.ExternalProviders(), + Config: config, + Check: resource.ComposeTestCheckFunc( + checkExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "provider_name", "AWS"), + resource.TestCheckResourceAttr(resourceName, "comment", commentOrigin), + resource.TestCheckResourceAttr(datasourceName, "comment", commentOrigin), + ), + }, + mig.TestStep(config), + }, + }) +} diff --git a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_test.go b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_test.go index 1e988a8db4..8c37490620 100644 --- a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_test.go +++ b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless_test.go @@ -27,12 +27,12 @@ func TestAccServerlessPrivateLinkEndpointService_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessDestroy, + CheckDestroy: checkDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(orgID, projectName, instanceName, commentOrigin), + Config: configBasic(orgID, projectName, instanceName, commentOrigin), Check: resource.ComposeTestCheckFunc( - testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resourceName), + checkExists(resourceName), resource.TestCheckResourceAttr(resourceName, "provider_name", "AWS"), resource.TestCheckResourceAttr(resourceName, "comment", commentOrigin), resource.TestCheckResourceAttr(datasourceName, "comment", commentOrigin), @@ -56,19 +56,19 @@ func TestAccServerlessPrivateLinkEndpointService_importBasic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - CheckDestroy: acc.CheckDestroySearchIndex, + CheckDestroy: checkDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(orgID, projectName, instanceName, commentOrigin), + Config: configBasic(orgID, projectName, instanceName, commentOrigin), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "provider_name", "AWS"), resource.TestCheckResourceAttr(resourceName, "comment", commentOrigin), ), }, { - Config: testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(orgID, projectName, instanceName, commentOrigin), + Config: configBasic(orgID, projectName, instanceName, commentOrigin), ResourceName: resourceName, - ImportStateIdFunc: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessImportStateIDFunc(resourceName), + ImportStateIdFunc: importStateIDFunc(resourceName), ImportState: true, ImportStateVerify: true, }, @@ -76,13 +76,13 @@ func TestAccServerlessPrivateLinkEndpointService_importBasic(t *testing.T) { }) } -func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessDestroy(state *terraform.State) error { +func checkDestroy(state *terraform.State) error { for _, rs := range state.RootModule().Resources { if rs.Type != "mongodbatlas_privatelink_endpoint_service_serverless" { continue } ids := conversion.DecodeStateID(rs.Primary.ID) - privateLink, _, err := acc.Conn().ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + privateLink, _, err := acc.ConnV2().ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]).Execute() if err == nil && privateLink != nil { return fmt.Errorf("endpoint_id (%s) still exists", ids["endpoint_id"]) } @@ -90,7 +90,7 @@ func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessDestroy(state * return nil } -func testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(orgID, projectName, instanceName, comment string) string { +func configBasic(orgID, projectName, instanceName, comment string) string { return fmt.Sprintf(` resource "mongodbatlas_project" "test" { @@ -145,7 +145,7 @@ func testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(orgID, projec `, orgID, projectName, instanceName, comment) } -func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resourceName string) resource.TestCheckFunc { +func checkExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -155,7 +155,7 @@ func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resource return fmt.Errorf("no ID is set") } ids := conversion.DecodeStateID(rs.Primary.ID) - _, _, err := acc.Conn().ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + _, _, err := acc.ConnV2().ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]).Execute() if err == nil { return nil } @@ -163,7 +163,7 @@ func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resource } } -func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { +func importStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] if !ok {