From ce8986ef7a8ebe954c21bed6a2c4fd63fab5c762 Mon Sep 17 00:00:00 2001 From: dengyali0125 Date: Mon, 15 Jan 2024 16:37:07 +0800 Subject: [PATCH] feat(EIP): Synchronized EIP dataSources, unit test and document. --- docs/data-sources/vpc_eip.md | 12 +++-- ...data_source_flexibleengine_vpc_eip_test.go | 54 +++++++++++++++++++ flexibleengine/provider.go | 3 +- 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 flexibleengine/acceptance/data_source_flexibleengine_vpc_eip_test.go diff --git a/docs/data-sources/vpc_eip.md b/docs/data-sources/vpc_eip.md index 7573be183..66ae238da 100644 --- a/docs/data-sources/vpc_eip.md +++ b/docs/data-sources/vpc_eip.md @@ -19,22 +19,26 @@ data "flexibleengine_vpc_eip" "by_address" { * `region` - (Optional, String) Specifies the region in which to obtain the EIP. If omitted, the provider-level region will be used. -* `public_ip` - (Optional, String) The public ip address of the EIP. +* `public_ip` - (Optional, String) Specifies the public **IPv4** address of the EIP. -* `port_id` - (Optional, String) The port id of the EIP. +* `port_id` - (Optional, String) Specifies the port id of the EIP. + +* `enterprise_project_id` - (Optional, String) Specifies the enterprise project id of the EIP. ## Attribute Reference In addition to all arguments above, the following attributes are exported: -* `id` - The data source ID in UUID format. - * `status` - The status of the EIP. * `type` - The type of the EIP. * `private_ip` - The private ip of the EIP. +* `ip_version` - The IP version, either 4 or 6. + +* `ipv6_address` - The IPv6 address of the EIP. + * `bandwidth_id` - The bandwidth id of the EIP. * `bandwidth_size` - The bandwidth size of the EIP. diff --git a/flexibleengine/acceptance/data_source_flexibleengine_vpc_eip_test.go b/flexibleengine/acceptance/data_source_flexibleengine_vpc_eip_test.go new file mode 100644 index 000000000..dd9e3077e --- /dev/null +++ b/flexibleengine/acceptance/data_source_flexibleengine_vpc_eip_test.go @@ -0,0 +1,54 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func TestAccVpcEipDataSource_basic(t *testing.T) { + randName := acceptance.RandomAccResourceName() + dataSourceName := "data.flexibleengine_vpc_eip.test" + + dc := acceptance.InitDataSourceCheck(dataSourceName) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceVpcEipConfig_basic(randName), + Check: resource.ComposeTestCheckFunc( + dc.CheckResourceExists(), + resource.TestCheckResourceAttr(dataSourceName, "status", "UNBOUND"), + resource.TestCheckResourceAttr(dataSourceName, "type", "5_bgp"), + resource.TestCheckResourceAttr(dataSourceName, "ip_version", "4"), + resource.TestCheckResourceAttr(dataSourceName, "bandwidth_size", "5"), + resource.TestCheckResourceAttr(dataSourceName, "bandwidth_share_type", "PER"), + ), + }, + }, + }) +} + +func testAccDataSourceVpcEipConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "flexibleengine_vpc_eip" "test" { + publicip { + type = "5_bgp" + } + bandwidth { + name = "%s" + size = 5 + share_type = "PER" + charge_mode = "traffic" + } +} + +data "flexibleengine_vpc_eip" "test" { + public_ip = flexibleengine_vpc_eip.test.address +} +`, rName) +} diff --git a/flexibleengine/provider.go b/flexibleengine/provider.go index 5a861c878..17c1e1950 100644 --- a/flexibleengine/provider.go +++ b/flexibleengine/provider.go @@ -252,7 +252,6 @@ func Provider() *schema.Provider { "flexibleengine_vpc_subnet_v1": dataSourceVpcSubnetV1(), "flexibleengine_vpc_subnet_ids_v1": dataSourceVpcSubnetIdsV1(), "flexibleengine_vpc_peering_connection_v2": dataSourceVpcPeeringConnectionV2(), - "flexibleengine_vpc_eip": dataSourceVpcEipV1(), "flexibleengine_nat_gateway_v2": dataSourceNatGatewayV2(), @@ -319,6 +318,8 @@ func Provider() *schema.Provider { "flexibleengine_compute_servergroups": ecs.DataSourceComputeServerGroups(), + "flexibleengine_vpc_eip": eip.DataSourceVpcEip(), + "flexibleengine_css_flavors": css.DataSourceCssFlavors(), "flexibleengine_dcs_flavors": dcs.DataSourceDcsFlavorsV2(),