-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GaussDB): add gaussdb opengauss recycling instances data source
- Loading branch information
Showing
4 changed files
with
450 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
docs/data-sources/gaussdb_opengauss_recycling_instances.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
subcategory: "GaussDB" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_gaussdb_opengauss_recycling_instances" | ||
description: |- | ||
Use this data source to get the list of GaussDB OpenGauss instances in the recycle bin. | ||
--- | ||
|
||
# huaweicloud_gaussdb_opengauss_recycling_instances | ||
|
||
Use this data source to get the list of GaussDB OpenGauss instances in the recycle bin. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "huaweicloud_gaussdb_opengauss_recycling_instances" "test" {} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String) Specifies the region in which to query the resource. | ||
If omitted, the provider-level region will be used. | ||
|
||
* `instance_name` - (Optional, String) Specifies the GaussDB OpenGauss instance name. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `instances` - Indicates the information about all instances in the recycle bin. | ||
|
||
The [instances](#instances_struct) structure is documented below. | ||
|
||
<a name="instances_struct"></a> | ||
The `instances` block supports: | ||
|
||
* `id` - Indicates the instance ID. | ||
|
||
* `name` - Indicates the instance name. | ||
|
||
* `mode` - Indicates the product type. | ||
The value can be: | ||
+ **basic**: basic edition | ||
+ **standard**: standard edition | ||
+ **enterprise**: enterprise edition | ||
|
||
* `ha_mode` - Indicates the deployment model. | ||
The value can be: | ||
+ **Ha**: primary/standby deployment | ||
+ **Independent**: independent deployment | ||
+ **Combined**: combined deployment | ||
|
||
* `engine_name` - Indicates the engine name. | ||
|
||
* `engine_version` - Indicates the engine version. | ||
|
||
* `pay_model` - Indicates the billing mode. | ||
The value can be: | ||
+ **0**: pay-per-use | ||
+ **1**: yearly/monthly | ||
|
||
* `volume_type` - Indicates the disk type. | ||
The value can be: | ||
+ **high**: high I/O | ||
+ **ultrahigh**: ultra-high I/O | ||
+ **essd**: extreme SSD | ||
|
||
* `volume_size` - Indicates the disk size. | ||
|
||
* `enterprise_project_id` - Indicates the enterprise project ID. | ||
|
||
* `enterprise_project_name` - Indicates the enterprise project name. | ||
|
||
* `recycle_backup_id` - Indicates the backup ID. | ||
|
||
* `backup_level` - Indicates the backup level. | ||
|
||
* `data_vip` - Indicates the private IP address. | ||
|
||
* `recycle_status` - Indicates the backup status in the recycle bin. | ||
The value can be: **Running**, **Active**. | ||
|
||
* `created_at` - Indicates the creation time in the **yyyy-mm-ddThh:mm:ssZ** format. | ||
|
||
* `deleted_at` - Indicates the deletion time in the **yyyy-mm-ddThh:mm:ssZ** format. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
.../acceptance/gaussdb/data_source_huaweicloud_gaussdb_opengauss_recycling_instances_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package gaussdb | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance/common" | ||
) | ||
|
||
func TestAccDataSourceGaussdbOpengaussRecyclingInstances_basic(t *testing.T) { | ||
dataSource := "data.huaweicloud_gaussdb_opengauss_recycling_instances.test" | ||
rName := acceptance.RandomAccResourceName() | ||
dc := acceptance.InitDataSourceCheck(dataSource) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceGaussdbOpengaussRecyclingInstances_create_instance(rName), | ||
}, | ||
{ | ||
Config: testDataSourceGaussdbOpengaussRecyclingInstances_delete_instance(), | ||
}, | ||
{ | ||
Config: testDataSourceGaussdbOpengaussRecyclingInstances_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.mode"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.ha_mode"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.engine_name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.engine_version"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.pay_model"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.volume_type"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.enterprise_project_id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.enterprise_project_name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.recycle_backup_id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.data_vip"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.recycle_status"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.created_at"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.deleted_at"), | ||
resource.TestCheckOutput("instance_name_filter_is_useful", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceGaussdbOpengaussRecyclingInstances_create_instance(rName string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
data "huaweicloud_availability_zones" "test" {} | ||
data "huaweicloud_gaussdb_opengauss_flavors" "test" { | ||
version = "8.201" | ||
ha_mode = "centralization_standard" | ||
} | ||
resource "huaweicloud_networking_secgroup_rule" "in_v4_tcp_opengauss" { | ||
security_group_id = huaweicloud_networking_secgroup.test.id | ||
ethertype = "IPv4" | ||
direction = "ingress" | ||
protocol = "tcp" | ||
remote_ip_prefix = "0.0.0.0/0" | ||
} | ||
resource "huaweicloud_networking_secgroup_rule" "in_v4_tcp_opengauss_egress" { | ||
security_group_id = huaweicloud_networking_secgroup.test.id | ||
ethertype = "IPv4" | ||
direction = "egress" | ||
protocol = "tcp" | ||
remote_ip_prefix = "0.0.0.0/0" | ||
} | ||
resource "huaweicloud_gaussdb_opengauss_instance" "test" { | ||
depends_on = [ | ||
huaweicloud_networking_secgroup_rule.in_v4_tcp_opengauss, | ||
huaweicloud_networking_secgroup_rule.in_v4_tcp_opengauss_egress | ||
] | ||
vpc_id = huaweicloud_vpc.test.id | ||
subnet_id = huaweicloud_vpc_subnet.test.id | ||
security_group_id = huaweicloud_networking_secgroup.test.id | ||
flavor = data.huaweicloud_gaussdb_opengauss_flavors.test.flavors[0].spec_code | ||
name = "%[2]s" | ||
password = "Huangwei!120521" | ||
replica_num = 3 | ||
availability_zone = join(",", [data.huaweicloud_availability_zones.test.names[0], | ||
data.huaweicloud_availability_zones.test.names[1], | ||
data.huaweicloud_availability_zones.test.names[2]]) | ||
enterprise_project_id = "%[3]s" | ||
ha { | ||
mode = "centralization_standard" | ||
replication_mode = "sync" | ||
consistency = "eventual" | ||
instance_mode = "basic" | ||
} | ||
volume { | ||
type = "ULTRAHIGH" | ||
size = 40 | ||
} | ||
} | ||
`, common.TestBaseNetwork(rName), rName, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST) | ||
} | ||
|
||
func testDataSourceGaussdbOpengaussRecyclingInstances_delete_instance() string { | ||
return ` | ||
data "huaweicloud_availability_zones" "test" {} | ||
data "huaweicloud_gaussdb_opengauss_flavors" "test" { | ||
version = "8.201" | ||
ha_mode = "centralization_standard" | ||
}` | ||
} | ||
|
||
func testDataSourceGaussdbOpengaussRecyclingInstances_basic(rName string) string { | ||
return fmt.Sprintf(` | ||
data "huaweicloud_gaussdb_opengauss_recycling_instances" "test" {} | ||
locals { | ||
instance_name = "%[1]s" | ||
} | ||
data "huaweicloud_gaussdb_opengauss_recycling_instances" "instance_name_filter" { | ||
instance_name = "%[1]s" | ||
} | ||
output "instance_name_filter_is_useful" { | ||
value = length(data.huaweicloud_gaussdb_opengauss_recycling_instances.instance_name_filter.instances) > 0 && alltrue( | ||
[for v in data.huaweicloud_gaussdb_opengauss_recycling_instances.instance_name_filter.instances[*] : v.name == local.instance_name] | ||
) | ||
} | ||
`, rName) | ||
} |
Oops, something went wrong.