Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion acceptance_tests/private_endpoint_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package acceptance_tests

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -11,7 +12,7 @@ import (
func TestAccPrivateEndpointServiceEnableDisable(t *testing.T) {
resourceName := "disable_private_endpoint_service"
resourceReference := "couchbase-capella_private_endpoint_service." + resourceName
resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: globalProtoV6ProviderFactory,
Steps: []resource.TestStep{
// First enable the service
Expand All @@ -38,6 +39,33 @@ func TestAccPrivateEndpointServiceEnableDisable(t *testing.T) {
})
}

func TestAccDatasourcePrivateEndpointsServiceEnabledNoEndpointAdded(t *testing.T) {
serviceResourceName := randomStringWithPrefix("tf_acc_private_endpoint_service_")
dataSourceName := randomStringWithPrefix("tf_acc_private_endpoints_ds_")
serviceResourceReference := "couchbase-capella_private_endpoint_service." + serviceResourceName
dataSourceReference := "data.couchbase-capella_private_endpoints." + dataSourceName

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: globalProtoV6ProviderFactory,
Steps: []resource.TestStep{
{
Config: testAccPrivateEndpointsDataSourceNoEndpointConfig(serviceResourceName, dataSourceName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(serviceResourceReference, "organization_id", globalOrgId),
resource.TestCheckResourceAttr(serviceResourceReference, "project_id", globalProjectId),
resource.TestCheckResourceAttr(serviceResourceReference, "cluster_id", globalClusterId),
resource.TestCheckResourceAttr(serviceResourceReference, "enabled", "true"),
resource.TestCheckResourceAttr(dataSourceReference, "organization_id", globalOrgId),
resource.TestCheckResourceAttr(dataSourceReference, "project_id", globalProjectId),
resource.TestCheckResourceAttr(dataSourceReference, "cluster_id", globalClusterId),
resource.TestMatchResourceAttr(dataSourceReference, "private_endpoint_dns", regexp.MustCompile(`^private-endpoint\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$`)),
Comment thread
nimiyajoseph marked this conversation as resolved.
Outdated
resource.TestCheckResourceAttr(dataSourceReference, "data.#", "0"),
Comment thread
nimiyajoseph marked this conversation as resolved.
Outdated
),
},
},
})
}

// testAccPrivateEndpointServiceEnableConfig returns terraform config for enabling/disabling private endpoint service
func testAccPrivateEndpointServiceEnableConfig(resourceName string, enabled bool) string {
return fmt.Sprintf(
Expand All @@ -52,3 +80,24 @@ func testAccPrivateEndpointServiceEnableConfig(resourceName string, enabled bool
}
`, globalProviderBlock, resourceName, globalOrgId, globalProjectId, globalClusterId, enabled)
}

func testAccPrivateEndpointsDataSourceNoEndpointConfig(serviceResourceName, dataSourceName string) string {
return fmt.Sprintf(`
%[1]s

resource "couchbase-capella_private_endpoint_service" "%[2]s" {
organization_id = "%[4]s"
project_id = "%[5]s"
cluster_id = "%[6]s"
enabled = true
}

data "couchbase-capella_private_endpoints" "%[3]s" {
organization_id = "%[4]s"
project_id = "%[5]s"
cluster_id = "%[6]s"

depends_on = [couchbase-capella_private_endpoint_service.%[2]s]
}
`, globalProviderBlock, serviceResourceName, dataSourceName, globalOrgId, globalProjectId, globalClusterId)
}
2 changes: 2 additions & 0 deletions docs/data-sources/private_endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ data "couchbase-capella_private_endpoints" "list_endpoints" {
### Read-Only

- `data` (Attributes List) (see [below for nested schema](#nestedatt--data))
- `private_endpoint_dns` (String)

<a id="nestedatt--data"></a>
### Nested Schema for `data`
Expand All @@ -43,4 +44,5 @@ Read-Only:
- `id` (String)
- `organization_id` (String) The GUID4 ID of the organization.
- `project_id` (String) The GUID4 ID of the project.
- `service_name` (String)
- `status` (String)
1 change: 1 addition & 0 deletions docs/resources/private_endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ resource "couchbase-capella_private_endpoints" "accept_endpoint" {

### Read-Only

- `private_endpoint_dns` (String)
- `service_name` (String)
- `status` (String)

Expand Down
Loading