From d3eb725c8b600e8cde981d42d7c2f6b445efe260 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Mon, 17 Oct 2022 12:37:15 -0500 Subject: [PATCH 01/16] Add support for serverless private endpoints --- go.mod | 2 +- go.sum | 6 + ...privatelink_endpoint_service_serverless.go | 98 +++++++ ...telink_endpoint_service_serverless_test.go | 115 ++++++++ mongodbatlas/provider.go | 229 ++++++++-------- ...dbatlas_privatelink_endpoint_serverless.go | 248 ++++++++++++++++++ ...as_privatelink_endpoint_serverless_test.go | 142 ++++++++++ ...privatelink_endpoint_service_serverless.go | 240 +++++++++++++++++ ...telink_endpoint_service_serverless_test.go | 153 +++++++++++ 9 files changed, 1119 insertions(+), 114 deletions(-) create mode 100644 mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless.go create mode 100644 mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless_test.go create mode 100644 mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go create mode 100644 mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless_test.go create mode 100644 mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go create mode 100644 mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless_test.go diff --git a/go.mod b/go.mod index c721ea3c05..e565b83244 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/mwielbut/pointy v1.1.0 github.com/spf13/cast v1.5.0 github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f - go.mongodb.org/atlas v0.16.1-0.20220823081124-819fb5448bfe + go.mongodb.org/atlas v0.17.1-0.20221014180449-ac6bf94f55ee go.mongodb.org/realm v0.1.0 ) diff --git a/go.sum b/go.sum index 15bbe1f43b..c21bf0b903 100644 --- a/go.sum +++ b/go.sum @@ -927,6 +927,12 @@ go.etcd.io/etcd v0.0.0-20200513171258-e048e166ab9c/go.mod h1:xCI7ZzBfRuGgBXyXO6y go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M= go.mongodb.org/atlas v0.16.1-0.20220823081124-819fb5448bfe h1:jmRFnzQejpiVo7xsPSCUYOqIzltc9Z95UuLr5fy5+qM= go.mongodb.org/atlas v0.16.1-0.20220823081124-819fb5448bfe/go.mod h1:GUuW7/ZrHzCO0o47aiqhokN0N6i0GM3yraRyHIBTykU= +go.mongodb.org/atlas v0.16.1-0.20221010173144-9997c59cd605 h1:12Womm9VlCopRecm8Zb9Go1N1uVrGqxVKXdrl0+AcVk= +go.mongodb.org/atlas v0.16.1-0.20221010173144-9997c59cd605/go.mod h1:GUuW7/ZrHzCO0o47aiqhokN0N6i0GM3yraRyHIBTykU= +go.mongodb.org/atlas v0.16.1-0.20221012041413-786c00762719 h1:rZU2GzEZSoM4YCck8244pg2+KotHo07cjBTsUnaON8k= +go.mongodb.org/atlas v0.16.1-0.20221012041413-786c00762719/go.mod h1:GUuW7/ZrHzCO0o47aiqhokN0N6i0GM3yraRyHIBTykU= +go.mongodb.org/atlas v0.17.1-0.20221014180449-ac6bf94f55ee h1:KaIgMuhmsvuIX8h5WPFVeNPBtM0wFw3ZaSlCCmmQNKA= +go.mongodb.org/atlas v0.17.1-0.20221014180449-ac6bf94f55ee/go.mod h1:GUuW7/ZrHzCO0o47aiqhokN0N6i0GM3yraRyHIBTykU= 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_privatelink_endpoint_service_serverless.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless.go new file mode 100644 index 0000000000..50467b7a2f --- /dev/null +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless.go @@ -0,0 +1,98 @@ +package mongodbatlas + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceMongoDBAtlasPrivateLinkEndpointServerless() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceMongoDBAtlasPrivateEndpointServiceServerlessLinkRead, + Schema: map[string]*schema.Schema{ + "project_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "instance_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "endpoint_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "endpoint_service_name": { + Type: schema.TypeString, + Computed: true, + }, + "cloud_provider_endpoint_id": { + Type: schema.TypeString, + Computed: true, + }, + "error_message": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceMongoDBAtlasPrivateEndpointServiceServerlessLinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // Get client connection. + conn := meta.(*MongoDBClient).Atlas + + 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) + if err != nil { + return diag.FromErr(fmt.Errorf(errorServiceEndpointRead, endpointID, err)) + } + + if err := d.Set("error_message", serviceEndpoint.ErrorMessage); err != nil { + return diag.FromErr(fmt.Errorf(errorEndpointSetting, "error_message", endpointID, err)) + } + + if err := d.Set("status", serviceEndpoint.Status); err != nil { + return diag.FromErr(fmt.Errorf(errorEndpointSetting, "status", endpointID, err)) + } + + if err := d.Set("comment", serviceEndpoint.Comment); err != nil { + return diag.FromErr(fmt.Errorf(errorEndpointSetting, "comment", endpointID, err)) + } + + if err := d.Set("error_message", serviceEndpoint.ErrorMessage); err != nil { + return diag.FromErr(fmt.Errorf(errorEndpointSetting, "error_message", endpointID, err)) + } + + if err := d.Set("endpoint_service_name", serviceEndpoint.EndpointServiceName); err != nil { + return diag.FromErr(fmt.Errorf(errorEndpointSetting, "endpoint_service_name", endpointID, err)) + } + + if err := d.Set("cloud_provider_endpoint_id", serviceEndpoint.CloudProviderEndpointID); err != nil { + return diag.FromErr(fmt.Errorf(errorEndpointSetting, "cloud_provider_endpoint_id", endpointID, err)) + } + + d.SetId(encodeStateID(map[string]string{ + "project_id": projectID, + "instance_name": instanceName, + "endpoint_id": endpointID, + })) + + return nil +} diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless_test.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless_test.go new file mode 100644 index 0000000000..41d59a34d8 --- /dev/null +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless_test.go @@ -0,0 +1,115 @@ +package mongodbatlas + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccDataSourceMongoDBAtlasPrivateLinkEndpointServiceServerless_basic(t *testing.T) { + var ( + resourceName = "data.mongodbatlas_privatelink_endpoint_service_serverless.test" + projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + instanceName = "dsserverless" + commentOrigin = "create" + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccDSCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDSMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(projectID, instanceName, commentOrigin), + Check: resource.ComposeTestCheckFunc( + testAccDSCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "comment", commentOrigin), + ), + }, + }, + }) +} + +func testAccDSCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessDestroy(state *terraform.State) error { + conn := testAccProvider.Meta().(*MongoDBClient).Atlas + + for _, rs := range state.RootModule().Resources { + if rs.Type != "data.mongodbatlas_privatelink_endpoint_service_serverless" { + continue + } + + ids := decodeStateID(rs.Primary.ID) + + privateLink, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + if err == nil && privateLink != nil { + return fmt.Errorf("endpoint_id (%s) still exists", ids["endpoint_id"]) + } + } + + return nil +} + +func testAccDSMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(projectID, instanceName, comment string) string { + return fmt.Sprintf(` + + data "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "%[1]s" + instance_name = mongodbatlas_serverless_instance.test.name + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + } + + resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = "%[1]s" + instance_name = mongodbatlas_serverless_instance.test.name + provider_name = "AWS" + } + + + resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "%[1]s" + instance_name = "%[2]s" + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + //cloud_endpoint_id = aws_vpc_endpoint.ptfe_service.id + provider_name = "AWS" + comment = "%[3]s" + } + + resource "mongodbatlas_serverless_instance" "test" { + project_id = "%[1]s" + name = "%[2]s" + provider_settings_backing_provider_name = "AWS" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST_1" + continuous_backup_enabled = true + } + + `, projectID, instanceName, comment) +} + +func testAccDSCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*MongoDBClient).Atlas + + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("not found: %s", resourceName) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("no ID is set") + } + + ids := decodeStateID(rs.Primary.ID) + + _, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + if err == nil { + return nil + } + + return fmt.Errorf("endpoint_id (%s) does not exist", ids["endpoint_id"]) + } +} diff --git a/mongodbatlas/provider.go b/mongodbatlas/provider.go index 2fddb58bec..e132589f89 100644 --- a/mongodbatlas/provider.go +++ b/mongodbatlas/provider.go @@ -71,125 +71,128 @@ func Provider() *schema.Provider { func getDataSourcesMap() map[string]*schema.Resource { dataSourcesMap := map[string]*schema.Resource{ - "mongodbatlas_advanced_cluster": dataSourceMongoDBAtlasAdvancedCluster(), - "mongodbatlas_advanced_clusters": dataSourceMongoDBAtlasAdvancedClusters(), - "mongodbatlas_custom_db_role": dataSourceMongoDBAtlasCustomDBRole(), - "mongodbatlas_custom_db_roles": dataSourceMongoDBAtlasCustomDBRoles(), - "mongodbatlas_database_user": dataSourceMongoDBAtlasDatabaseUser(), - "mongodbatlas_database_users": dataSourceMongoDBAtlasDatabaseUsers(), - "mongodbatlas_project": dataSourceMongoDBAtlasProject(), - "mongodbatlas_projects": dataSourceMongoDBAtlasProjects(), - "mongodbatlas_cluster": dataSourceMongoDBAtlasCluster(), - "mongodbatlas_clusters": dataSourceMongoDBAtlasClusters(), - "mongodbatlas_cloud_provider_snapshot": dataSourceMongoDBAtlasCloudProviderSnapshot(), - "mongodbatlas_cloud_provider_snapshots": dataSourceMongoDBAtlasCloudProviderSnapshots(), - "mongodbatlas_network_container": dataSourceMongoDBAtlasNetworkContainer(), - "mongodbatlas_network_containers": dataSourceMongoDBAtlasNetworkContainers(), - "mongodbatlas_network_peering": dataSourceMongoDBAtlasNetworkPeering(), - "mongodbatlas_network_peerings": dataSourceMongoDBAtlasNetworkPeerings(), - "mongodbatlas_cloud_provider_snapshot_restore_job": dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJob(), - "mongodbatlas_cloud_provider_snapshot_restore_jobs": dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJobs(), - "mongodbatlas_maintenance_window": dataSourceMongoDBAtlasMaintenanceWindow(), - "mongodbatlas_auditing": dataSourceMongoDBAtlasAuditing(), - "mongodbatlas_team": dataSourceMongoDBAtlasTeam(), - "mongodbatlas_teams": dataSourceMongoDBAtlasTeam(), - "mongodbatlas_global_cluster_config": dataSourceMongoDBAtlasGlobalCluster(), - "mongodbatlas_alert_configuration": dataSourceMongoDBAtlasAlertConfiguration(), - "mongodbatlas_x509_authentication_database_user": dataSourceMongoDBAtlasX509AuthDBUser(), - "mongodbatlas_private_endpoint_regional_mode": dataSourceMongoDBAtlasPrivateEndpointRegionalMode(), - "mongodbatlas_privatelink_endpoint": dataSourceMongoDBAtlasPrivateLinkEndpoint(), - "mongodbatlas_privatelink_endpoint_service": dataSourceMongoDBAtlasPrivateEndpointServiceLink(), - "mongodbatlas_privatelink_endpoint_service_adl": dataSourceMongoDBAtlasPrivateLinkEndpointServiceADL(), - "mongodbatlas_privatelink_endpoints_service_adl": dataSourceMongoDBAtlasPrivateLinkEndpointsServiceADL(), - "mongodbatlas_cloud_provider_snapshot_backup_policy": dataSourceMongoDBAtlasCloudProviderSnapshotBackupPolicy(), - "mongodbatlas_cloud_backup_schedule": dataSourceMongoDBAtlasCloudBackupSchedule(), - "mongodbatlas_third_party_integrations": dataSourceMongoDBAtlasThirdPartyIntegrations(), - "mongodbatlas_third_party_integration": dataSourceMongoDBAtlasThirdPartyIntegration(), - "mongodbatlas_project_ip_access_list": dataSourceMongoDBAtlasProjectIPAccessList(), - "mongodbatlas_cloud_provider_access": dataSourceMongoDBAtlasCloudProviderAccessList(), - "mongodbatlas_cloud_provider_access_setup": dataSourceMongoDBAtlasCloudProviderAccessSetup(), - "mongodbatlas_custom_dns_configuration_cluster_aws": dataSourceMongoDBAtlasCustomDNSConfigurationAWS(), - "mongodbatlas_online_archive": dataSourceMongoDBAtlasOnlineArchive(), - "mongodbatlas_online_archives": dataSourceMongoDBAtlasOnlineArchives(), - "mongodbatlas_ldap_configuration": dataSourceMongoDBAtlasLDAPConfiguration(), - "mongodbatlas_ldap_verify": dataSourceMongoDBAtlasLDAPVerify(), - "mongodbatlas_search_index": dataSourceMongoDBAtlasSearchIndex(), - "mongodbatlas_search_indexes": dataSourceMongoDBAtlasSearchIndexes(), - "mongodbatlas_data_lake": dataSourceMongoDBAtlasDataLake(), - "mongodbatlas_data_lakes": dataSourceMongoDBAtlasDataLakes(), - "mongodbatlas_event_trigger": dataSourceMongoDBAtlasEventTrigger(), - "mongodbatlas_event_triggers": dataSourceMongoDBAtlasEventTriggers(), - "mongodbatlas_project_invitation": dataSourceMongoDBAtlasProjectInvitation(), - "mongodbatlas_org_invitation": dataSourceMongoDBAtlasOrgInvitation(), - "mongodbatlas_cloud_backup_snapshot": dataSourceMongoDBAtlasCloudBackupSnapshot(), - "mongodbatlas_cloud_backup_snapshots": dataSourceMongoDBAtlasCloudBackupSnapshots(), - "mongodbatlas_cloud_backup_snapshot_restore_job": dataSourceMongoDBAtlasCloudBackupSnapshotRestoreJob(), - "mongodbatlas_cloud_backup_snapshot_restore_jobs": dataSourceMongoDBAtlasCloudBackupSnapshotRestoreJobs(), - "mongodbatlas_cloud_backup_snapshot_export_bucket": datasourceMongoDBAtlasCloudBackupSnapshotExportBucket(), - "mongodbatlas_cloud_backup_snapshot_export_buckets": datasourceMongoDBAtlasCloudBackupSnapshotExportBuckets(), - "mongodbatlas_cloud_backup_snapshot_export_job": datasourceMongoDBAtlasCloudBackupSnapshotExportJob(), - "mongodbatlas_cloud_backup_snapshot_export_jobs": datasourceMongoDBAtlasCloudBackupSnapshotExportJobs(), - "mongodbatlas_federated_settings": dataSourceMongoDBAtlasFederatedSettings(), - "mongodbatlas_federated_settings_identity_provider": dataSourceMongoDBAtlasFederatedSettingsIdentityProvider(), - "mongodbatlas_federated_settings_identity_providers": dataSourceMongoDBAtlasFederatedSettingsIdentityProviders(), - "mongodbatlas_federated_settings_org_config": dataSourceMongoDBAtlasFederatedSettingsOrganizationConfig(), - "mongodbatlas_federated_settings_org_configs": dataSourceMongoDBAtlasFederatedSettingsOrganizationConfigs(), - "mongodbatlas_federated_settings_org_role_mapping": dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMapping(), - "mongodbatlas_federated_settings_org_role_mappings": dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMappings(), - "mongodbatlas_serverless_instance": dataSourceMongoDBAtlasServerlessInstance(), - "mongodbatlas_serverless_instances": dataSourceMongoDBAtlasServerlessInstances(), + "mongodbatlas_advanced_cluster": dataSourceMongoDBAtlasAdvancedCluster(), + "mongodbatlas_advanced_clusters": dataSourceMongoDBAtlasAdvancedClusters(), + "mongodbatlas_custom_db_role": dataSourceMongoDBAtlasCustomDBRole(), + "mongodbatlas_custom_db_roles": dataSourceMongoDBAtlasCustomDBRoles(), + "mongodbatlas_database_user": dataSourceMongoDBAtlasDatabaseUser(), + "mongodbatlas_database_users": dataSourceMongoDBAtlasDatabaseUsers(), + "mongodbatlas_project": dataSourceMongoDBAtlasProject(), + "mongodbatlas_projects": dataSourceMongoDBAtlasProjects(), + "mongodbatlas_cluster": dataSourceMongoDBAtlasCluster(), + "mongodbatlas_clusters": dataSourceMongoDBAtlasClusters(), + "mongodbatlas_cloud_provider_snapshot": dataSourceMongoDBAtlasCloudProviderSnapshot(), + "mongodbatlas_cloud_provider_snapshots": dataSourceMongoDBAtlasCloudProviderSnapshots(), + "mongodbatlas_network_container": dataSourceMongoDBAtlasNetworkContainer(), + "mongodbatlas_network_containers": dataSourceMongoDBAtlasNetworkContainers(), + "mongodbatlas_network_peering": dataSourceMongoDBAtlasNetworkPeering(), + "mongodbatlas_network_peerings": dataSourceMongoDBAtlasNetworkPeerings(), + "mongodbatlas_cloud_provider_snapshot_restore_job": dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJob(), + "mongodbatlas_cloud_provider_snapshot_restore_jobs": dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJobs(), + "mongodbatlas_maintenance_window": dataSourceMongoDBAtlasMaintenanceWindow(), + "mongodbatlas_auditing": dataSourceMongoDBAtlasAuditing(), + "mongodbatlas_team": dataSourceMongoDBAtlasTeam(), + "mongodbatlas_teams": dataSourceMongoDBAtlasTeam(), + "mongodbatlas_global_cluster_config": dataSourceMongoDBAtlasGlobalCluster(), + "mongodbatlas_alert_configuration": dataSourceMongoDBAtlasAlertConfiguration(), + "mongodbatlas_x509_authentication_database_user": dataSourceMongoDBAtlasX509AuthDBUser(), + "mongodbatlas_private_endpoint_regional_mode": dataSourceMongoDBAtlasPrivateEndpointRegionalMode(), + "mongodbatlas_privatelink_endpoint": dataSourceMongoDBAtlasPrivateLinkEndpoint(), + "mongodbatlas_privatelink_endpoint_service": dataSourceMongoDBAtlasPrivateEndpointServiceLink(), + "mongodbatlas_privatelink_endpoint_service_serverless": dataSourceMongoDBAtlasPrivateLinkEndpointServerless(), + "mongodbatlas_privatelink_endpoint_service_adl": dataSourceMongoDBAtlasPrivateLinkEndpointServiceADL(), + "mongodbatlas_privatelink_endpoints_service_adl": dataSourceMongoDBAtlasPrivateLinkEndpointsServiceADL(), + "mongodbatlas_cloud_provider_snapshot_backup_policy": dataSourceMongoDBAtlasCloudProviderSnapshotBackupPolicy(), + "mongodbatlas_cloud_backup_schedule": dataSourceMongoDBAtlasCloudBackupSchedule(), + "mongodbatlas_third_party_integrations": dataSourceMongoDBAtlasThirdPartyIntegrations(), + "mongodbatlas_third_party_integration": dataSourceMongoDBAtlasThirdPartyIntegration(), + "mongodbatlas_project_ip_access_list": dataSourceMongoDBAtlasProjectIPAccessList(), + "mongodbatlas_cloud_provider_access": dataSourceMongoDBAtlasCloudProviderAccessList(), + "mongodbatlas_cloud_provider_access_setup": dataSourceMongoDBAtlasCloudProviderAccessSetup(), + "mongodbatlas_custom_dns_configuration_cluster_aws": dataSourceMongoDBAtlasCustomDNSConfigurationAWS(), + "mongodbatlas_online_archive": dataSourceMongoDBAtlasOnlineArchive(), + "mongodbatlas_online_archives": dataSourceMongoDBAtlasOnlineArchives(), + "mongodbatlas_ldap_configuration": dataSourceMongoDBAtlasLDAPConfiguration(), + "mongodbatlas_ldap_verify": dataSourceMongoDBAtlasLDAPVerify(), + "mongodbatlas_search_index": dataSourceMongoDBAtlasSearchIndex(), + "mongodbatlas_search_indexes": dataSourceMongoDBAtlasSearchIndexes(), + "mongodbatlas_data_lake": dataSourceMongoDBAtlasDataLake(), + "mongodbatlas_data_lakes": dataSourceMongoDBAtlasDataLakes(), + "mongodbatlas_event_trigger": dataSourceMongoDBAtlasEventTrigger(), + "mongodbatlas_event_triggers": dataSourceMongoDBAtlasEventTriggers(), + "mongodbatlas_project_invitation": dataSourceMongoDBAtlasProjectInvitation(), + "mongodbatlas_org_invitation": dataSourceMongoDBAtlasOrgInvitation(), + "mongodbatlas_cloud_backup_snapshot": dataSourceMongoDBAtlasCloudBackupSnapshot(), + "mongodbatlas_cloud_backup_snapshots": dataSourceMongoDBAtlasCloudBackupSnapshots(), + "mongodbatlas_cloud_backup_snapshot_restore_job": dataSourceMongoDBAtlasCloudBackupSnapshotRestoreJob(), + "mongodbatlas_cloud_backup_snapshot_restore_jobs": dataSourceMongoDBAtlasCloudBackupSnapshotRestoreJobs(), + "mongodbatlas_cloud_backup_snapshot_export_bucket": datasourceMongoDBAtlasCloudBackupSnapshotExportBucket(), + "mongodbatlas_cloud_backup_snapshot_export_buckets": datasourceMongoDBAtlasCloudBackupSnapshotExportBuckets(), + "mongodbatlas_cloud_backup_snapshot_export_job": datasourceMongoDBAtlasCloudBackupSnapshotExportJob(), + "mongodbatlas_cloud_backup_snapshot_export_jobs": datasourceMongoDBAtlasCloudBackupSnapshotExportJobs(), + "mongodbatlas_federated_settings": dataSourceMongoDBAtlasFederatedSettings(), + "mongodbatlas_federated_settings_identity_provider": dataSourceMongoDBAtlasFederatedSettingsIdentityProvider(), + "mongodbatlas_federated_settings_identity_providers": dataSourceMongoDBAtlasFederatedSettingsIdentityProviders(), + "mongodbatlas_federated_settings_org_config": dataSourceMongoDBAtlasFederatedSettingsOrganizationConfig(), + "mongodbatlas_federated_settings_org_configs": dataSourceMongoDBAtlasFederatedSettingsOrganizationConfigs(), + "mongodbatlas_federated_settings_org_role_mapping": dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMapping(), + "mongodbatlas_federated_settings_org_role_mappings": dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMappings(), + "mongodbatlas_serverless_instance": dataSourceMongoDBAtlasServerlessInstance(), + "mongodbatlas_serverless_instances": dataSourceMongoDBAtlasServerlessInstances(), } return dataSourcesMap } func getResourcesMap() map[string]*schema.Resource { resourcesMap := map[string]*schema.Resource{ - "mongodbatlas_advanced_cluster": resourceMongoDBAtlasAdvancedCluster(), - "mongodbatlas_custom_db_role": resourceMongoDBAtlasCustomDBRole(), - "mongodbatlas_database_user": resourceMongoDBAtlasDatabaseUser(), - "mongodbatlas_project": resourceMongoDBAtlasProject(), - "mongodbatlas_cluster": resourceMongoDBAtlasCluster(), - "mongodbatlas_cloud_provider_snapshot": resourceMongoDBAtlasCloudProviderSnapshot(), - "mongodbatlas_network_container": resourceMongoDBAtlasNetworkContainer(), - "mongodbatlas_cloud_provider_snapshot_restore_job": resourceMongoDBAtlasCloudProviderSnapshotRestoreJob(), - "mongodbatlas_network_peering": resourceMongoDBAtlasNetworkPeering(), - "mongodbatlas_encryption_at_rest": resourceMongoDBAtlasEncryptionAtRest(), - "mongodbatlas_private_ip_mode": resourceMongoDBAtlasPrivateIPMode(), - "mongodbatlas_maintenance_window": resourceMongoDBAtlasMaintenanceWindow(), - "mongodbatlas_auditing": resourceMongoDBAtlasAuditing(), - "mongodbatlas_team": resourceMongoDBAtlasTeam(), - "mongodbatlas_teams": resourceMongoDBAtlasTeam(), - "mongodbatlas_global_cluster_config": resourceMongoDBAtlasGlobalCluster(), - "mongodbatlas_alert_configuration": resourceMongoDBAtlasAlertConfiguration(), - "mongodbatlas_x509_authentication_database_user": resourceMongoDBAtlasX509AuthDBUser(), - "mongodbatlas_private_endpoint_regional_mode": resourceMongoDBAtlasPrivateEndpointRegionalMode(), - "mongodbatlas_privatelink_endpoint": resourceMongoDBAtlasPrivateLinkEndpoint(), - "mongodbatlas_privatelink_endpoint_service": resourceMongoDBAtlasPrivateEndpointServiceLink(), - "mongodbatlas_privatelink_endpoint_service_adl": resourceMongoDBAtlasPrivateLinkEndpointServiceADL(), - "mongodbatlas_cloud_provider_snapshot_backup_policy": resourceMongoDBAtlasCloudProviderSnapshotBackupPolicy(), - "mongodbatlas_third_party_integration": resourceMongoDBAtlasThirdPartyIntegration(), - "mongodbatlas_project_ip_access_list": resourceMongoDBAtlasProjectIPAccessList(), - "mongodbatlas_cloud_provider_access": resourceMongoDBAtlasCloudProviderAccess(), - "mongodbatlas_online_archive": resourceMongoDBAtlasOnlineArchive(), - "mongodbatlas_custom_dns_configuration_cluster_aws": resourceMongoDBAtlasCustomDNSConfiguration(), - "mongodbatlas_ldap_configuration": resourceMongoDBAtlasLDAPConfiguration(), - "mongodbatlas_ldap_verify": resourceMongoDBAtlasLDAPVerify(), - "mongodbatlas_cloud_provider_access_setup": resourceMongoDBAtlasCloudProviderAccessSetup(), - "mongodbatlas_cloud_provider_access_authorization": resourceMongoDBAtlasCloudProviderAccessAuthorization(), - "mongodbatlas_search_index": resourceMongoDBAtlasSearchIndex(), - "mongodbatlas_data_lake": resourceMongoDBAtlasDataLake(), - "mongodbatlas_event_trigger": resourceMongoDBAtlasEventTriggers(), - "mongodbatlas_cloud_backup_schedule": resourceMongoDBAtlasCloudBackupSchedule(), - "mongodbatlas_project_invitation": resourceMongoDBAtlasProjectInvitation(), - "mongodbatlas_org_invitation": resourceMongoDBAtlasOrgInvitation(), - "mongodbatlas_cloud_backup_snapshot": resourceMongoDBAtlasCloudBackupSnapshot(), - "mongodbatlas_cloud_backup_snapshot_restore_job": resourceMongoDBAtlasCloudBackupSnapshotRestoreJob(), - "mongodbatlas_cloud_backup_snapshot_export_bucket": resourceMongoDBAtlasCloudBackupSnapshotExportBucket(), - "mongodbatlas_cloud_backup_snapshot_export_job": resourceMongoDBAtlasCloudBackupSnapshotExportJob(), - "mongodbatlas_federated_settings_org_config": resourceMongoDBAtlasFederatedSettingsOrganizationConfig(), - "mongodbatlas_federated_settings_org_role_mapping": resourceMongoDBAtlasFederatedSettingsOrganizationRoleMapping(), - "mongodbatlas_federated_settings_identity_provider": resourceMongoDBAtlasFederatedSettingsIdentityProvider(), - "mongodbatlas_serverless_instance": resourceMongoDBAtlasServerlessInstance(), + "mongodbatlas_advanced_cluster": resourceMongoDBAtlasAdvancedCluster(), + "mongodbatlas_custom_db_role": resourceMongoDBAtlasCustomDBRole(), + "mongodbatlas_database_user": resourceMongoDBAtlasDatabaseUser(), + "mongodbatlas_project": resourceMongoDBAtlasProject(), + "mongodbatlas_cluster": resourceMongoDBAtlasCluster(), + "mongodbatlas_cloud_provider_snapshot": resourceMongoDBAtlasCloudProviderSnapshot(), + "mongodbatlas_network_container": resourceMongoDBAtlasNetworkContainer(), + "mongodbatlas_cloud_provider_snapshot_restore_job": resourceMongoDBAtlasCloudProviderSnapshotRestoreJob(), + "mongodbatlas_network_peering": resourceMongoDBAtlasNetworkPeering(), + "mongodbatlas_encryption_at_rest": resourceMongoDBAtlasEncryptionAtRest(), + "mongodbatlas_private_ip_mode": resourceMongoDBAtlasPrivateIPMode(), + "mongodbatlas_maintenance_window": resourceMongoDBAtlasMaintenanceWindow(), + "mongodbatlas_auditing": resourceMongoDBAtlasAuditing(), + "mongodbatlas_team": resourceMongoDBAtlasTeam(), + "mongodbatlas_teams": resourceMongoDBAtlasTeam(), + "mongodbatlas_global_cluster_config": resourceMongoDBAtlasGlobalCluster(), + "mongodbatlas_alert_configuration": resourceMongoDBAtlasAlertConfiguration(), + "mongodbatlas_x509_authentication_database_user": resourceMongoDBAtlasX509AuthDBUser(), + "mongodbatlas_private_endpoint_regional_mode": resourceMongoDBAtlasPrivateEndpointRegionalMode(), + "mongodbatlas_privatelink_endpoint": resourceMongoDBAtlasPrivateLinkEndpoint(), + "mongodbatlas_privatelink_endpoint_serverless": resourceMongoDBAtlasPrivateLinkEndpointServerless(), + "mongodbatlas_privatelink_endpoint_service": resourceMongoDBAtlasPrivateEndpointServiceLink(), + "mongodbatlas_privatelink_endpoint_service_adl": resourceMongoDBAtlasPrivateLinkEndpointServiceADL(), + "mongodbatlas_privatelink_endpoint_service_serverless": resourceMongoDBAtlasPrivateLinkEndpointServiceServerless(), + "mongodbatlas_cloud_provider_snapshot_backup_policy": resourceMongoDBAtlasCloudProviderSnapshotBackupPolicy(), + "mongodbatlas_third_party_integration": resourceMongoDBAtlasThirdPartyIntegration(), + "mongodbatlas_project_ip_access_list": resourceMongoDBAtlasProjectIPAccessList(), + "mongodbatlas_cloud_provider_access": resourceMongoDBAtlasCloudProviderAccess(), + "mongodbatlas_online_archive": resourceMongoDBAtlasOnlineArchive(), + "mongodbatlas_custom_dns_configuration_cluster_aws": resourceMongoDBAtlasCustomDNSConfiguration(), + "mongodbatlas_ldap_configuration": resourceMongoDBAtlasLDAPConfiguration(), + "mongodbatlas_ldap_verify": resourceMongoDBAtlasLDAPVerify(), + "mongodbatlas_cloud_provider_access_setup": resourceMongoDBAtlasCloudProviderAccessSetup(), + "mongodbatlas_cloud_provider_access_authorization": resourceMongoDBAtlasCloudProviderAccessAuthorization(), + "mongodbatlas_search_index": resourceMongoDBAtlasSearchIndex(), + "mongodbatlas_data_lake": resourceMongoDBAtlasDataLake(), + "mongodbatlas_event_trigger": resourceMongoDBAtlasEventTriggers(), + "mongodbatlas_cloud_backup_schedule": resourceMongoDBAtlasCloudBackupSchedule(), + "mongodbatlas_project_invitation": resourceMongoDBAtlasProjectInvitation(), + "mongodbatlas_org_invitation": resourceMongoDBAtlasOrgInvitation(), + "mongodbatlas_cloud_backup_snapshot": resourceMongoDBAtlasCloudBackupSnapshot(), + "mongodbatlas_cloud_backup_snapshot_restore_job": resourceMongoDBAtlasCloudBackupSnapshotRestoreJob(), + "mongodbatlas_cloud_backup_snapshot_export_bucket": resourceMongoDBAtlasCloudBackupSnapshotExportBucket(), + "mongodbatlas_cloud_backup_snapshot_export_job": resourceMongoDBAtlasCloudBackupSnapshotExportJob(), + "mongodbatlas_federated_settings_org_config": resourceMongoDBAtlasFederatedSettingsOrganizationConfig(), + "mongodbatlas_federated_settings_org_role_mapping": resourceMongoDBAtlasFederatedSettingsOrganizationRoleMapping(), + "mongodbatlas_federated_settings_identity_provider": resourceMongoDBAtlasFederatedSettingsIdentityProvider(), + "mongodbatlas_serverless_instance": resourceMongoDBAtlasServerlessInstance(), } return resourcesMap } diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go new file mode 100644 index 0000000000..54696d1f95 --- /dev/null +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go @@ -0,0 +1,248 @@ +package mongodbatlas + +import ( + "context" + "errors" + "fmt" + "log" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + matlas "go.mongodb.org/atlas/mongodbatlas" +) + +const ( + errorServerlessEndpointAdd = "error adding MongoDB Serverless PrivateLink Endpoint Connection(%s): %s" + errorServerlessEndpointDelete = "error deleting MongoDB Serverless PrivateLink Endpoint Connection(%s): %s" +) + +func resourceMongoDBAtlasPrivateLinkEndpointServerless() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceMongoDBAtlasPrivateLinkEndpointServerlessCreate, + ReadContext: resourceMongoDBAtlasPrivateLinkEndpointServerlessRead, + DeleteContext: resourceMongoDBAtlasPrivateLinkEndpointServerlessDelete, + Importer: &schema.ResourceImporter{ + StateContext: resourceMongoDBAtlasPrivateLinkEndpointServerlessImportState, + }, + Schema: map[string]*schema.Schema{ + "project_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "instance_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "endpoint_id": { + Type: schema.TypeString, + Computed: true, + }, + "provider_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"AWS"}, false), + }, + "endpoint_service_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(1 * time.Hour), + Delete: schema.DefaultTimeout(1 * time.Hour), + }, + } +} + +func resourceMongoDBAtlasPrivateLinkEndpointServerlessCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // Get client connection. + conn := meta.(*MongoDBClient).Atlas + projectID := d.Get("project_id").(string) + instanceName := d.Get("instance_name").(string) + + privateLinkRequest := &matlas.ServerlessPrivateEndpointConnection{ + Comment: "create", + } + + endPoint, _, err := conn.ServerlessPrivateEndpoints.Create(ctx, projectID, instanceName, privateLinkRequest) + if err != nil { + return diag.Errorf(errorServerlessServiceEndpointAdd, privateLinkRequest.CloudProviderEndpointID, err) + } + + stateConf := &resource.StateChangeConf{ + Pending: []string{"RESERVATION_REQUESTED", "INITIATING", "DELETING"}, + Target: []string{"RESERVED", "FAILED", "DELETED", "AVAILABLE"}, + Refresh: resourcePrivateLinkEndpointServerlessRefreshFunc(ctx, conn, projectID, instanceName, endPoint.ID), + Timeout: d.Timeout(schema.TimeoutCreate), + MinTimeout: 5 * time.Second, + Delay: 3 * time.Second, + } + // RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. + // Wait, catching any errors + _, err = stateConf.WaitForStateContext(ctx) + if err != nil { + return diag.FromErr(fmt.Errorf(errorServerlessEndpointAdd, err, endPoint.ID)) + } + + d.SetId(encodeStateID(map[string]string{ + "project_id": projectID, + "instance_name": instanceName, + "endpoint_id": endPoint.ID, + })) + + return resourceMongoDBAtlasPrivateLinkEndpointServerlessRead(ctx, d, meta) +} + +func resourceMongoDBAtlasPrivateLinkEndpointServerlessRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // Get client connection. + conn := meta.(*MongoDBClient).Atlas + ids := decodeStateID(d.Id()) + projectID := ids["project_id"] + instanceName := ids["instance_name"] + endpointID := ids["endpoint_id"] + + privateLinkResponse, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + if err != nil { + // case 404/ 400 + // 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) + } + + if err := d.Set("endpoint_id", privateLinkResponse.ID); err != nil { + return diag.Errorf("error setting `endpoint_id` for endpoint_id (%s): %s", d.Id(), err) + } + + if err := d.Set("instance_name", instanceName); err != nil { + return diag.Errorf("error setting `instance Name` for endpoint_id (%s): %s", d.Id(), err) + } + + if err := d.Set("endpoint_service_name", privateLinkResponse.EndpointServiceName); err != nil { + return diag.Errorf("error setting `endpoint_service_name Name` for endpoint_id (%s): %s", d.Id(), err) + } + + d.SetId(encodeStateID(map[string]string{ + "project_id": projectID, + "instance_name": instanceName, + "endpoint_id": privateLinkResponse.ID, + })) + + return nil +} + +func resourceMongoDBAtlasPrivateLinkEndpointServerlessDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // Get client connection. + conn := meta.(*MongoDBClient).Atlas + ids := decodeStateID(d.Id()) + projectID := ids["project_id"] + instanceName := ids["instance_name"] + endpointID := ids["endpoint_id"] + + _, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + if err != nil { + // 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) + } + + _, err = conn.ServerlessPrivateEndpoints.Delete(ctx, projectID, instanceName, endpointID) + if err != nil { + return diag.Errorf("error deleting serverless private link endpoint(%s): %s", endpointID, err) + } + + stateConf := &resource.StateChangeConf{ + Pending: []string{"DELETING"}, + Target: []string{"DELETED", "FAILED"}, + Refresh: resourcePrivateLinkEndpointServerlessRefreshFunc(ctx, conn, projectID, instanceName, endpointID), + Timeout: d.Timeout(schema.TimeoutDelete), + MinTimeout: 5 * time.Second, + Delay: 3 * time.Second, + } + // Wait, catching any errors + _, err = stateConf.WaitForStateContext(ctx) + if err != nil { + return diag.FromErr(fmt.Errorf(errorServerlessEndpointDelete, endpointID, err)) + } + + return nil +} + +func resourceMongoDBAtlasPrivateLinkEndpointServerlessImportState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + conn := meta.(*MongoDBClient).Atlas + + parts := strings.SplitN(d.Id(), "--", 3) + if len(parts) != 3 { + return nil, errors.New("import format error: to import a search index, use the format {project_id}--{instance_name}--{endpoint_id}") + } + + projectID := parts[0] + instanceName := parts[1] + endpointID := parts[2] + + privateLinkResponse, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + if err != nil { + return nil, fmt.Errorf("couldn't import serverless private link endpoint (%s) in projectID (%s) , error: %s", endpointID, projectID, err) + } + + if err := d.Set("project_id", projectID); err != nil { + log.Printf("[WARN] Error setting project_id for (%s): %s", projectID, err) + } + + if err := d.Set("endpoint_id", endpointID); err != nil { + log.Printf("[WARN] Error setting endpoint_id for (%s): %s", endpointID, err) + } + if err := d.Set("instance_name", instanceName); err != nil { + log.Printf("[WARN] Error setting instance_name for (%s): %s", endpointID, err) + } + + if err := d.Set("endpoint_service_name", privateLinkResponse.EndpointServiceName); err != nil { + log.Printf("[WARN] Error setting endpoint_service_name for (%s): %s", endpointID, err) + } + + /*if err := d.Set("provider_name", privateLinkResponse.ProviderName); err != nil { + log.Printf("[WARN] Error setting endpoint_service_name for (%s): %s", endpointID, err) + }*/ + + d.SetId(encodeStateID(map[string]string{ + "project_id": projectID, + "instance_name": instanceName, + "endpoint_id": endpointID, + })) + + return []*schema.ResourceData{d}, nil +} + +func resourcePrivateLinkEndpointServerlessRefreshFunc(ctx context.Context, client *matlas.Client, projectID, instanceName, privateLinkID string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + p, resp, err := client.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, privateLinkID) + if err != nil { + if resp.Response.StatusCode == 404 || resp.Response.StatusCode == 400 { + return "", "DELETED", nil + } + + return nil, "REJECTED", err + } + + if p.Status != "WAITING_FOR_USER" { + return "", p.Status, nil + } + + return p, p.Status, nil + } +} diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless_test.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless_test.go new file mode 100644 index 0000000000..7ae8a9d327 --- /dev/null +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless_test.go @@ -0,0 +1,142 @@ +package mongodbatlas + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccResourceMongoDBAtlasPrivateLinkEndpointServerless_basic(t *testing.T) { + var ( + resourceName = "mongodbatlas_privatelink_endpoint_serverless.test" + projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + instanceName = "serverlessplink" + commentOrigin = "this is a comment for serverless private link endpoint" + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServerlessDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMongoDBAtlasPrivateLinkEndpointServerlessConfig(projectID, instanceName, commentOrigin), + Check: resource.ComposeTestCheckFunc( + testAccCheckMongoDBAtlasPrivateLinkEndpointServerlessExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "instance_name", instanceName), + ), + }, + }, + }) +} + +func TestAccResourceMongoDBAtlasPrivateLinkEndpointServerless_importBasic(t *testing.T) { + var ( + resourceName = "mongodbatlas_privatelink_endpoint_serverless.test" + projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + instanceName = "serverlessimport" + commentOrigin = "this is a comment for serverless private link endpoint" + ) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServerlessDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMongoDBAtlasPrivateLinkEndpointServerlessConfig(projectID, instanceName, commentOrigin), + Check: resource.ComposeTestCheckFunc( + //resource.TestCheckResourceAttr(resourceName, "provider_name", "AWS"), + resource.TestCheckResourceAttr(resourceName, "instance_name", instanceName), + ), + }, + { + Config: testAccMongoDBAtlasPrivateLinkEndpointServerlessConfig(projectID, instanceName, commentOrigin), + ResourceName: resourceName, + ImportStateIdFunc: testAccCheckMongoDBAtlasPrivateLinkEndpointServerlessImportStateIDFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckMongoDBAtlasPrivateLinkEndpointServerlessDestroy(state *terraform.State) error { + conn := testAccProvider.Meta().(*MongoDBClient).Atlas + + for _, rs := range state.RootModule().Resources { + if rs.Type != "mongodbatlas_privatelink_endpoint_serverless" { + continue + } + + ids := decodeStateID(rs.Primary.ID) + + privateLink, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + if err == nil && privateLink != nil { + return fmt.Errorf("endpoint_id (%s) still exists", ids["endpoint_id"]) + } + } + + return nil +} + +func testAccMongoDBAtlasPrivateLinkEndpointServerlessConfig(projectID, instanceName, comment string) string { + return fmt.Sprintf(` + + resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = "%[1]s" + instance_name = mongodbatlas_serverless_instance.test.name + provider_name = "AWS" + } + + resource "mongodbatlas_serverless_instance" "test" { + project_id = "%[1]s" + name = "%[2]s" + provider_settings_backing_provider_name = "AWS" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST_1" + continuous_backup_enabled = true + } + + `, projectID, instanceName, comment) +} + +func testAccCheckMongoDBAtlasPrivateLinkEndpointServerlessExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*MongoDBClient).Atlas + + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("not found: %s", resourceName) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("no ID is set") + } + + ids := decodeStateID(rs.Primary.ID) + + _, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + if err == nil { + return nil + } + + return fmt.Errorf("endpoint_id (%s) does not exist", ids["endpoint_id"]) + } +} + +func testAccCheckMongoDBAtlasPrivateLinkEndpointServerlessImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { + return func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return "", fmt.Errorf("not found: %s", resourceName) + } + + ids := decodeStateID(rs.Primary.ID) + + return fmt.Sprintf("%s--%s--%s", ids["project_id"], ids["instance_name"], ids["endpoint_id"]), nil + } +} diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go new file mode 100644 index 0000000000..9fa24ed7dd --- /dev/null +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go @@ -0,0 +1,240 @@ +package mongodbatlas + +import ( + "context" + "errors" + "fmt" + "log" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + matlas "go.mongodb.org/atlas/mongodbatlas" +) + +const ( + errorServerlessServiceEndpointAdd = "error adding MongoDB Serverless PrivateLink Endpoint Connection(%s): %s" + errorServerlessServiceEndpointDelete = "error deleting MongoDB Serverless PrivateLink Endpoint Connection(%s): %s" +) + +func resourceMongoDBAtlasPrivateLinkEndpointServiceServerless() *schema.Resource { + return &schema.Resource{ + CreateWithoutTimeout: resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessCreate, + ReadWithoutTimeout: resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessRead, + DeleteWithoutTimeout: resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessDelete, + Importer: &schema.ResourceImporter{ + StateContext: resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessImportState, + }, + Schema: map[string]*schema.Schema{ + "project_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "instance_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "endpoint_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "comment": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "provider_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"AWS"}, false), + ForceNew: true, + }, + "cloud_endpoint_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + }, + } +} + +func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // Get client connection. + conn := meta.(*MongoDBClient).Atlas + 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) + 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_endpoint_id").(string) + privateLink.ProviderName = d.Get("provider_name").(string) + privateLink.ID = "" + privateLink.Status = "" + privateLink.EndpointServiceName = "" + + endPoint, _, err := conn.ServerlessPrivateEndpoints.Update(ctx, projectID, instanceName, endpointID, privateLink) + if err != nil { + return diag.Errorf(errorServerlessServiceEndpointAdd, endPoint.CloudProviderEndpointID, err) + } + + stateConf := &resource.StateChangeConf{ + Pending: []string{"RESERVATION_REQUESTED", "INITIATING", "DELETING"}, + Target: []string{"RESERVED", "FAILED", "DELETED", "AVAILABLE"}, + Refresh: resourceServiceEndpointServerlessRefreshFunc(ctx, conn, projectID, instanceName, endpointID), + Timeout: 1 * time.Hour, + 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)) + } + + d.SetId(encodeStateID(map[string]string{ + "project_id": projectID, + "instance_name": instanceName, + "endpoint_id": endPoint.ID, + })) + + return resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessRead(ctx, d, meta) +} + +func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // Get client connection. + conn := meta.(*MongoDBClient).Atlas + ids := decodeStateID(d.Id()) + projectID := ids["project_id"] + instanceName := ids["instance_name"] + endpointID := ids["endpoint_id"] + + privateLinkResponse, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + if err != nil { + // 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) + + if err := d.Set("endpoint_id", privateLinkResponse.ID); err != nil { + return diag.Errorf("error setting `endpoint_id` for endpoint_id (%s): %s", d.Id(), err) + } + + if err := d.Set("instance_name", instanceName); err != nil { + return diag.Errorf("error setting `instance Name` for endpoint_id (%s): %s", d.Id(), err) + } + + if err := d.Set("comment", privateLinkResponse.Comment); 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 { + return diag.Errorf("error setting `provider_name` for endpoint_id (%s): %s", d.Id(), err) + } + + d.SetId(encodeStateID(map[string]string{ + "project_id": projectID, + "instance_name": instanceName, + "endpoint_id": privateLinkResponse.ID, + })) + + return nil +} + +func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // Get client connection. + conn := meta.(*MongoDBClient).Atlas + ids := decodeStateID(d.Id()) + projectID := ids["project_id"] + instanceName := ids["instance_name"] + endpointID := ids["endpoint_id"] + + _, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + if err != nil { + // 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 service information: %s", err) + } + + d.SetId("") // Set to null as linked resource will delete servless endpoint + + return nil +} + +func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessImportState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + conn := meta.(*MongoDBClient).Atlas + + parts := strings.SplitN(d.Id(), "--", 3) + if len(parts) != 3 { + return nil, errors.New("import format error: to import a search index, use the format {project_id}--{instance_name}--{endpoint_id}") + } + + projectID := parts[0] + instanceName := parts[1] + endpointID := parts[2] + + _, _, err := conn.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointID) + if err != nil { + return nil, fmt.Errorf("couldn't import serverless private link endpoint (%s) in projectID (%s) , error: %s", endpointID, projectID, err) + } + + if err := d.Set("project_id", projectID); err != nil { + log.Printf("[WARN] Error setting project_id for (%s): %s", projectID, err) + } + + if err := d.Set("endpoint_id", endpointID); err != nil { + log.Printf("[WARN] Error setting endpoint_id for (%s): %s", endpointID, err) + } + if err := d.Set("instance_name", instanceName); err != nil { + log.Printf("[WARN] Error setting instance_name for (%s): %s", endpointID, err) + } + + d.SetId(encodeStateID(map[string]string{ + "project_id": projectID, + "instance_name": instanceName, + "endpoint_id": endpointID, + })) + + return []*schema.ResourceData{d}, nil +} + +func resourceServiceEndpointServerlessRefreshFunc(ctx context.Context, client *matlas.Client, projectID, instanceName, endpointServiceID string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + i, resp, err := client.ServerlessPrivateEndpoints.Get(ctx, projectID, instanceName, endpointServiceID) + if err != nil { + if resp != nil && resp.StatusCode == 404 || resp.Response.StatusCode == 400 { + return "", "DELETED", nil + } + + return nil, "", err + } + + if i.Status != "AVAILABLE" { + return "", i.Status, nil + } + + return i, i.Status, nil + } +} diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless_test.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless_test.go new file mode 100644 index 0000000000..7f7cc44ba5 --- /dev/null +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless_test.go @@ -0,0 +1,153 @@ +package mongodbatlas + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccResourceMongoDBAtlasPrivateLinkEndpointServiceServerless_basic(t *testing.T) { + var ( + resourceName = "mongodbatlas_privatelink_endpoint_service_serverless.test" + projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + instanceName = "serverlesssrv" + commentOrigin = "this is a comment for serverless private link endpoint" + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(projectID, instanceName, commentOrigin), + Check: resource.ComposeTestCheckFunc( + testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "provider_name", "AWS"), + resource.TestCheckResourceAttr(resourceName, "comment", commentOrigin), + ), + }, + }, + }) +} + +func TestAccResourceMongoDBAtlasPrivateLinkEndpointServiceServerless_importBasic(t *testing.T) { + var ( + resourceName = "mongodbatlas_privatelink_endpoint_service_serverless.test" + projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") + instanceName = "serverlesssrvimport" + commentOrigin = "this is a comment for serverless private link endpoint" + ) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckMongoDBAtlasSearchIndexDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(projectID, instanceName, commentOrigin), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "provider_name", "AWS"), + resource.TestCheckResourceAttr(resourceName, "comment", commentOrigin), + ), + }, + { + Config: testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(projectID, instanceName, commentOrigin), + ResourceName: resourceName, + ImportStateIdFunc: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessImportStateIDFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessDestroy(state *terraform.State) error { + conn := testAccProvider.Meta().(*MongoDBClient).Atlas + + for _, rs := range state.RootModule().Resources { + if rs.Type != "mongodbatlas_privatelink_endpoint_service_serverless" { + continue + } + + ids := decodeStateID(rs.Primary.ID) + + privateLink, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + if err == nil && privateLink != nil { + return fmt.Errorf("endpoint_id (%s) still exists", ids["endpoint_id"]) + } + } + + return nil +} + +func testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(projectID, instanceName, comment string) string { + return fmt.Sprintf(` + + resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = "%[1]s" + instance_name = mongodbatlas_serverless_instance.test.name + provider_name = "AWS" + } + + + resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "%[1]s" + instance_name = "%[2]s" + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + //cloud_endpoint_id = aws_vpc_endpoint.ptfe_service.id + provider_name = "AWS" + comment = "%[3]s" + } + + resource "mongodbatlas_serverless_instance" "test" { + project_id = "%[1]s" + name = "%[2]s" + provider_settings_backing_provider_name = "AWS" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST_1" + continuous_backup_enabled = true + } + + `, projectID, instanceName, comment) +} + +func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*MongoDBClient).Atlas + + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("not found: %s", resourceName) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("no ID is set") + } + + ids := decodeStateID(rs.Primary.ID) + + _, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"]) + if err == nil { + return nil + } + + return fmt.Errorf("endpoint_id (%s) does not exist", ids["endpoint_id"]) + } +} + +func testAccCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { + return func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return "", fmt.Errorf("not found: %s", resourceName) + } + + ids := decodeStateID(rs.Primary.ID) + + return fmt.Sprintf("%s--%s--%s", ids["project_id"], ids["instance_name"], ids["endpoint_id"]), nil + } +} From eff840faccf27037b0b4c7e8f898deef217d38d7 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Wed, 9 Nov 2022 12:30:48 -0600 Subject: [PATCH 02/16] Correct lint error --- .../resource_mongodbatlas_privatelink_endpoint_serverless.go | 4 ---- ...ource_mongodbatlas_privatelink_endpoint_serverless_test.go | 1 - ...ce_mongodbatlas_privatelink_endpoint_service_serverless.go | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go index 54696d1f95..9c8d2811bd 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go @@ -215,10 +215,6 @@ func resourceMongoDBAtlasPrivateLinkEndpointServerlessImportState(ctx context.Co log.Printf("[WARN] Error setting endpoint_service_name for (%s): %s", endpointID, err) } - /*if err := d.Set("provider_name", privateLinkResponse.ProviderName); err != nil { - log.Printf("[WARN] Error setting endpoint_service_name for (%s): %s", endpointID, err) - }*/ - d.SetId(encodeStateID(map[string]string{ "project_id": projectID, "instance_name": instanceName, diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless_test.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless_test.go index 7ae8a9d327..6bb3230582 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless_test.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless_test.go @@ -49,7 +49,6 @@ func TestAccResourceMongoDBAtlasPrivateLinkEndpointServerless_importBasic(t *tes { Config: testAccMongoDBAtlasPrivateLinkEndpointServerlessConfig(projectID, instanceName, commentOrigin), Check: resource.ComposeTestCheckFunc( - //resource.TestCheckResourceAttr(resourceName, "provider_name", "AWS"), resource.TestCheckResourceAttr(resourceName, "instance_name", instanceName), ), }, diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go index 9fa24ed7dd..fe6b282055 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go @@ -175,7 +175,7 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessDelete(ctx context. return nil } - return diag.Errorf("error getting Serverless private link endpoint service information: %s", err) + return diag.Errorf(errorServerlessServiceEndpointDelete, endpointID, err) } d.SetId("") // Set to null as linked resource will delete servless endpoint From 8f6bf4f628ee2927294bab1321a69c0639b16d7b Mon Sep 17 00:00:00 2001 From: Zuhair Ahmed Date: Wed, 9 Nov 2022 17:51:01 -0500 Subject: [PATCH 03/16] Update 1.5.0-upgrade-guide.html.markdown --- website/docs/guides/1.5.0-upgrade-guide.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/guides/1.5.0-upgrade-guide.html.markdown b/website/docs/guides/1.5.0-upgrade-guide.html.markdown index aaf8ced902..11909ae448 100644 --- a/website/docs/guides/1.5.0-upgrade-guide.html.markdown +++ b/website/docs/guides/1.5.0-upgrade-guide.html.markdown @@ -11,7 +11,7 @@ MongoDB Atlas Provider 1.5.0: Upgrade and Information Guide The Terraform MongoDB Atlas Provider version 1.5.0 has a number of new and exciting features and changes. New Features: -* You can now manage AWS Serverless Private Endpoints [`mongodbatlas_serverless_private_endpoints`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/serverless_private_endpoints) +* You can now manage private endpoints for Atlas serverless instances on AWS [`mongodbatlas_privatelink_endpoint_severless`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_serverless), [`mongodbatlas_privatelink_endpoint_service_severless`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_service_serverless) * You can now manage AtlasGov Projects [`mongodbatlas_project`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/project) * To enable the Terraform MongoDB Atlas Provider for use with AtlasGov see [`Getting Started Guide`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs#configure-mongodb-atlas-for-government) * You can now manage Microsoft Teams Alert Notifications with [`mongodbatlas_alert_configuration`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/alert_configuration) From 0ae11932370793e3208de2838418875310fe48c1 Mon Sep 17 00:00:00 2001 From: Zuhair Ahmed Date: Wed, 9 Nov 2022 18:15:09 -0500 Subject: [PATCH 04/16] Update 1.5.0-upgrade-guide.html.markdown --- website/docs/guides/1.5.0-upgrade-guide.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/guides/1.5.0-upgrade-guide.html.markdown b/website/docs/guides/1.5.0-upgrade-guide.html.markdown index 11909ae448..aaf8ced902 100644 --- a/website/docs/guides/1.5.0-upgrade-guide.html.markdown +++ b/website/docs/guides/1.5.0-upgrade-guide.html.markdown @@ -11,7 +11,7 @@ MongoDB Atlas Provider 1.5.0: Upgrade and Information Guide The Terraform MongoDB Atlas Provider version 1.5.0 has a number of new and exciting features and changes. New Features: -* You can now manage private endpoints for Atlas serverless instances on AWS [`mongodbatlas_privatelink_endpoint_severless`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_serverless), [`mongodbatlas_privatelink_endpoint_service_severless`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_service_serverless) +* You can now manage AWS Serverless Private Endpoints [`mongodbatlas_serverless_private_endpoints`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/serverless_private_endpoints) * You can now manage AtlasGov Projects [`mongodbatlas_project`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/project) * To enable the Terraform MongoDB Atlas Provider for use with AtlasGov see [`Getting Started Guide`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs#configure-mongodb-atlas-for-government) * You can now manage Microsoft Teams Alert Notifications with [`mongodbatlas_alert_configuration`](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/alert_configuration) From 9ecf9f4674a8403ecfaba23047e0c7292b0f003d Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Wed, 9 Nov 2022 19:23:32 -0600 Subject: [PATCH 05/16] Add documentation for serverless endpoints --- ...dbatlas_privatelink_endpoint_serverless.go | 8 +++ ...privatelink_endpoint_service_serverless.go | 8 +++ ...telink_endpoint_service_serverless_test.go | 1 - ..._endpoint_service_serverless.html.markdown | 62 +++++++++++++++++ ...vatelink_endpoint_serverless.html.markdown | 53 +++++++++++++++ ..._endpoint_service_serverless.html.markdown | 68 +++++++++++++++++++ 6 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 website/docs/d/privatelink_endpoint_service_serverless.html.markdown create mode 100644 website/docs/r/privatelink_endpoint_serverless.html.markdown create mode 100644 website/docs/r/privatelink_endpoint_service_serverless.html.markdown diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go index 9c8d2811bd..fd4ddb09f7 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go @@ -53,6 +53,10 @@ func resourceMongoDBAtlasPrivateLinkEndpointServerless() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "status": { + Type: schema.TypeString, + Computed: true, + }, }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(1 * time.Hour), @@ -132,6 +136,10 @@ func resourceMongoDBAtlasPrivateLinkEndpointServerlessRead(ctx context.Context, return diag.Errorf("error setting `endpoint_service_name Name` for endpoint_id (%s): %s", d.Id(), err) } + if err := d.Set("status", privateLinkResponse.Status); err != nil { + return diag.FromErr(fmt.Errorf(errorPrivateLinkEndpointsSetting, "status", d.Id(), err)) + } + d.SetId(encodeStateID(map[string]string{ "project_id": projectID, "instance_name": instanceName, diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go index fe6b282055..67a826061a 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go @@ -60,6 +60,10 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerless() *schema.Resource Optional: true, ForceNew: true, }, + "status": { + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -149,6 +153,10 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessRead(ctx context.Co return diag.Errorf("error setting `provider_name` for endpoint_id (%s): %s", d.Id(), err) } + if err := d.Set("status", privateLinkResponse.Status); err != nil { + return diag.Errorf("error setting `status` for endpoint_id (%s): %s", d.Id(), err) + } + d.SetId(encodeStateID(map[string]string{ "project_id": projectID, "instance_name": instanceName, diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless_test.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless_test.go index 7f7cc44ba5..66e4a274c2 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless_test.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless_test.go @@ -98,7 +98,6 @@ func testAccMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(projectID, in project_id = "%[1]s" instance_name = "%[2]s" endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id - //cloud_endpoint_id = aws_vpc_endpoint.ptfe_service.id provider_name = "AWS" comment = "%[3]s" } diff --git a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown new file mode 100644 index 0000000000..ce6af1a83c --- /dev/null +++ b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown @@ -0,0 +1,62 @@ +--- +layout: "mongodbatlas" +page_title: "MongoDB Atlas: privatelink_endpoint_service_serverless" +sidebar_current: "docs-mongodbatlas-datasource-privatelink-endpoint-service-serverless" +description: |- +Describes a Serverless PrivateLink endpoint service +--- + + +# Data Source: privatelink_endpoint_service_serverless + +`privatelink_endpoint_service_serverless` Provides a Serverless PrivateLink endpoint service resource. + +-> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. + +## Example Usage + +### Basic +```terraform + +resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name + provider_name = "AWS" +} + + +resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "" + instance_name = "test-db" + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + provider_name = "AWS" + comment = "New serverless endpoint" +} + +resource "mongodbatlas_serverless_instance" "test" { + project_id = "" + name = "test-db" + provider_settings_backing_provider_name = "AWS" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST_1" + continuous_backup_enabled = true +} +``` + + +## Argument Reference + +* `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. +* `instance_name` - (Required) Serverless instance name to attach private +* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. +* `comment` - Human-readable string to associate with this private endpoint. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. +* `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. + +For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Serverless-Private-Endpoints/operation/createOnePrivateEndpointForOneServerlessInstance/) and [MongoDB Atlas API - Online Archive](https://docs.atlas.mongodb.com/reference/api/online-archive/) Documentation. diff --git a/website/docs/r/privatelink_endpoint_serverless.html.markdown b/website/docs/r/privatelink_endpoint_serverless.html.markdown new file mode 100644 index 0000000000..04080ce0ea --- /dev/null +++ b/website/docs/r/privatelink_endpoint_serverless.html.markdown @@ -0,0 +1,53 @@ +--- +layout: "mongodbatlas" +page_title: "MongoDB Atlas: privatelink_endpoint_serverless" +sidebar_current: "docs-mongodbatlas-datasource-privatelink-endpoint-serverless" +description: |- +Describes a Serverless PrivateLink endpoint +--- + + +# Data Source: privatelink_endpoint_serverless + +`privatelink_endpoint_serverless` Provides a Serverless PrivateLink endpoint resource. + +-> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. + +## Example Usage + +### Basic +```terraform + +resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name + provider_name = "AWS" +} + +resource "mongodbatlas_serverless_instance" "test" { + project_id = "" + name = "test-db" + provider_settings_backing_provider_name = "AWS" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST_1" + continuous_backup_enabled = true +} +``` + + +## Argument Reference + +* `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. +* `instance_name` - (Required) Serverless instance name to attach private +* `provider_name` - (Required) Cloud provider name AWS currently supported + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: +* `endpoint_id` - Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. +* `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. +* `comment` - Human-readable string to associate with this private endpoint. +* `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. + +For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/) and [MongoDB Atlas API - Online Archive](https://docs.atlas.mongodb.com/reference/api/online-archive/) Documentation. diff --git a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown new file mode 100644 index 0000000000..373d4d51c8 --- /dev/null +++ b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown @@ -0,0 +1,68 @@ +--- +layout: "mongodbatlas" +page_title: "MongoDB Atlas: privatelink_endpoint_service_serverless" +sidebar_current: "docs-mongodbatlas-datasource-privatelink-endpoint-service-serverless" +description: |- +Describes a Serverless PrivateLink endpoint service +--- + + +# Data Source: privatelink_endpoint_service_serverless + +`privatelink_endpoint_service_serverless` Provides a Serverless PrivateLink endpoint service resource. + +-> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. + +## Example Usage + +### Basic +```terraform +data "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id +} + +resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name + provider_name = "AWS" +} + + +resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "" + instance_name = "test-db" + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + provider_name = "AWS" + comment = "New serverless endpoint" +} + +resource "mongodbatlas_serverless_instance" "test" { + project_id = "" + name = "test-db" + provider_settings_backing_provider_name = "AWS" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST_1" + continuous_backup_enabled = true +} +``` + + +## Argument Reference + +* `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. +* `instance_name` - (Required) Serverless instance name to attach private +* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. +* `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. +* `comment` - Human-readable string to associate with this private endpoint. +* `error_message` - Human-readable error message that indicates the error condition associated with establishing the private endpoint connection. +* `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. + +For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/) and [MongoDB Atlas API - Online Archive](https://docs.atlas.mongodb.com/reference/api/online-archive/) Documentation. From cc5e7e5b459a0c7c8f59a391fbe02d5cf6b0950b Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Wed, 9 Nov 2022 19:41:48 -0600 Subject: [PATCH 06/16] Update Schema timeout values --- ...resource_mongodbatlas_privatelink_endpoint_serverless.go | 4 ++-- ..._mongodbatlas_privatelink_endpoint_service_serverless.go | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go index fd4ddb09f7..be9b263ab8 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go @@ -59,8 +59,8 @@ func resourceMongoDBAtlasPrivateLinkEndpointServerless() *schema.Resource { }, }, Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(1 * time.Hour), - Delete: schema.DefaultTimeout(1 * time.Hour), + Create: schema.DefaultTimeout(2 * time.Hour), + Delete: schema.DefaultTimeout(2 * time.Hour), }, } } diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go index 67a826061a..0f49517f46 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go @@ -65,6 +65,10 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerless() *schema.Resource Computed: true, }, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(2 * time.Hour), + Delete: schema.DefaultTimeout(2 * time.Hour), + }, } } @@ -96,7 +100,7 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessCreate(ctx context. Pending: []string{"RESERVATION_REQUESTED", "INITIATING", "DELETING"}, Target: []string{"RESERVED", "FAILED", "DELETED", "AVAILABLE"}, Refresh: resourceServiceEndpointServerlessRefreshFunc(ctx, conn, projectID, instanceName, endpointID), - Timeout: 1 * time.Hour, + Timeout: d.Timeout(schema.TimeoutCreate), MinTimeout: 5 * time.Second, Delay: 5 * time.Minute, } From 7af4a6a320543b8cc29a536d7bde4e6453638284 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Thu, 10 Nov 2022 08:22:49 -0600 Subject: [PATCH 07/16] Update documentation --- .../privatelink_endpoint_service_serverless.html.markdown | 4 ++-- .../docs/r/privatelink_endpoint_serverless.html.markdown | 6 +++--- .../privatelink_endpoint_service_serverless.html.markdown | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown index ce6af1a83c..b44a207f98 100644 --- a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown @@ -3,13 +3,13 @@ layout: "mongodbatlas" page_title: "MongoDB Atlas: privatelink_endpoint_service_serverless" sidebar_current: "docs-mongodbatlas-datasource-privatelink-endpoint-service-serverless" description: |- -Describes a Serverless PrivateLink endpoint service +Describes a Serverless PrivateLink Endpoint Service --- # Data Source: privatelink_endpoint_service_serverless -`privatelink_endpoint_service_serverless` Provides a Serverless PrivateLink endpoint service resource. +`privatelink_endpoint_service_serverless` Provides a Serverless PrivateLink Endpoint Service resource. -> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. diff --git a/website/docs/r/privatelink_endpoint_serverless.html.markdown b/website/docs/r/privatelink_endpoint_serverless.html.markdown index 04080ce0ea..ed91f5fb7a 100644 --- a/website/docs/r/privatelink_endpoint_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_serverless.html.markdown @@ -3,13 +3,13 @@ layout: "mongodbatlas" page_title: "MongoDB Atlas: privatelink_endpoint_serverless" sidebar_current: "docs-mongodbatlas-datasource-privatelink-endpoint-serverless" description: |- -Describes a Serverless PrivateLink endpoint +Describes a Serverless PrivateLink Endpoint --- # Data Source: privatelink_endpoint_serverless -`privatelink_endpoint_serverless` Provides a Serverless PrivateLink endpoint resource. +`privatelink_endpoint_serverless` Provides a Serverless PrivateLink Endpoint resource. -> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. @@ -38,7 +38,7 @@ resource "mongodbatlas_serverless_instance" "test" { ## Argument Reference * `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. -* `instance_name` - (Required) Serverless instance name to attach private +* `instance_name` - (Required) Human-readable label that identifies the serverless instance associated with the tenant endpoint * `provider_name` - (Required) Cloud provider name AWS currently supported ## Attributes Reference diff --git a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown index 373d4d51c8..b052cf5bbe 100644 --- a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown @@ -3,13 +3,13 @@ layout: "mongodbatlas" page_title: "MongoDB Atlas: privatelink_endpoint_service_serverless" sidebar_current: "docs-mongodbatlas-datasource-privatelink-endpoint-service-serverless" description: |- -Describes a Serverless PrivateLink endpoint service +Describes a Serverless PrivateLink Endpoint Service --- # Data Source: privatelink_endpoint_service_serverless -`privatelink_endpoint_service_serverless` Provides a Serverless PrivateLink endpoint service resource. +`privatelink_endpoint_service_serverless` Provides a Serverless PrivateLink Endpoint Service resource. -> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. @@ -52,8 +52,8 @@ resource "mongodbatlas_serverless_instance" "test" { ## Argument Reference * `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. -* `instance_name` - (Required) Serverless instance name to attach private -* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `instance_name` - (Required)Human-readable label that identifies the serverless instance associated with the tenant endpoint +* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint's network interface. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. ## Attributes Reference From cc1e11f02d29252009d2de2a119e04beeb7fe8a1 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Thu, 10 Nov 2022 14:47:29 -0600 Subject: [PATCH 08/16] Add privatelink_endpoints_service_serverless datasource and documentation --- ...telink_endpoint_service_serverless_test.go | 1 - ...rivatelink_endpoints_service_serverless.go | 116 +++++++++++++++ ...elink_endpoints_service_serverless_test.go | 70 +++++++++ mongodbatlas/provider.go | 137 +++++++++--------- ..._endpoint_service_serverless.html.markdown | 6 + ...endpoints_service_serverless.html.markdown | 71 +++++++++ ...vatelink_endpoint_serverless.html.markdown | 2 +- 7 files changed, 333 insertions(+), 70 deletions(-) create mode 100644 mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go create mode 100644 mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless_test.go create mode 100644 website/docs/d/privatelink_endpoints_service_serverless.html.markdown diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless_test.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless_test.go index 41d59a34d8..dc1c64aa06 100644 --- a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless_test.go +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless_test.go @@ -73,7 +73,6 @@ func testAccDSMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(projectID, project_id = "%[1]s" instance_name = "%[2]s" endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id - //cloud_endpoint_id = aws_vpc_endpoint.ptfe_service.id provider_name = "AWS" comment = "%[3]s" } diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go new file mode 100644 index 0000000000..2801c45707 --- /dev/null +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go @@ -0,0 +1,116 @@ +package mongodbatlas + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + matlas "go.mongodb.org/atlas/mongodbatlas" +) + +func dataSourceMongoDBAtlasPrivateLinkEndpointsServiceServerless() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceMongoDBAtlasPrivateLinkEndpointsServiceServerlessRead, + Schema: map[string]*schema.Schema{ + "project_id": { + Type: schema.TypeString, + Required: true, + }, + "instance_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "page_num": { + Type: schema.TypeInt, + Optional: true, + }, + "items_per_page": { + Type: schema.TypeInt, + Optional: true, + }, + "results": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cloud_provider_endpoint_id": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "endpoint_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "endpoint_service_name": { + Type: schema.TypeString, + Computed: true, + }, + "error_message": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func dataSourceMongoDBAtlasPrivateLinkEndpointsServiceServerlessRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // Get client connection. + conn := meta.(*MongoDBClient).Atlas + 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) + if err != nil { + return diag.Errorf("error getting Serverless PrivateLink Endpoints Information: %s", err) + } + + if err := d.Set("results", flattenServerlessPrivateLinkEndpoints(privateLinkEndpoints)); err != nil { + return diag.Errorf("error setting `results`: %s", err) + } + + d.SetId(resource.UniqueId()) + + return nil +} + +func flattenServerlessPrivateLinkEndpoints(privateLinks []matlas.ServerlessPrivateEndpointConnection) []map[string]interface{} { + var results []map[string]interface{} + + if len(privateLinks) == 0 { + return results + } + + results = make([]map[string]interface{}, len(privateLinks)) + + for k, privateLink := range privateLinks { + results[k] = map[string]interface{}{ + "endpoint_id": privateLink.ID, + "endpoint_service_name": privateLink.EndpointServiceName, + "cloud_provider_endpoint_id": privateLink.CloudProviderEndpointID, + "comment": privateLink.Comment, + "error_message": privateLink.ErrorMessage, + "status": privateLink.Status, + } + } + + return results +} diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless_test.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless_test.go new file mode 100644 index 0000000000..efb78f9235 --- /dev/null +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless_test.go @@ -0,0 +1,70 @@ +package mongodbatlas + +import ( + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDataSourceMongoDBAtlasPrivateLinkEndpointsServiceServerless_basic(t *testing.T) { + datasourceName := "data.mongodbatlas_privatelink_endpoints_service_serverless.test" + projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID") + instanceID := "serverless" + comments := "Test Comments" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccMongoDBAtlasPrivateLinkEndpointsServerlessDataSourceConfig(projectID, instanceID, comments), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(datasourceName, "project_id"), + resource.TestCheckResourceAttrSet(datasourceName, "results.#"), + resource.TestCheckResourceAttrSet(datasourceName, "instance_name"), + ), + }, + }, + }) +} + +func testAccMongoDBAtlasPrivateLinkEndpointsServerlessDataSourceConfig(projectID, instanceID, comments string) string { + return fmt.Sprintf(` + data "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "%[1]s" + instance_name = mongodbatlas_serverless_instance.test.name + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + } + + data "mongodbatlas_privatelink_endpoints_service_serverless" "test" { + project_id = "%[1]s" + instance_name = mongodbatlas_serverless_instance.test.name + } + + resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = "%[1]s" + instance_name = mongodbatlas_serverless_instance.test.name + provider_name = "AWS" + } + + + resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "%[1]s" + instance_name = "%[2]s" + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + provider_name = "AWS" + comment = "%[3]s" + } + + resource "mongodbatlas_serverless_instance" "test" { + project_id = "%[1]s" + name = "%[2]s" + provider_settings_backing_provider_name = "AWS" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST_1" + continuous_backup_enabled = true + } + `, projectID, instanceID, comments) +} diff --git a/mongodbatlas/provider.go b/mongodbatlas/provider.go index ba85daa589..2d144e20f7 100644 --- a/mongodbatlas/provider.go +++ b/mongodbatlas/provider.go @@ -78,74 +78,75 @@ func Provider() *schema.Provider { func getDataSourcesMap() map[string]*schema.Resource { dataSourcesMap := map[string]*schema.Resource{ - "mongodbatlas_advanced_cluster": dataSourceMongoDBAtlasAdvancedCluster(), - "mongodbatlas_advanced_clusters": dataSourceMongoDBAtlasAdvancedClusters(), - "mongodbatlas_custom_db_role": dataSourceMongoDBAtlasCustomDBRole(), - "mongodbatlas_custom_db_roles": dataSourceMongoDBAtlasCustomDBRoles(), - "mongodbatlas_database_user": dataSourceMongoDBAtlasDatabaseUser(), - "mongodbatlas_database_users": dataSourceMongoDBAtlasDatabaseUsers(), - "mongodbatlas_project": dataSourceMongoDBAtlasProject(), - "mongodbatlas_projects": dataSourceMongoDBAtlasProjects(), - "mongodbatlas_cluster": dataSourceMongoDBAtlasCluster(), - "mongodbatlas_clusters": dataSourceMongoDBAtlasClusters(), - "mongodbatlas_cloud_provider_snapshot": dataSourceMongoDBAtlasCloudProviderSnapshot(), - "mongodbatlas_cloud_provider_snapshots": dataSourceMongoDBAtlasCloudProviderSnapshots(), - "mongodbatlas_network_container": dataSourceMongoDBAtlasNetworkContainer(), - "mongodbatlas_network_containers": dataSourceMongoDBAtlasNetworkContainers(), - "mongodbatlas_network_peering": dataSourceMongoDBAtlasNetworkPeering(), - "mongodbatlas_network_peerings": dataSourceMongoDBAtlasNetworkPeerings(), - "mongodbatlas_cloud_provider_snapshot_restore_job": dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJob(), - "mongodbatlas_cloud_provider_snapshot_restore_jobs": dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJobs(), - "mongodbatlas_maintenance_window": dataSourceMongoDBAtlasMaintenanceWindow(), - "mongodbatlas_auditing": dataSourceMongoDBAtlasAuditing(), - "mongodbatlas_team": dataSourceMongoDBAtlasTeam(), - "mongodbatlas_teams": dataSourceMongoDBAtlasTeam(), - "mongodbatlas_global_cluster_config": dataSourceMongoDBAtlasGlobalCluster(), - "mongodbatlas_alert_configuration": dataSourceMongoDBAtlasAlertConfiguration(), - "mongodbatlas_x509_authentication_database_user": dataSourceMongoDBAtlasX509AuthDBUser(), - "mongodbatlas_private_endpoint_regional_mode": dataSourceMongoDBAtlasPrivateEndpointRegionalMode(), - "mongodbatlas_privatelink_endpoint": dataSourceMongoDBAtlasPrivateLinkEndpoint(), - "mongodbatlas_privatelink_endpoint_service": dataSourceMongoDBAtlasPrivateEndpointServiceLink(), - "mongodbatlas_privatelink_endpoint_service_serverless": dataSourceMongoDBAtlasPrivateLinkEndpointServerless(), - "mongodbatlas_privatelink_endpoint_service_adl": dataSourceMongoDBAtlasPrivateLinkEndpointServiceADL(), - "mongodbatlas_privatelink_endpoints_service_adl": dataSourceMongoDBAtlasPrivateLinkEndpointsServiceADL(), - "mongodbatlas_cloud_provider_snapshot_backup_policy": dataSourceMongoDBAtlasCloudProviderSnapshotBackupPolicy(), - "mongodbatlas_cloud_backup_schedule": dataSourceMongoDBAtlasCloudBackupSchedule(), - "mongodbatlas_third_party_integrations": dataSourceMongoDBAtlasThirdPartyIntegrations(), - "mongodbatlas_third_party_integration": dataSourceMongoDBAtlasThirdPartyIntegration(), - "mongodbatlas_project_ip_access_list": dataSourceMongoDBAtlasProjectIPAccessList(), - "mongodbatlas_cloud_provider_access": dataSourceMongoDBAtlasCloudProviderAccessList(), - "mongodbatlas_cloud_provider_access_setup": dataSourceMongoDBAtlasCloudProviderAccessSetup(), - "mongodbatlas_custom_dns_configuration_cluster_aws": dataSourceMongoDBAtlasCustomDNSConfigurationAWS(), - "mongodbatlas_online_archive": dataSourceMongoDBAtlasOnlineArchive(), - "mongodbatlas_online_archives": dataSourceMongoDBAtlasOnlineArchives(), - "mongodbatlas_ldap_configuration": dataSourceMongoDBAtlasLDAPConfiguration(), - "mongodbatlas_ldap_verify": dataSourceMongoDBAtlasLDAPVerify(), - "mongodbatlas_search_index": dataSourceMongoDBAtlasSearchIndex(), - "mongodbatlas_search_indexes": dataSourceMongoDBAtlasSearchIndexes(), - "mongodbatlas_data_lake": dataSourceMongoDBAtlasDataLake(), - "mongodbatlas_data_lakes": dataSourceMongoDBAtlasDataLakes(), - "mongodbatlas_event_trigger": dataSourceMongoDBAtlasEventTrigger(), - "mongodbatlas_event_triggers": dataSourceMongoDBAtlasEventTriggers(), - "mongodbatlas_project_invitation": dataSourceMongoDBAtlasProjectInvitation(), - "mongodbatlas_org_invitation": dataSourceMongoDBAtlasOrgInvitation(), - "mongodbatlas_cloud_backup_snapshot": dataSourceMongoDBAtlasCloudBackupSnapshot(), - "mongodbatlas_cloud_backup_snapshots": dataSourceMongoDBAtlasCloudBackupSnapshots(), - "mongodbatlas_cloud_backup_snapshot_restore_job": dataSourceMongoDBAtlasCloudBackupSnapshotRestoreJob(), - "mongodbatlas_cloud_backup_snapshot_restore_jobs": dataSourceMongoDBAtlasCloudBackupSnapshotRestoreJobs(), - "mongodbatlas_cloud_backup_snapshot_export_bucket": datasourceMongoDBAtlasCloudBackupSnapshotExportBucket(), - "mongodbatlas_cloud_backup_snapshot_export_buckets": datasourceMongoDBAtlasCloudBackupSnapshotExportBuckets(), - "mongodbatlas_cloud_backup_snapshot_export_job": datasourceMongoDBAtlasCloudBackupSnapshotExportJob(), - "mongodbatlas_cloud_backup_snapshot_export_jobs": datasourceMongoDBAtlasCloudBackupSnapshotExportJobs(), - "mongodbatlas_federated_settings": dataSourceMongoDBAtlasFederatedSettings(), - "mongodbatlas_federated_settings_identity_provider": dataSourceMongoDBAtlasFederatedSettingsIdentityProvider(), - "mongodbatlas_federated_settings_identity_providers": dataSourceMongoDBAtlasFederatedSettingsIdentityProviders(), - "mongodbatlas_federated_settings_org_config": dataSourceMongoDBAtlasFederatedSettingsOrganizationConfig(), - "mongodbatlas_federated_settings_org_configs": dataSourceMongoDBAtlasFederatedSettingsOrganizationConfigs(), - "mongodbatlas_federated_settings_org_role_mapping": dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMapping(), - "mongodbatlas_federated_settings_org_role_mappings": dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMappings(), - "mongodbatlas_serverless_instance": dataSourceMongoDBAtlasServerlessInstance(), - "mongodbatlas_serverless_instances": dataSourceMongoDBAtlasServerlessInstances(), + "mongodbatlas_advanced_cluster": dataSourceMongoDBAtlasAdvancedCluster(), + "mongodbatlas_advanced_clusters": dataSourceMongoDBAtlasAdvancedClusters(), + "mongodbatlas_custom_db_role": dataSourceMongoDBAtlasCustomDBRole(), + "mongodbatlas_custom_db_roles": dataSourceMongoDBAtlasCustomDBRoles(), + "mongodbatlas_database_user": dataSourceMongoDBAtlasDatabaseUser(), + "mongodbatlas_database_users": dataSourceMongoDBAtlasDatabaseUsers(), + "mongodbatlas_project": dataSourceMongoDBAtlasProject(), + "mongodbatlas_projects": dataSourceMongoDBAtlasProjects(), + "mongodbatlas_cluster": dataSourceMongoDBAtlasCluster(), + "mongodbatlas_clusters": dataSourceMongoDBAtlasClusters(), + "mongodbatlas_cloud_provider_snapshot": dataSourceMongoDBAtlasCloudProviderSnapshot(), + "mongodbatlas_cloud_provider_snapshots": dataSourceMongoDBAtlasCloudProviderSnapshots(), + "mongodbatlas_network_container": dataSourceMongoDBAtlasNetworkContainer(), + "mongodbatlas_network_containers": dataSourceMongoDBAtlasNetworkContainers(), + "mongodbatlas_network_peering": dataSourceMongoDBAtlasNetworkPeering(), + "mongodbatlas_network_peerings": dataSourceMongoDBAtlasNetworkPeerings(), + "mongodbatlas_cloud_provider_snapshot_restore_job": dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJob(), + "mongodbatlas_cloud_provider_snapshot_restore_jobs": dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJobs(), + "mongodbatlas_maintenance_window": dataSourceMongoDBAtlasMaintenanceWindow(), + "mongodbatlas_auditing": dataSourceMongoDBAtlasAuditing(), + "mongodbatlas_team": dataSourceMongoDBAtlasTeam(), + "mongodbatlas_teams": dataSourceMongoDBAtlasTeam(), + "mongodbatlas_global_cluster_config": dataSourceMongoDBAtlasGlobalCluster(), + "mongodbatlas_alert_configuration": dataSourceMongoDBAtlasAlertConfiguration(), + "mongodbatlas_x509_authentication_database_user": dataSourceMongoDBAtlasX509AuthDBUser(), + "mongodbatlas_private_endpoint_regional_mode": dataSourceMongoDBAtlasPrivateEndpointRegionalMode(), + "mongodbatlas_privatelink_endpoint": dataSourceMongoDBAtlasPrivateLinkEndpoint(), + "mongodbatlas_privatelink_endpoint_service": dataSourceMongoDBAtlasPrivateEndpointServiceLink(), + "mongodbatlas_privatelink_endpoint_service_serverless": dataSourceMongoDBAtlasPrivateLinkEndpointServerless(), + "mongodbatlas_privatelink_endpoints_service_serverless": dataSourceMongoDBAtlasPrivateLinkEndpointsServiceServerless(), + "mongodbatlas_privatelink_endpoint_service_adl": dataSourceMongoDBAtlasPrivateLinkEndpointServiceADL(), + "mongodbatlas_privatelink_endpoints_service_adl": dataSourceMongoDBAtlasPrivateLinkEndpointsServiceADL(), + "mongodbatlas_cloud_provider_snapshot_backup_policy": dataSourceMongoDBAtlasCloudProviderSnapshotBackupPolicy(), + "mongodbatlas_cloud_backup_schedule": dataSourceMongoDBAtlasCloudBackupSchedule(), + "mongodbatlas_third_party_integrations": dataSourceMongoDBAtlasThirdPartyIntegrations(), + "mongodbatlas_third_party_integration": dataSourceMongoDBAtlasThirdPartyIntegration(), + "mongodbatlas_project_ip_access_list": dataSourceMongoDBAtlasProjectIPAccessList(), + "mongodbatlas_cloud_provider_access": dataSourceMongoDBAtlasCloudProviderAccessList(), + "mongodbatlas_cloud_provider_access_setup": dataSourceMongoDBAtlasCloudProviderAccessSetup(), + "mongodbatlas_custom_dns_configuration_cluster_aws": dataSourceMongoDBAtlasCustomDNSConfigurationAWS(), + "mongodbatlas_online_archive": dataSourceMongoDBAtlasOnlineArchive(), + "mongodbatlas_online_archives": dataSourceMongoDBAtlasOnlineArchives(), + "mongodbatlas_ldap_configuration": dataSourceMongoDBAtlasLDAPConfiguration(), + "mongodbatlas_ldap_verify": dataSourceMongoDBAtlasLDAPVerify(), + "mongodbatlas_search_index": dataSourceMongoDBAtlasSearchIndex(), + "mongodbatlas_search_indexes": dataSourceMongoDBAtlasSearchIndexes(), + "mongodbatlas_data_lake": dataSourceMongoDBAtlasDataLake(), + "mongodbatlas_data_lakes": dataSourceMongoDBAtlasDataLakes(), + "mongodbatlas_event_trigger": dataSourceMongoDBAtlasEventTrigger(), + "mongodbatlas_event_triggers": dataSourceMongoDBAtlasEventTriggers(), + "mongodbatlas_project_invitation": dataSourceMongoDBAtlasProjectInvitation(), + "mongodbatlas_org_invitation": dataSourceMongoDBAtlasOrgInvitation(), + "mongodbatlas_cloud_backup_snapshot": dataSourceMongoDBAtlasCloudBackupSnapshot(), + "mongodbatlas_cloud_backup_snapshots": dataSourceMongoDBAtlasCloudBackupSnapshots(), + "mongodbatlas_cloud_backup_snapshot_restore_job": dataSourceMongoDBAtlasCloudBackupSnapshotRestoreJob(), + "mongodbatlas_cloud_backup_snapshot_restore_jobs": dataSourceMongoDBAtlasCloudBackupSnapshotRestoreJobs(), + "mongodbatlas_cloud_backup_snapshot_export_bucket": datasourceMongoDBAtlasCloudBackupSnapshotExportBucket(), + "mongodbatlas_cloud_backup_snapshot_export_buckets": datasourceMongoDBAtlasCloudBackupSnapshotExportBuckets(), + "mongodbatlas_cloud_backup_snapshot_export_job": datasourceMongoDBAtlasCloudBackupSnapshotExportJob(), + "mongodbatlas_cloud_backup_snapshot_export_jobs": datasourceMongoDBAtlasCloudBackupSnapshotExportJobs(), + "mongodbatlas_federated_settings": dataSourceMongoDBAtlasFederatedSettings(), + "mongodbatlas_federated_settings_identity_provider": dataSourceMongoDBAtlasFederatedSettingsIdentityProvider(), + "mongodbatlas_federated_settings_identity_providers": dataSourceMongoDBAtlasFederatedSettingsIdentityProviders(), + "mongodbatlas_federated_settings_org_config": dataSourceMongoDBAtlasFederatedSettingsOrganizationConfig(), + "mongodbatlas_federated_settings_org_configs": dataSourceMongoDBAtlasFederatedSettingsOrganizationConfigs(), + "mongodbatlas_federated_settings_org_role_mapping": dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMapping(), + "mongodbatlas_federated_settings_org_role_mappings": dataSourceMongoDBAtlasFederatedSettingsOrganizationRoleMappings(), + "mongodbatlas_serverless_instance": dataSourceMongoDBAtlasServerlessInstance(), + "mongodbatlas_serverless_instances": dataSourceMongoDBAtlasServerlessInstances(), } return dataSourcesMap } diff --git a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown index b44a207f98..7d2d764089 100644 --- a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown @@ -18,6 +18,12 @@ Describes a Serverless PrivateLink Endpoint Service ### Basic ```terraform +data "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id +} + resource "mongodbatlas_privatelink_endpoint_serverless" "test" { project_id = "" instance_name = mongodbatlas_serverless_instance.test.name diff --git a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown new file mode 100644 index 0000000000..abc22e65d3 --- /dev/null +++ b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown @@ -0,0 +1,71 @@ +--- +layout: "mongodbatlas" +page_title: "MongoDB Atlas: privatelink_endpoints_service_serverless" +sidebar_current: "docs-mongodbatlas-datasource-privatelink-endpoints-service-serverless" +description: |- +Describes the list of all Serverless PrivateLink Endpoint Service +--- + + +# Data Source: privatelink_endpoints_service_serverless + +`privatelink_endpoints_service_serverless` Describes the list of all Serverless PrivateLink Endpoint Service resource. + +-> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. + +## Example Usage + +### Basic +```terraform + +data "mongodbatlas_privatelink_endpoints_service_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name +} + +resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name + provider_name = "AWS" +} + +resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "" + instance_name = "test-db" + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + provider_name = "AWS" + comment = "New serverless endpoint" +} + +resource "mongodbatlas_serverless_instance" "test" { + project_id = "" + name = "test-db" + provider_settings_backing_provider_name = "AWS" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST_1" + continuous_backup_enabled = true +} +``` + + +## Argument Reference + +* `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. +* `instance_name` - (Required) Serverless instance name to attach private + + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: +* `results` - Each element in the `result` array is one private serverless endpoint. + +### results + +Each object in the `results` array represents an online archive with the following attributes: +* `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. +* `comment` - Human-readable string to associate with this private endpoint. +* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. +* `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. + +For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Serverless-Private-Endpoints/operation/createOnePrivateEndpointForOneServerlessInstance/) and [MongoDB Atlas API - Online Archive](https://docs.atlas.mongodb.com/reference/api/online-archive/) Documentation. diff --git a/website/docs/r/privatelink_endpoint_serverless.html.markdown b/website/docs/r/privatelink_endpoint_serverless.html.markdown index ed91f5fb7a..92c7f30fd6 100644 --- a/website/docs/r/privatelink_endpoint_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_serverless.html.markdown @@ -39,7 +39,7 @@ resource "mongodbatlas_serverless_instance" "test" { * `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. * `instance_name` - (Required) Human-readable label that identifies the serverless instance associated with the tenant endpoint -* `provider_name` - (Required) Cloud provider name AWS currently supported +* `provider_name` - (Required) Cloud provider name; AWS is currently supported ## Attributes Reference From 887e65f2032dbe049fca9c21af5ab19692d9f8ca Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:42:11 -0600 Subject: [PATCH 09/16] Fix lint error --- ...las_privatelink_endpoints_service_serverless.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go index 2801c45707..c36c2581f7 100644 --- a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go @@ -101,14 +101,14 @@ func flattenServerlessPrivateLinkEndpoints(privateLinks []matlas.ServerlessPriva results = make([]map[string]interface{}, len(privateLinks)) - for k, privateLink := range privateLinks { + for k := range privateLinks { results[k] = map[string]interface{}{ - "endpoint_id": privateLink.ID, - "endpoint_service_name": privateLink.EndpointServiceName, - "cloud_provider_endpoint_id": privateLink.CloudProviderEndpointID, - "comment": privateLink.Comment, - "error_message": privateLink.ErrorMessage, - "status": privateLink.Status, + "endpoint_id": privateLinks[k].ID, + "endpoint_service_name": privateLinks[k].EndpointServiceName, + "cloud_provider_endpoint_id": privateLinks[k].CloudProviderEndpointID, + "comment": privateLinks[k].Comment, + "error_message": privateLinks[k].ErrorMessage, + "status": privateLinks[k].Status, } } From c4f38e8f631b63a69ba17a766d0eeb26cbe0dbd2 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Fri, 11 Nov 2022 19:55:55 -0600 Subject: [PATCH 10/16] Add support for Azure private endpoints --- ...privatelink_endpoint_service_serverless.go | 16 +++++++++ ...rivatelink_endpoints_service_serverless.go | 22 +++++++++---- ...dbatlas_privatelink_endpoint_serverless.go | 16 +++++---- ...privatelink_endpoint_service_serverless.go | 33 +++++++++++++++---- ..._endpoint_service_serverless.html.markdown | 2 ++ ...endpoints_service_serverless.html.markdown | 2 ++ 6 files changed, 71 insertions(+), 20 deletions(-) diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless.go index 50467b7a2f..37357c3091 100644 --- a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless.go +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoint_service_serverless.go @@ -39,6 +39,14 @@ func dataSourceMongoDBAtlasPrivateLinkEndpointServerless() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "private_link_service_resource_id": { + Type: schema.TypeString, + Computed: true, + }, + "private_endpoint_ip_address": { + Type: schema.TypeString, + Computed: true, + }, "error_message": { Type: schema.TypeString, Computed: true, @@ -88,6 +96,14 @@ func dataSourceMongoDBAtlasPrivateEndpointServiceServerlessLinkRead(ctx context. return diag.FromErr(fmt.Errorf(errorEndpointSetting, "cloud_provider_endpoint_id", endpointID, err)) } + if err := d.Set("private_link_service_resource_id", serviceEndpoint.PrivateLinkServiceResourceID); err != nil { + return diag.FromErr(fmt.Errorf(errorEndpointSetting, "private_link_service_resource_id", endpointID, err)) + } + + if err := d.Set("private_endpoint_ip_address", serviceEndpoint.PrivateEndpointIPAddress); err != nil { + return diag.FromErr(fmt.Errorf(errorEndpointSetting, "private_endpoint_ip_address", endpointID, err)) + } + d.SetId(encodeStateID(map[string]string{ "project_id": projectID, "instance_name": instanceName, diff --git a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go index c36c2581f7..6be9673c31 100644 --- a/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go +++ b/mongodbatlas/data_source_mongodbatlas_privatelink_endpoints_service_serverless.go @@ -52,6 +52,14 @@ func dataSourceMongoDBAtlasPrivateLinkEndpointsServiceServerless() *schema.Resou Type: schema.TypeString, Computed: true, }, + "private_link_service_resource_id": { + Type: schema.TypeString, + Computed: true, + }, + "private_endpoint_ip_address": { + Type: schema.TypeString, + Computed: true, + }, "error_message": { Type: schema.TypeString, Computed: true, @@ -103,12 +111,14 @@ func flattenServerlessPrivateLinkEndpoints(privateLinks []matlas.ServerlessPriva for k := range privateLinks { results[k] = map[string]interface{}{ - "endpoint_id": privateLinks[k].ID, - "endpoint_service_name": privateLinks[k].EndpointServiceName, - "cloud_provider_endpoint_id": privateLinks[k].CloudProviderEndpointID, - "comment": privateLinks[k].Comment, - "error_message": privateLinks[k].ErrorMessage, - "status": privateLinks[k].Status, + "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, } } diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go index be9b263ab8..1310e467ce 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_serverless.go @@ -47,12 +47,16 @@ func resourceMongoDBAtlasPrivateLinkEndpointServerless() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{"AWS"}, false), + ValidateFunc: validation.StringInSlice([]string{"AWS", "AZURE"}, false), }, "endpoint_service_name": { Type: schema.TypeString, Computed: true, }, + "private_link_service_resource_id": { + Type: schema.TypeString, + Computed: true, + }, "status": { Type: schema.TypeString, Computed: true, @@ -136,16 +140,14 @@ func resourceMongoDBAtlasPrivateLinkEndpointServerlessRead(ctx context.Context, return diag.Errorf("error setting `endpoint_service_name Name` for endpoint_id (%s): %s", d.Id(), err) } + if err := d.Set("private_link_service_resource_id", privateLinkResponse.PrivateLinkServiceResourceID); err != nil { + return diag.Errorf("error setting `private_link_service_resource_id Name` for endpoint_id (%s): %s", d.Id(), err) + } + if err := d.Set("status", privateLinkResponse.Status); err != nil { return diag.FromErr(fmt.Errorf(errorPrivateLinkEndpointsSetting, "status", d.Id(), err)) } - d.SetId(encodeStateID(map[string]string{ - "project_id": projectID, - "instance_name": instanceName, - "endpoint_id": privateLinkResponse.ID, - })) - return nil } diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go index 0f49517f46..dcff9e6ff3 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go @@ -52,13 +52,24 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerless() *schema.Resource "provider_name": { Type: schema.TypeString, Required: true, - ValidateFunc: validation.StringInSlice([]string{"AWS"}, false), + ValidateFunc: validation.StringInSlice([]string{"AWS", "AZURE"}, false), ForceNew: true, }, "cloud_endpoint_id": { Type: schema.TypeString, Optional: true, ForceNew: true, + Computed: true, + }, + "private_link_service_resource_id": { + Type: schema.TypeString, + Computed: true, + }, + "private_endpoint_ip_address": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, }, "status": { Type: schema.TypeString, @@ -87,13 +98,15 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessCreate(ctx context. privateLink.Comment = d.Get("comment").(string) privateLink.CloudProviderEndpointID = d.Get("cloud_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 = "" endPoint, _, err := conn.ServerlessPrivateEndpoints.Update(ctx, projectID, instanceName, endpointID, privateLink) if err != nil { - return diag.Errorf(errorServerlessServiceEndpointAdd, endPoint.CloudProviderEndpointID, err) + return diag.Errorf(errorServerlessServiceEndpointAdd, endpointID, err) } stateConf := &resource.StateChangeConf{ @@ -161,11 +174,17 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessRead(ctx context.Co return diag.Errorf("error setting `status` for endpoint_id (%s): %s", d.Id(), err) } - d.SetId(encodeStateID(map[string]string{ - "project_id": projectID, - "instance_name": instanceName, - "endpoint_id": privateLinkResponse.ID, - })) + if err := d.Set("cloud_endpoint_id", privateLinkResponse.CloudProviderEndpointID); err != nil { + return diag.Errorf("error setting `cloud_endpoint_id` for endpoint_id (%s): %s", d.Id(), err) + } + + if err := d.Set("private_link_service_resource_id", privateLinkResponse.PrivateLinkServiceResourceID); 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 { + return diag.Errorf("error setting `private_endpoint_ip_address` for endpoint_id (%s): %s", d.Id(), err) + } return nil } diff --git a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown index 7d2d764089..14f33ad60a 100644 --- a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown @@ -63,6 +63,8 @@ resource "mongodbatlas_serverless_instance" "test" { In addition to all arguments above, the following attributes are exported: * `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. +* `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. MongoDB Cloud returns null while it creates the endpoint service. +* `private_endpoint_ip_address` - IPv4 address of the private endpoint in your Azure VNet that someone added to this private endpoint service. * `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Serverless-Private-Endpoints/operation/createOnePrivateEndpointForOneServerlessInstance/) and [MongoDB Atlas API - Online Archive](https://docs.atlas.mongodb.com/reference/api/online-archive/) Documentation. diff --git a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown index abc22e65d3..7c1d6173f1 100644 --- a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown @@ -66,6 +66,8 @@ Each object in the `results` array represents an online archive with the followi * `comment` - Human-readable string to associate with this private endpoint. * `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. * `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. +* `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. MongoDB Cloud returns null while it creates the endpoint service. +* `private_endpoint_ip_address` - IPv4 address of the private endpoint in your Azure VNet that someone added to this private endpoint service. * `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Serverless-Private-Endpoints/operation/createOnePrivateEndpointForOneServerlessInstance/) and [MongoDB Atlas API - Online Archive](https://docs.atlas.mongodb.com/reference/api/online-archive/) Documentation. From 255a79dba6c38a4d5d2b0fd500972b7e4a82cced Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Fri, 11 Nov 2022 20:51:58 -0600 Subject: [PATCH 11/16] Provide additional examples for AWS and AZURE standardize parameter cloud_provider_endpoint_id --- ...privatelink_endpoint_service_serverless.go | 8 +-- ..._endpoint_service_serverless.html.markdown | 6 +-- ...endpoints_service_serverless.html.markdown | 6 +-- ...vatelink_endpoint_serverless.html.markdown | 8 +-- ..._endpoint_service_serverless.html.markdown | 53 +++++++++++++++---- 5 files changed, 58 insertions(+), 23 deletions(-) diff --git a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go index dcff9e6ff3..c38b07970b 100644 --- a/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go +++ b/mongodbatlas/resource_mongodbatlas_privatelink_endpoint_service_serverless.go @@ -55,7 +55,7 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerless() *schema.Resource ValidateFunc: validation.StringInSlice([]string{"AWS", "AZURE"}, false), ForceNew: true, }, - "cloud_endpoint_id": { + "cloud_provider_endpoint_id": { Type: schema.TypeString, Optional: true, ForceNew: true, @@ -96,7 +96,7 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessCreate(ctx context. } privateLink.Comment = d.Get("comment").(string) - privateLink.CloudProviderEndpointID = d.Get("cloud_endpoint_id").(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) @@ -174,8 +174,8 @@ func resourceMongoDBAtlasPrivateLinkEndpointServiceServerlessRead(ctx context.Co return diag.Errorf("error setting `status` for endpoint_id (%s): %s", d.Id(), err) } - if err := d.Set("cloud_endpoint_id", privateLinkResponse.CloudProviderEndpointID); err != nil { - return diag.Errorf("error setting `cloud_endpoint_id` for endpoint_id (%s): %s", d.Id(), err) + if err := d.Set("cloud_provider_endpoint_id", privateLinkResponse.CloudProviderEndpointID); 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 { diff --git a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown index 14f33ad60a..76c3544ff1 100644 --- a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown @@ -53,7 +53,7 @@ resource "mongodbatlas_serverless_instance" "test" { ## Argument Reference * `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. -* `instance_name` - (Required) Serverless instance name to attach private +* `instance_name` - (Required) Human-readable label that identifies the serverless instance * `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. * `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. * `comment` - Human-readable string to associate with this private endpoint. @@ -63,8 +63,8 @@ resource "mongodbatlas_serverless_instance" "test" { In addition to all arguments above, the following attributes are exported: * `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. -* `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. MongoDB Cloud returns null while it creates the endpoint service. +* `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. * `private_endpoint_ip_address` - IPv4 address of the private endpoint in your Azure VNet that someone added to this private endpoint service. * `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. -For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Serverless-Private-Endpoints/operation/createOnePrivateEndpointForOneServerlessInstance/) and [MongoDB Atlas API - Online Archive](https://docs.atlas.mongodb.com/reference/api/online-archive/) Documentation. +For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/). diff --git a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown index 7c1d6173f1..0d3d36d966 100644 --- a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown @@ -51,7 +51,7 @@ resource "mongodbatlas_serverless_instance" "test" { ## Argument Reference * `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. -* `instance_name` - (Required) Serverless instance name to attach private +* `instance_name` - Human-readable label that identifies the serverless instance ## Attributes Reference @@ -66,8 +66,8 @@ Each object in the `results` array represents an online archive with the followi * `comment` - Human-readable string to associate with this private endpoint. * `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. * `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. -* `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. MongoDB Cloud returns null while it creates the endpoint service. +* `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. * `private_endpoint_ip_address` - IPv4 address of the private endpoint in your Azure VNet that someone added to this private endpoint service. * `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. -For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Serverless-Private-Endpoints/operation/createOnePrivateEndpointForOneServerlessInstance/) and [MongoDB Atlas API - Online Archive](https://docs.atlas.mongodb.com/reference/api/online-archive/) Documentation. +For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Serverless-Private-Endpoints/operation/createOnePrivateEndpointForOneServerlessInstance/). diff --git a/website/docs/r/privatelink_endpoint_serverless.html.markdown b/website/docs/r/privatelink_endpoint_serverless.html.markdown index 92c7f30fd6..11aa68dfc6 100644 --- a/website/docs/r/privatelink_endpoint_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_serverless.html.markdown @@ -10,6 +10,7 @@ Describes a Serverless PrivateLink Endpoint # Data Source: privatelink_endpoint_serverless `privatelink_endpoint_serverless` Provides a Serverless PrivateLink Endpoint resource. +This is the first of two resources required to configure PrivateLink for Serverless, the second is [mongodbatlas_privatelink_endpoint_service_serverless](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_service_serverless). -> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. @@ -38,16 +39,17 @@ resource "mongodbatlas_serverless_instance" "test" { ## Argument Reference * `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. -* `instance_name` - (Required) Human-readable label that identifies the serverless instance associated with the tenant endpoint +* `instance_name` - (Required) Human-readable label that identifies the serverless instance. * `provider_name` - (Required) Cloud provider name; AWS is currently supported ## Attributes Reference In addition to all arguments above, the following attributes are exported: * `endpoint_id` - Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. -* `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. +* `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. +* `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. * `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. * `comment` - Human-readable string to associate with this private endpoint. * `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. -For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/) and [MongoDB Atlas API - Online Archive](https://docs.atlas.mongodb.com/reference/api/online-archive/) Documentation. +For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/). diff --git a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown index b052cf5bbe..6da6ec706f 100644 --- a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown @@ -10,18 +10,14 @@ Describes a Serverless PrivateLink Endpoint Service # Data Source: privatelink_endpoint_service_serverless `privatelink_endpoint_service_serverless` Provides a Serverless PrivateLink Endpoint Service resource. +This is the second of two resources required to configure PrivateLink for Serverless, the first is [mongodbatlas_privatelink_endpoint_serverless](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_serverless). -> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. ## Example Usage -### Basic +## Example with AWS ```terraform -data "mongodbatlas_privatelink_endpoint_service_serverless" "test" { - project_id = "" - instance_name = mongodbatlas_serverless_instance.test.name - endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id -} resource "mongodbatlas_privatelink_endpoint_serverless" "test" { project_id = "" @@ -32,7 +28,7 @@ resource "mongodbatlas_privatelink_endpoint_serverless" "test" { resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { project_id = "" - instance_name = "test-db" + instance_name = mongodbatlas_serverless_instance.test.name endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id provider_name = "AWS" comment = "New serverless endpoint" @@ -48,21 +44,58 @@ resource "mongodbatlas_serverless_instance" "test" { } ``` +## Example with AZURE +```terraform +resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = var.project_id + provider_name = "AZURE" +} + +resource "azurerm_private_endpoint" "test" { + name = "endpoint-test" + location = data.azurerm_resource_group.test.location + resource_group_name = var.resource_group_name + subnet_id = azurerm_subnet.test.id + private_service_connection { + name = mongodbatlas_privatelink_endpoint_serverless.test.private_link_service_name + private_connection_resource_id = mongodbatlas_privatelink_endpoint_serverless.test.private_link_service_resource_id + is_manual_connection = true + request_message = "Azure Private Link test" + } + +} + +resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = mongodbatlas_privatelink_endpoint_serverless.test.project_id + instance_name = mongodbatlas_serverless_instance.test.name + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + cloud_endpoint_id = azurerm_private_endpoint.test.id + private_endpoint_ip_address = azurerm_private_endpoint.test.private_service_connection.0.private_ip_address + provider_name = "AZURE" + comment = "test" +} +``` ## Argument Reference * `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. -* `instance_name` - (Required)Human-readable label that identifies the serverless instance associated with the tenant endpoint +* `instance_name` - (Required)Human-readable label that identifies the serverless instance. * `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint's network interface. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `cloud_provider_endpoint_id` - (Optional) Unique string that identifies the private endpoint's network interface. +* `private_endpoint_ip_address` - (Optional) IPv4 address of the private endpoint in your Azure VNet that someone added to this private endpoint service. +* `provider_name` - (Required) Cloud provider for which you want to create a private endpoint. Atlas accepts `AWS`, `AZURE`. +* `comment` - (Optional) Human-readable string to associate with this private endpoint. ## Attributes Reference In addition to all arguments above, the following attributes are exported: -* `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. +* `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. +* `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. +* `private_endpoint_ip_address` - IPv4 address of the private endpoint in your Azure VNet that someone added to this private endpoint service. * `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. * `comment` - Human-readable string to associate with this private endpoint. * `error_message` - Human-readable error message that indicates the error condition associated with establishing the private endpoint connection. * `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. -For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/) and [MongoDB Atlas API - Online Archive](https://docs.atlas.mongodb.com/reference/api/online-archive/) Documentation. +For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/). From 56f754113807e508d99c730d15b10be1f4515f9d Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Sun, 13 Nov 2022 18:42:20 -0600 Subject: [PATCH 12/16] Additional examples --- ..._endpoint_service_serverless.html.markdown | 35 ++++++++++++++++++- ...endpoints_service_serverless.html.markdown | 33 ++++++++++++++++- ...vatelink_endpoint_serverless.html.markdown | 15 ++++++-- ..._endpoint_service_serverless.html.markdown | 17 ++++++--- 4 files changed, 91 insertions(+), 9 deletions(-) diff --git a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown index 76c3544ff1..1c2dcb5db2 100644 --- a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown @@ -15,7 +15,7 @@ Describes a Serverless PrivateLink Endpoint Service ## Example Usage -### Basic +## Example with AWS ```terraform data "mongodbatlas_privatelink_endpoint_service_serverless" "test" { @@ -49,6 +49,39 @@ resource "mongodbatlas_serverless_instance" "test" { } ``` +## Example with AZURE +```terraform + +data "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id +} + +resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name + provider_name = "AZURE" +} + + +resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "" + instance_name = "test-db" + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + provider_name = "AZURE" + comment = "New serverless endpoint" +} + +resource "mongodbatlas_serverless_instance" "test" { + project_id = "" + name = "test-db" + provider_settings_backing_provider_name = "AZURE" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST_1" + continuous_backup_enabled = true +} +``` ## Argument Reference diff --git a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown index 0d3d36d966..fbe19b4fc5 100644 --- a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown @@ -15,7 +15,7 @@ Describes the list of all Serverless PrivateLink Endpoint Service ## Example Usage -### Basic +## Example with AWS ```terraform data "mongodbatlas_privatelink_endpoints_service_serverless" "test" { @@ -47,6 +47,37 @@ resource "mongodbatlas_serverless_instance" "test" { } ``` +## Example with AZURE +```terraform + +data "mongodbatlas_privatelink_endpoints_service_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name +} + +resource "mongodbatlas_privatelink_endpoint_serverless" "test" { + project_id = "" + instance_name = mongodbatlas_serverless_instance.test.name + provider_name = "AZURE" +} + +resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { + project_id = "" + instance_name = "test-db" + endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + provider_name = "AZURE" + comment = "New serverless endpoint" +} + +resource "mongodbatlas_serverless_instance" "test" { + project_id = "" + name = "test-db" + provider_settings_backing_provider_name = "AZURE" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST_1" + continuous_backup_enabled = true +} +``` ## Argument Reference diff --git a/website/docs/r/privatelink_endpoint_serverless.html.markdown b/website/docs/r/privatelink_endpoint_serverless.html.markdown index 11aa68dfc6..48b6b6bd97 100644 --- a/website/docs/r/privatelink_endpoint_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_serverless.html.markdown @@ -7,13 +7,14 @@ Describes a Serverless PrivateLink Endpoint --- -# Data Source: privatelink_endpoint_serverless +# Resource: privatelink_endpoint_serverless `privatelink_endpoint_serverless` Provides a Serverless PrivateLink Endpoint resource. This is the first of two resources required to configure PrivateLink for Serverless, the second is [mongodbatlas_privatelink_endpoint_service_serverless](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_service_serverless). -> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. - +-> **NOTE:** Feature unavailable in Free and Shared-Tier Clusters +This feature is not available for M0 free clusters, M2, and M5 clusters. To learn more about which features are unavailable, see [Atlas M0 (Free Cluster), M2, and M5 Limitations.](https://www.mongodb.com/docs/atlas/reference/free-shared-limitations/#std-label-atlas-free-tier) ## Example Usage ### Basic @@ -45,11 +46,19 @@ resource "mongodbatlas_serverless_instance" "test" { ## Attributes Reference In addition to all arguments above, the following attributes are exported: -* `endpoint_id` - Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `endpoint_id` - Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [AWS PrivateLink](https://aws.amazon.com/privatelink/) feature. * `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. * `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. * `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. * `comment` - Human-readable string to associate with this private endpoint. * `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. +## Import + +Serverless privatelink endpoint can be imported using project ID and endpoint ID, in the format `project_id`--`endpoint_id`, e.g. + +``` +$ terraform import mongodbatlas_privatelink_endpoint_serverless.test 1112222b3bf99403840e8934--serverless_name--vpce-jjg5e24qp93513h03 +``` + For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/). diff --git a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown index 6da6ec706f..f24f476f76 100644 --- a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown @@ -7,13 +7,14 @@ Describes a Serverless PrivateLink Endpoint Service --- -# Data Source: privatelink_endpoint_service_serverless +# Resource: privatelink_endpoint_service_serverless `privatelink_endpoint_service_serverless` Provides a Serverless PrivateLink Endpoint Service resource. This is the second of two resources required to configure PrivateLink for Serverless, the first is [mongodbatlas_privatelink_endpoint_serverless](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_serverless). -> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. - +-> **NOTE:** Feature unavailable in Free and Shared-Tier Clusters +This feature is not available for M0 free clusters, M2, and M5 clusters. To learn more about which features are unavailable, see [Atlas M0 (Free Cluster), M2, and M5 Limitations.](https://www.mongodb.com/docs/atlas/reference/free-shared-limitations/#std-label-atlas-free-tier) ## Example Usage ## Example with AWS @@ -79,8 +80,8 @@ resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { ## Argument Reference * `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. -* `instance_name` - (Required)Human-readable label that identifies the serverless instance. -* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint's network interface. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `instance_name` - (Required) Human-readable label that identifies the serverless instance. +* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint's network interface. Atlas supports AWS private endpoints using the [AWS PrivateLink](https://aws.amazon.com/privatelink/) feature. * `cloud_provider_endpoint_id` - (Optional) Unique string that identifies the private endpoint's network interface. * `private_endpoint_ip_address` - (Optional) IPv4 address of the private endpoint in your Azure VNet that someone added to this private endpoint service. * `provider_name` - (Required) Cloud provider for which you want to create a private endpoint. Atlas accepts `AWS`, `AZURE`. @@ -98,4 +99,12 @@ In addition to all arguments above, the following attributes are exported: * `error_message` - Human-readable error message that indicates the error condition associated with establishing the private endpoint connection. * `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. +## Import + +Serverless privatelink endpoint can be imported using project ID and endpoint ID, in the format `project_id`--`endpoint_id`, e.g. + +``` +$ terraform import mongodbatlas_privatelink_endpoint_service_serverless.test 1112222b3bf99403840e8934--serverless_name--vpce-jjg5e24qp93513h03 +``` + For more information see: [MongoDB Atlas API - Serverless Private Endpoints](https://www.mongodb.com/docs/atlas/reference/api/serverless-private-endpoints-get-one/). From 98bb5212644a683da1e7eda262568a545bc6f921 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Sun, 13 Nov 2022 19:47:54 -0600 Subject: [PATCH 13/16] Tidy up docs --- .../d/privatelink_endpoint_service_serverless.html.markdown | 2 +- .../d/privatelink_endpoints_service_serverless.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown index 1c2dcb5db2..3093b316a1 100644 --- a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown @@ -87,7 +87,7 @@ resource "mongodbatlas_serverless_instance" "test" { * `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. * `instance_name` - (Required) Human-readable label that identifies the serverless instance -* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [AWS PrivateLink](https://aws.amazon.com/privatelink/) feature. * `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. * `comment` - Human-readable string to associate with this private endpoint. diff --git a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown index fbe19b4fc5..a30850063d 100644 --- a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown @@ -95,7 +95,7 @@ In addition to all arguments above, the following attributes are exported: Each object in the `results` array represents an online archive with the following attributes: * `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. * `comment` - Human-readable string to associate with this private endpoint. -* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [|aws| PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [AWS PrivateLink](https://aws.amazon.com/privatelink/) feature. * `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. MongoDB Cloud returns null while it creates the endpoint service. * `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. * `private_endpoint_ip_address` - IPv4 address of the private endpoint in your Azure VNet that someone added to this private endpoint service. From f99b8885f4d6954bedc3e2cfb8414f07d19a3371 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Mon, 14 Nov 2022 18:51:58 -0600 Subject: [PATCH 14/16] Update Doc region for Azure --- ...atelink_endpoint_service_serverless.html.markdown | 2 +- ...telink_endpoints_service_serverless.html.markdown | 2 +- .../r/privatelink_endpoint_serverless.html.markdown | 5 +++-- ...atelink_endpoint_service_serverless.html.markdown | 12 +++++++++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown index 3093b316a1..c807e9b30f 100644 --- a/website/docs/d/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoint_service_serverless.html.markdown @@ -78,7 +78,7 @@ resource "mongodbatlas_serverless_instance" "test" { name = "test-db" provider_settings_backing_provider_name = "AZURE" provider_settings_provider_name = "SERVERLESS" - provider_settings_region_name = "US_EAST_1" + provider_settings_region_name = "US_EAST" continuous_backup_enabled = true } ``` diff --git a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown index a30850063d..125df35297 100644 --- a/website/docs/d/privatelink_endpoints_service_serverless.html.markdown +++ b/website/docs/d/privatelink_endpoints_service_serverless.html.markdown @@ -74,7 +74,7 @@ resource "mongodbatlas_serverless_instance" "test" { name = "test-db" provider_settings_backing_provider_name = "AZURE" provider_settings_provider_name = "SERVERLESS" - provider_settings_region_name = "US_EAST_1" + provider_settings_region_name = "US_EAST" continuous_backup_enabled = true } ``` diff --git a/website/docs/r/privatelink_endpoint_serverless.html.markdown b/website/docs/r/privatelink_endpoint_serverless.html.markdown index 48b6b6bd97..c55dcb02c0 100644 --- a/website/docs/r/privatelink_endpoint_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_serverless.html.markdown @@ -17,7 +17,7 @@ This is the first of two resources required to configure PrivateLink for Serverl This feature is not available for M0 free clusters, M2, and M5 clusters. To learn more about which features are unavailable, see [Atlas M0 (Free Cluster), M2, and M5 Limitations.](https://www.mongodb.com/docs/atlas/reference/free-shared-limitations/#std-label-atlas-free-tier) ## Example Usage -### Basic +### AWS Example ```terraform resource "mongodbatlas_privatelink_endpoint_serverless" "test" { @@ -46,12 +46,13 @@ resource "mongodbatlas_serverless_instance" "test" { ## Attributes Reference In addition to all arguments above, the following attributes are exported: -* `endpoint_id` - Unique 22-character alphanumeric string that identifies the private endpoint. Atlas supports AWS private endpoints using the [AWS PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `endpoint_id` - Unique 24-hexadecimal digit string that identifies the private endpoint. * `endpoint_service_name` - Unique string that identifies the PrivateLink endpoint service. * `private_link_service_resource_id` - Root-relative path that identifies the Azure Private Link Service that MongoDB Cloud manages. * `cloud_provider_endpoint_id` - Unique string that identifies the private endpoint's network interface. * `comment` - Human-readable string to associate with this private endpoint. * `status` - Human-readable label that indicates the current operating status of the private endpoint. Values include: RESERVATION_REQUESTED, RESERVED, INITIATING, AVAILABLE, FAILED, DELETING. +* `timeouts`- (Optional) The duration of time to wait for Private Endpoint Service to be created or deleted. The timeout value is definded by a signed sequence of decimal numbers with an time unit suffix such as: `1h45m`, `300s`, `10m`, .... The valid time units are: `ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`. The default timeout for Private Endpoint create & delete is `2h`. Learn more about timeouts [here](https://www.terraform.io/plugin/sdkv2/resources/retries-and-customizable-timeouts). ## Import diff --git a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown index f24f476f76..19cceb0981 100644 --- a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown @@ -75,17 +75,27 @@ resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { provider_name = "AZURE" comment = "test" } + +resource "mongodbatlas_serverless_instance" "test" { + project_id = "" + name = "test-db" + provider_settings_backing_provider_name = "AZURE" + provider_settings_provider_name = "SERVERLESS" + provider_settings_region_name = "US_EAST" + continuous_backup_enabled = true +} ``` ## Argument Reference * `project_id` - (Required) Unique 24-digit hexadecimal string that identifies the project. * `instance_name` - (Required) Human-readable label that identifies the serverless instance. -* `endpoint_id` - (Required) Unique 22-character alphanumeric string that identifies the private endpoint's network interface. Atlas supports AWS private endpoints using the [AWS PrivateLink](https://aws.amazon.com/privatelink/) feature. +* `endpoint_id` - (Required) Unique 24-hexadecimal digit string that identifies the private endpoint. * `cloud_provider_endpoint_id` - (Optional) Unique string that identifies the private endpoint's network interface. * `private_endpoint_ip_address` - (Optional) IPv4 address of the private endpoint in your Azure VNet that someone added to this private endpoint service. * `provider_name` - (Required) Cloud provider for which you want to create a private endpoint. Atlas accepts `AWS`, `AZURE`. * `comment` - (Optional) Human-readable string to associate with this private endpoint. +* `timeouts`- (Optional) The duration of time to wait for Private Endpoint Service to be created or deleted. The timeout value is definded by a signed sequence of decimal numbers with an time unit suffix such as: `1h45m`, `300s`, `10m`, .... The valid time units are: `ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`. The default timeout for Private Endpoint create & delete is `2h`. Learn more about timeouts [here](https://www.terraform.io/plugin/sdkv2/resources/retries-and-customizable-timeouts). ## Attributes Reference From d6ae4756486639b617acef35a259b69829fe4566 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Mon, 14 Nov 2022 19:06:04 -0600 Subject: [PATCH 15/16] Add AWS aws_vpc_endpoint to link to mongodbatlas_privatelink_endpoint_service_serverless --- ...vatelink_endpoint_service_serverless.html.markdown | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown index 19cceb0981..b7cf365134 100644 --- a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown @@ -26,11 +26,20 @@ resource "mongodbatlas_privatelink_endpoint_serverless" "test" { provider_name = "AWS" } - + +resource "aws_vpc_endpoint" "ptfe_service" { + vpc_id = "vpc-7fc0a543" + service_name = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_service_name + vpc_endpoint_type = "Interface" + subnet_ids = ["subnet-de0406d2"] + security_group_ids = ["sg-3f238186"] +} + resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" { project_id = "" instance_name = mongodbatlas_serverless_instance.test.name endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id + cloud_endpoint_id = aws_vpc_endpoint.ptfe_service.id provider_name = "AWS" comment = "New serverless endpoint" } From 16d1a663675e58f98de6b545098bdce2a8a0c740 Mon Sep 17 00:00:00 2001 From: admin <33664051+martinstibbe@users.noreply.github.com> Date: Mon, 14 Nov 2022 19:20:23 -0600 Subject: [PATCH 16/16] Remove Extra note --- website/docs/r/privatelink_endpoint_serverless.html.markdown | 3 +-- .../r/privatelink_endpoint_service_serverless.html.markdown | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/website/docs/r/privatelink_endpoint_serverless.html.markdown b/website/docs/r/privatelink_endpoint_serverless.html.markdown index c55dcb02c0..90313d792a 100644 --- a/website/docs/r/privatelink_endpoint_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_serverless.html.markdown @@ -13,8 +13,7 @@ Describes a Serverless PrivateLink Endpoint This is the first of two resources required to configure PrivateLink for Serverless, the second is [mongodbatlas_privatelink_endpoint_service_serverless](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_service_serverless). -> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. --> **NOTE:** Feature unavailable in Free and Shared-Tier Clusters -This feature is not available for M0 free clusters, M2, and M5 clusters. To learn more about which features are unavailable, see [Atlas M0 (Free Cluster), M2, and M5 Limitations.](https://www.mongodb.com/docs/atlas/reference/free-shared-limitations/#std-label-atlas-free-tier) + ## Example Usage ### AWS Example diff --git a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown index b7cf365134..4beeea0991 100644 --- a/website/docs/r/privatelink_endpoint_service_serverless.html.markdown +++ b/website/docs/r/privatelink_endpoint_service_serverless.html.markdown @@ -13,8 +13,7 @@ Describes a Serverless PrivateLink Endpoint Service This is the second of two resources required to configure PrivateLink for Serverless, the first is [mongodbatlas_privatelink_endpoint_serverless](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/privatelink_endpoint_serverless). -> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation. --> **NOTE:** Feature unavailable in Free and Shared-Tier Clusters -This feature is not available for M0 free clusters, M2, and M5 clusters. To learn more about which features are unavailable, see [Atlas M0 (Free Cluster), M2, and M5 Limitations.](https://www.mongodb.com/docs/atlas/reference/free-shared-limitations/#std-label-atlas-free-tier) + ## Example Usage ## Example with AWS