Skip to content

Commit

Permalink
feat(VPCEP): add a new data source to query VPC endpoint list (#4025)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangting951007 authored Jan 17, 2024
1 parent b4e585b commit ad0f8a6
Show file tree
Hide file tree
Showing 4 changed files with 412 additions and 0 deletions.
90 changes: 90 additions & 0 deletions docs/data-sources/vpcep_endpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
subcategory: "VPC Endpoint (VPCEP)"
---

# huaweicloud_vpcep_endpoints

Use this data source to get a list of VPC endpoints.

## Example Usage

```hcl
variable "service_name" {}
variable "endpoint_id" {}
data "huaweicloud_vpcep_endpoints" "endpoints" {
service_name = var.service_name
endpoint_id = var.endpoint_id
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) The region in which to query the VPC endpoints.
If omitted, the provider-level region will be used.

* `service_name` - (Optional, String) The name of the VPC endpoint service.

* `vpc_id` - (Optional, String) The ID of the VPC where the endpoint is created.

* `endpoint_id` - (Optional, String) The ID of the VPC endpoint.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The data source ID.

* `endpoints` - A list of VPC endpoints.

The `endpoints` block supports:

* `id` - The ID of the VPC endpoint.

* `service_type` - The type of the VPC endpoint service. The valid value can be:
+ **gateway**: Configured by operation and maintenance personnel.
Users do not need to create it and can use it directly.
+ **interface**: Including cloud services configured by operation and maintenance personnel
and private services created by users themselves. Among them, the cloud services configured
by operation and maintenance personnel do not need to be created, and users can use them directly.
You can query the public endpoint service list to view all user-visible and connectable
endpoint services configured by operation and maintenance personnel, and create an **interface**
type endpoint service by creating an endpoint service.

* `status` - The status of the VPC endpoint. The value can be **accepted**, **pendingAcceptance**, **creating**,
**failed**, **deleting**, or **rejected**.

* `service_name` - The name of the VPC endpoint service.

* `service_id` - The ID of the VPC endpoint service.

* `packet_id` - The packet ID of the VPC endpoint.
OBS uses this field to implement double-ended fixed features, and distinguish what endpoint instance it is.

* `enable_dns` - Whether to create a private domain name. The value can be **true** or **false**.
When the type of endpoint service is **gateway**, the field is not valid.

* `ip_address` - The IP address for accessing the associated VPC endpoint service.

* `description` - The description of VPC endpoint.

* `vpc_id` - The ID of the VPC where the endpoint is created.

* `subnet_id` - The network ID of the subnet in the VPC specified by `vpc_id`, in UUID format.

* `created_at` - The creation time of the VPC endpoint. Use UTC time format, the format is: YYYY-MM-DDTHH:MM:SSZ.

* `updated_at` - The update time of the VPC endpoint. Use UTC time format, the format is: YYYY-MM-DDTHH:MM:SSZ.

* `tags` - The key/value pairs associating with the VPC endpoint.

* `whitelist` - The list of IP address or CIDR block which can be accessed to the
VPC endpoint.
If not created, an empty list is returned.
This field is displayed when creating an endpoint connected to an **interface** type endpoint service.
Array length: **1** - **1000**.

* `enable_whitelist` - Whether to enable access control.
This field is displayed when creating an endpoint connected to an **interface** type endpoint service.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ func Provider() *schema.Provider {
"huaweicloud_vpc_subnets": vpc.DataSourceVpcSubnets(),
"huaweicloud_vpc_subnet_ids": vpc.DataSourceVpcSubnetIdsV1(),

"huaweicloud_vpcep_endpoints": vpcep.DataSourceVPCEPEndpoints(),
"huaweicloud_vpcep_public_services": vpcep.DataSourceVPCEPPublicServices(),
"huaweicloud_vpcep_services": vpcep.DataSourceVPCEPServices(),
"huaweicloud_vpcep_service_connections": vpcep.DataSourceVPCEPServiceConnections(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package vpcep

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func TestAccDatasourceVPCEPEndpoints_basic(t *testing.T) {
name := acceptance.RandomAccResourceName()
rName := "data.huaweicloud_vpcep_endpoints.test"
dc := acceptance.InitDataSourceCheck(rName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDatasourceVpcepEndpoints_basic(name),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(rName, "endpoints.0.service_id"),
resource.TestCheckResourceAttrSet(rName, "endpoints.0.vpc_id"),
resource.TestCheckResourceAttrSet(rName, "endpoints.0.subnet_id"),
resource.TestCheckResourceAttrSet(rName, "endpoints.0.enable_dns"),
resource.TestCheckResourceAttrSet(rName, "endpoints.0.description"),
resource.TestCheckResourceAttrSet(rName, "endpoints.0.enable_whitelist"),
resource.TestCheckResourceAttr(rName, "endpoints.0.tags.owner", "tf-acc"),
resource.TestCheckResourceAttr(rName, "endpoints.0.whitelist.0", "192.168.0.0/24"),

resource.TestCheckOutput("service_name_filter_is_useful", "true"),

resource.TestCheckOutput("vpc_id_filter_is_useful", "true"),

resource.TestCheckOutput("endpoint_id_filter_is_useful", "true"),
),
},
},
})
}

func testAccDatasourceVpcepEndpoints_basic(name string) string {
return fmt.Sprintf(`
%s
data "huaweicloud_vpcep_endpoints" "test" {
depends_on = [huaweicloud_vpcep_endpoint.test]
}
data "huaweicloud_vpcep_endpoints" "service_name_filter" {
service_name = data.huaweicloud_vpcep_endpoints.test.endpoints.0.service_name
}
locals {
service_name = data.huaweicloud_vpcep_endpoints.test.endpoints.0.service_name
}
output "service_name_filter_is_useful" {
value = length(data.huaweicloud_vpcep_endpoints.service_name_filter.endpoints) > 0 && alltrue(
[for v in data.huaweicloud_vpcep_endpoints.service_name_filter.endpoints[*].service_name : v == local.service_name]
)
}
data "huaweicloud_vpcep_endpoints" "vpc_id_filter" {
vpc_id = data.huaweicloud_vpcep_endpoints.test.endpoints.0.vpc_id
}
locals {
vpc_id = data.huaweicloud_vpc.myvpc.id
}
output "vpc_id_filter_is_useful" {
value = length(data.huaweicloud_vpcep_endpoints.vpc_id_filter.endpoints) > 0 && alltrue(
[for v in data.huaweicloud_vpcep_endpoints.vpc_id_filter.endpoints[*].vpc_id : v == local.vpc_id]
)
}
data "huaweicloud_vpcep_endpoints" "endpoint_id_filter" {
endpoint_id = data.huaweicloud_vpcep_endpoints.test.endpoints.0.id
}
locals {
endpoint_id = huaweicloud_vpcep_endpoint.test.id
}
output "endpoint_id_filter_is_useful" {
value = length(data.huaweicloud_vpcep_endpoints.endpoint_id_filter.endpoints) > 0 && alltrue(
[for v in data.huaweicloud_vpcep_endpoints.endpoint_id_filter.endpoints[*].id : v == local.endpoint_id]
)
}
`, testAccVPCEndpoint_Basic(name))
}
Loading

0 comments on commit ad0f8a6

Please sign in to comment.