-
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 restorable instances data source (…
- Loading branch information
Showing
9 changed files
with
423 additions
and
16 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
docs/data-sources/gaussdb_opengauss_restorable_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,70 @@ | ||
--- | ||
subcategory: "GaussDB" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_gaussdb_opengauss_restorable_instances" | ||
description: |- | ||
Use this data source to get the instances that can be used for backups and restorations. | ||
--- | ||
|
||
# huaweicloud_gaussdb_opengauss_restorable_instances | ||
|
||
Use this data source to get the instances that can be used for backups and restorations. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "source_instance_id" {} | ||
variable "backup_id" {} | ||
data "huaweicloud_gaussdb_opengauss_restorable_instances" "test" { | ||
source_instance_id = var.source_instance_id | ||
backup_id = var.backup_id | ||
} | ||
``` | ||
|
||
## 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. | ||
|
||
* `source_instance_id` - (Required, String) Specifies the ID of the GaussDB OpenGauss instance to be restored. | ||
|
||
* `backup_id` - (Optional, String) Specifies the instance backup ID. | ||
|
||
* `restore_time` - (Optional, String) Specifies the time point of data restoration in the UNIX timestamp format. | ||
If the `backup_id` is left blank, this parameter is used to query the instance topology information and filter | ||
the queried instances. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `instances` - Indicates the instances that can be used for backups and restorations. | ||
|
||
The [instances](#instances_struct) structure is documented below. | ||
|
||
<a name="instances_struct"></a> | ||
The `instances` block supports: | ||
|
||
* `instance_id` - Indicates the instance ID. | ||
|
||
* `instance_name` - Indicates the instance name. | ||
|
||
* `instance_mode` - Indicates the instance model. | ||
+ **enterprise**: enterprise edition | ||
+ **standard**: standard edition | ||
+ **basic**: basic edition | ||
|
||
* `volume_type` - Indicates the storage type. | ||
|
||
* `data_volume_size` - Indicates the storage space, in GB | ||
|
||
* `version` - Indicates the instance version | ||
|
||
* `mode` - Indicates the deployment model. | ||
+ **Ha**: primary/standby deployment | ||
+ **Independent**: independent deployment |
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
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
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
140 changes: 140 additions & 0 deletions
140
...acceptance/gaussdb/data_source_huaweicloud_gaussdb_opengauss_restorable_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,140 @@ | ||
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 TestAccDataSourceGaussdbOpengaussRestorableInstances_basic(t *testing.T) { | ||
dataSource := "data.huaweicloud_gaussdb_opengauss_restorable_instances.test" | ||
rName := acceptance.RandomAccResourceName() | ||
dc := acceptance.InitDataSourceCheck(dataSource) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckEpsID(t) | ||
acceptance.TestAccPreCheckHighCostAllow(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceGaussdbOpengaussRestorableInstances_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.instance_id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.instance_name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.instance_mode"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.volume_type"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.data_volume_size"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.version"), | ||
resource.TestCheckResourceAttrSet(dataSource, "instances.0.mode"), | ||
resource.TestCheckOutput("restore_time_filter_is_useful", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceGaussdbOpengaussRestorableInstances_base(name 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 | ||
] | ||
count = 2 | ||
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_${count.index}" | ||
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 | ||
} | ||
} | ||
resource "huaweicloud_gaussdb_opengauss_backup" "test" { | ||
instance_id = huaweicloud_gaussdb_opengauss_instance.test[0].id | ||
name = "%[2]s_backup" | ||
} | ||
data "huaweicloud_gaussdb_opengauss_restore_time_ranges" "test" { | ||
instance_id = huaweicloud_gaussdb_opengauss_instance.test[0].id | ||
date = split("T", huaweicloud_gaussdb_opengauss_backup.test.end_time)[0] | ||
} | ||
`, common.TestBaseNetwork(name), name, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST) | ||
} | ||
|
||
func testDataSourceGaussdbOpengaussRestorableInstances_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "huaweicloud_gaussdb_opengauss_restorable_instances" "test" { | ||
source_instance_id = huaweicloud_gaussdb_opengauss_instance.test[0].id | ||
backup_id = huaweicloud_gaussdb_opengauss_backup.test.id | ||
} | ||
locals { | ||
restore_time = data.huaweicloud_gaussdb_opengauss_restore_time_ranges.test.restore_time[0].end_time | ||
} | ||
data "huaweicloud_gaussdb_opengauss_restorable_instances" "restore_time_filter" { | ||
source_instance_id = huaweicloud_gaussdb_opengauss_instance.test[0].id | ||
backup_id = huaweicloud_gaussdb_opengauss_backup.test.id | ||
restore_time = data.huaweicloud_gaussdb_opengauss_restore_time_ranges.test.restore_time[0].end_time | ||
} | ||
output "restore_time_filter_is_useful" { | ||
value = length(data.huaweicloud_gaussdb_opengauss_restorable_instances.restore_time_filter.instances) > 0 | ||
} | ||
`, testDataSourceGaussdbOpengaussRestorableInstances_base(name)) | ||
} |
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
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
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
Oops, something went wrong.