Skip to content

Commit

Permalink
chore: Migrates privatelink_endpoint_service to new auto-generated …
Browse files Browse the repository at this point in the history
…SDK (#2222)
  • Loading branch information
oarbusi authored May 3, 2024
1 parent 2dc29ba commit 3f87720
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func DataSource() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceMongoDBAtlasPrivateEndpointServiceLinkRead,
ReadContext: dataSourceRead,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -100,34 +100,34 @@ func DataSource() *schema.Resource {
}
}

func dataSourceMongoDBAtlasPrivateEndpointServiceLinkRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
// Get client connection.
conn := meta.(*config.MongoDBClient).Atlas
connV2 := meta.(*config.MongoDBClient).AtlasV2

projectID := d.Get("project_id").(string)
privateLinkID := conversion.GetEncodedID(d.Get("private_link_id").(string), "private_link_id")
endpointServiceID := conversion.GetEncodedID(d.Get("endpoint_service_id").(string), "endpoint_service_id")
providerName := d.Get("provider_name").(string)

serviceEndpoint, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(ctx, projectID, providerName, privateLinkID, endpointServiceID)
serviceEndpoint, _, err := connV2.PrivateEndpointServicesApi.GetPrivateEndpoint(ctx, projectID, providerName, endpointServiceID, privateLinkID).Execute()
if err != nil {
return diag.FromErr(fmt.Errorf(ErrorServiceEndpointRead, endpointServiceID, err))
}

if err := d.Set("delete_requested", cast.ToBool(serviceEndpoint.DeleteRequested)); err != nil {
if err := d.Set("delete_requested", cast.ToBool(serviceEndpoint.GetDeleteRequested())); err != nil {
return diag.FromErr(fmt.Errorf(ErrorEndpointSetting, "delete_requested", endpointServiceID, 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(ErrorEndpointSetting, "error_message", endpointServiceID, err))
}

if err := d.Set("aws_connection_status", serviceEndpoint.AWSConnectionStatus); err != nil {
if err := d.Set("aws_connection_status", serviceEndpoint.GetConnectionStatus()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorEndpointSetting, "aws_connection_status", endpointServiceID, err))
}

if strings.EqualFold(providerName, "azure") {
if err := d.Set("azure_status", serviceEndpoint.Status); err != nil {
if err := d.Set("azure_status", serviceEndpoint.GetStatus()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorEndpointSetting, "azure_status", endpointServiceID, err))
}
}
Expand All @@ -137,7 +137,7 @@ func dataSourceMongoDBAtlasPrivateEndpointServiceLinkRead(ctx context.Context, d
}

if strings.EqualFold(providerName, "gcp") {
if err := d.Set("gcp_status", serviceEndpoint.Status); err != nil {
if err := d.Set("gcp_status", serviceEndpoint.GetStatus()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorEndpointSetting, "gcp_status", endpointServiceID, err))
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit 3f87720

Please sign in to comment.