From 712bd37ca17b5b6b398fc312839990a4bbebc465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20L=C3=B3pez?= Date: Fri, 22 Jan 2021 20:04:13 -0700 Subject: [PATCH] fix: changed the wrong order for private link and endpoint service id in private link service --- ...ngodbatlas_privatelink_endpoint_service.go | 6 +++-- ...atlas_privatelink_endpoint_service_test.go | 6 ++--- ...ngodbatlas_privatelink_endpoint_service.go | 22 +++++++++++-------- ...atlas_privatelink_endpoint_service_test.go | 9 ++++---- ...privatelink_endpoint_service.html.markdown | 7 +++--- ...privatelink_endpoint_service.html.markdown | 2 +- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service.go index a5bd2a17e2..092150bc71 100644 --- a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service.go +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service.go @@ -3,6 +3,7 @@ package mongodbatlas import ( "context" "fmt" + "net/url" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/spf13/cast" @@ -74,8 +75,9 @@ func dataSourceMongoDBAtlasPrivateEndpointServiceLinkRead(d *schema.ResourceData privateLinkID := d.Get("private_link_id").(string) endpointServiceID := d.Get("endpoint_service_id").(string) providerName := d.Get("provider_name").(string) + encodedEndpointID := url.PathEscape(endpointServiceID) - serviceEndpoint, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), projectID, providerName, endpointServiceID, privateLinkID) + serviceEndpoint, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), projectID, providerName, privateLinkID, encodedEndpointID) if err != nil { return fmt.Errorf(errorServiceEndpointRead, endpointServiceID, err) } @@ -95,7 +97,7 @@ func dataSourceMongoDBAtlasPrivateEndpointServiceLinkRead(d *schema.ResourceData d.SetId(encodeStateID(map[string]string{ "project_id": projectID, "private_link_id": privateLinkID, - "endpoint_service_id": serviceEndpoint.ID, + "endpoint_service_id": endpointServiceID, "provider_name": providerName, })) diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_test.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_test.go index 44ed64cc11..f6bb10eda4 100644 --- a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_test.go +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_test.go @@ -24,7 +24,7 @@ func TestAccDataSourceMongoDBAtlasPrivateLinkEndpointServiceAWS_basic(t *testing securityGroupID := os.Getenv("AWS_SECURITY_GROUP_ID") resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t); checkAwsEnv(t); checkPeeringEnvAWS(t) }, + PreCheck: func() { testAccPreCheck(t); checkAwsEnv(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { @@ -66,8 +66,8 @@ func testAccMongoDBAtlasPrivateLinkEndpointServiceDataSourceConfig(awsAccessKey, resource "mongodbatlas_privatelink_endpoint_service" "test" { project_id = mongodbatlas_privatelink_endpoint.test.project_id - private_link_id = aws_vpc_endpoint.ptfe_service.id - endpoint_service_id = mongodbatlas_privatelink_endpoint.test.private_link_id + endpoint_service_id = aws_vpc_endpoint.ptfe_service.id + private_link_id = mongodbatlas_privatelink_endpoint.test.private_link_id provider_name = "%[4]s" } diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go index e304c66dd7..e0548f98a8 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service.go @@ -95,11 +95,11 @@ func resourceMongoDBAtlasPrivateEndpointServiceLinkCreate(d *schema.ResourceData endpointServiceID := d.Get("endpoint_service_id").(string) request := &matlas.InterfaceEndpointConnection{ - ID: privateLinkID, + ID: endpointServiceID, PrivateEndpointIPAddress: d.Get("private_endpoint_ip_address").(string), } - _, _, err := conn.PrivateEndpoints.AddOnePrivateEndpoint(context.Background(), projectID, providerName, endpointServiceID, request) + _, _, err := conn.PrivateEndpoints.AddOnePrivateEndpoint(context.Background(), projectID, providerName, privateLinkID, request) if err != nil { return fmt.Errorf(errorServiceEndpointAdd, providerName, privateLinkID, err) } @@ -136,9 +136,9 @@ func resourceMongoDBAtlasPrivateEndpointServiceLinkRead(d *schema.ResourceData, privateLinkID := ids["private_link_id"] endpointServiceID := ids["endpoint_service_id"] providerName := ids["provider_name"] - encodedPrivateLinkID := url.PathEscape(privateLinkID) + encodedEndpointID := url.PathEscape(endpointServiceID) - privateEndpoint, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), projectID, providerName, endpointServiceID, encodedPrivateLinkID) + privateEndpoint, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), projectID, providerName, privateLinkID, encodedEndpointID) if err != nil { return fmt.Errorf(errorServiceEndpointRead, endpointServiceID, err) } @@ -175,6 +175,10 @@ func resourceMongoDBAtlasPrivateEndpointServiceLinkRead(d *schema.ResourceData, return fmt.Errorf(errorEndpointSetting, "endpoint_service_id", endpointServiceID, err) } + if err := d.Set("private_link_id", privateLinkID); err != nil { + return fmt.Errorf(errorEndpointSetting, "private_link_id", endpointServiceID, err) + } + return nil } @@ -186,10 +190,10 @@ func resourceMongoDBAtlasPrivateEndpointServiceLinkDelete(d *schema.ResourceData privateLinkID := ids["private_link_id"] endpointServiceID := ids["endpoint_service_id"] providerName := ids["provider_name"] - encodedPrivateLinkID := url.PathEscape(privateLinkID) + encodedEndpointID := url.PathEscape(endpointServiceID) if endpointServiceID != "" { - _, err := conn.PrivateEndpoints.DeleteOnePrivateEndpoint(context.Background(), projectID, providerName, endpointServiceID, encodedPrivateLinkID) + _, err := conn.PrivateEndpoints.DeleteOnePrivateEndpoint(context.Background(), projectID, providerName, privateLinkID, encodedEndpointID) if err != nil { return fmt.Errorf(errorEndpointDelete, endpointServiceID, err) } @@ -225,9 +229,9 @@ func resourceMongoDBAtlasPrivateEndpointServiceLinkImportState(d *schema.Resourc privateLinkID := parts[1] endpointServiceID := parts[2] providerName := parts[3] - encodedPrivateLinkID := url.PathEscape(privateLinkID) + encodedEndpointID := url.PathEscape(endpointServiceID) - _, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), projectID, providerName, endpointServiceID, encodedPrivateLinkID) + _, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), projectID, providerName, privateLinkID, encodedEndpointID) if err != nil { return nil, fmt.Errorf(errorServiceEndpointRead, endpointServiceID, err) } @@ -260,7 +264,7 @@ func resourceMongoDBAtlasPrivateEndpointServiceLinkImportState(d *schema.Resourc func resourceServiceEndpointRefreshFunc(client *matlas.Client, projectID, providerName, privateLinkID, endpointServiceID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { - i, resp, err := client.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), projectID, providerName, endpointServiceID, privateLinkID) + i, resp, err := client.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), projectID, providerName, privateLinkID, endpointServiceID) if err != nil { if resp != nil && resp.StatusCode == 404 { return "", "DELETED", nil diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_test.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_test.go index 48dd8ce02a..19a60eb934 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_test.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_test.go @@ -3,6 +3,7 @@ package mongodbatlas import ( "context" "fmt" + "net/url" "os" "testing" @@ -28,7 +29,7 @@ func TestAccResourceMongoDBAtlasPrivateLinkEndpointServiceAWS_Complete(t *testin ) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t); checkAwsEnv(t); checkPeeringEnvAWS(t) }, + PreCheck: func() { testAccPreCheck(t); checkAwsEnv(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceDestroy, Steps: []resource.TestStep{ @@ -117,7 +118,7 @@ func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceExists(resourceName strin ids := decodeStateID(rs.Primary.ID) - _, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), ids["project_id"], ids["provider_name"], ids["endpoint_service_id"], ids["private_link_id"]) + _, _, err := conn.PrivateEndpoints.GetOnePrivateEndpoint(context.Background(), ids["project_id"], ids["provider_name"], ids["private_link_id"], url.QueryEscape(ids["endpoint_service_id"])) if err == nil { return nil } @@ -169,8 +170,8 @@ func testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(awsAccessKey resource "mongodbatlas_privatelink_endpoint_service" "test" { project_id = mongodbatlas_privatelink_endpoint.test.project_id - private_link_id = aws_vpc_endpoint.ptfe_service.id - endpoint_service_id = mongodbatlas_privatelink_endpoint.test.private_link_id + endpoint_service_id = aws_vpc_endpoint.ptfe_service.id + private_link_id = mongodbatlas_privatelink_endpoint.test.private_link_id provider_name = "%[4]s" } `, awsAccessKey, awsSecretKey, projectID, providerName, region, vpcID, subnetID, securityGroupID) diff --git a/website/docs/d/privatelink_endpoint_service.html.markdown b/website/docs/d/privatelink_endpoint_service.html.markdown index 86a682e188..66e1f88522 100644 --- a/website/docs/d/privatelink_endpoint_service.html.markdown +++ b/website/docs/d/privatelink_endpoint_service.html.markdown @@ -32,7 +32,8 @@ resource "aws_vpc_endpoint" "ptfe_service" { resource "mongodbatlas_privatelink_endpoint_service" "test" { project_id = "${mongodbatlas_privatelink_endpoint.test.project_id}" private_link_id = "${mongodbatlas_privatelink_endpoint.test.private_link_id}" - interface_endpoint_id = "${aws_vpc_endpoint.ptfe_service.id}" + endpoint_service_id = "${aws_vpc_endpoint.ptfe_service.id}" + provider_name ="AWS" } data "mongodbatlas_privatelink_endpoint_service" "test" { @@ -45,8 +46,8 @@ data "mongodbatlas_privatelink_endpoint_service" "test" { ## Argument Reference * `project_id` - (Required) Unique identifier for the project. -* `private_link_id` - (Required) Unique identifier of the `AWS` or `AZURE` PrivateLink connection. -* `endpoint_service_id` - (Required) Unique identifier of the private endpoint service for which you want to create a private endpoint service. +* `private_link_id` - (Required) Unique identifier of the private endpoint service for which you want to retrieve a private endpoint. +* `endpoint_service_id` - (Required) Unique identifier of the `AWS` or `AZURE` resource. * `provider_name` - (Required) Cloud provider for which you want to create a private endpoint. Atlas accepts `AWS` or `AZURE`. ## Attributes Reference diff --git a/website/docs/r/privatelink_endpoint_service.html.markdown b/website/docs/r/privatelink_endpoint_service.html.markdown index 841b2dc2ba..16b23f60d9 100644 --- a/website/docs/r/privatelink_endpoint_service.html.markdown +++ b/website/docs/r/privatelink_endpoint_service.html.markdown @@ -76,7 +76,7 @@ In addition to all arguments above, the following attributes are exported: Private Endpoint Link Connection can be imported using project ID and username, in the format `{project_id}--{private_link_id}--{endpoint_service_id}--{provider_name}`, e.g. ``` -$ terraform import mongodbatlas_privatelink_endpoint_service.test 1112222b3bf99403840e8934--vpce-4242342343--3242342343112--AWS +$ terraform import mongodbatlas_privatelink_endpoint_service.test 1112222b3bf99403840e8934--3242342343112--vpce-4242342343--AWS ``` See detailed information for arguments and attributes: [MongoDB API Private Endpoint Link Connection](https://docs.atlas.mongodb.com/reference/api/private-endpoints-endpoint-create-one/)