-
Notifications
You must be signed in to change notification settings - Fork 164
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 backups data source (#6063)
- Loading branch information
Showing
4 changed files
with
516 additions
and
0 deletions.
There are no files selected for viewing
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,95 @@ | ||
--- | ||
subcategory: "GaussDB" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_gaussdb_opengauss_backups" | ||
description: |- | ||
Use this data source to get the list of GaussDB OpenGauss backups. | ||
--- | ||
|
||
# huaweicloud_gaussdb_opengauss_backups | ||
|
||
Use this data source to get the list of GaussDB OpenGauss backups. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "instance_id" {} | ||
variable "backup_id" {} | ||
data "huaweicloud_gaussdb_opengauss_backups" "test" { | ||
instance_id = var.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. | ||
|
||
* `instance_id` - (Optional, String) Specifies the ID of the GaussDB OpenGauss instance | ||
|
||
* `backup_id` - (Optional, String) Specifies the ID of the backup. | ||
|
||
* `backup_type` - (Optional, String) Specifies the backup type. | ||
Value options: | ||
+ **auto**: instance-level automated full backup. | ||
+ **manual**: instance-level manual full backup. | ||
|
||
* `begin_time` - (Optional, String) Specifies the query start time in the **yyyy-mm-ddThh:mm:ssZ** format. | ||
It can be used together with `end_time`. If `end_time` is not used, the backups created after begin_time are | ||
returned. If `end_time` is used, the backups created between `begin_time` and `end_time` are returned. | ||
|
||
* `end_time` - (Optional, String) Specifies the query end time in the **yyyy-mm-ddThh:mm:ssZ** format. | ||
It must be later than the start time. It can be used together with `begin_time`. If `begin_time` is not used, the | ||
backups created before `end_time` are returned. If `begin_time` is used, the backups created between | ||
`begin_time` and `end_time` are returned. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `backups` - Indicates the list of backups. | ||
|
||
The [backups](#backups_struct) structure is documented below. | ||
|
||
<a name="backups_struct"></a> | ||
The `backups` block supports: | ||
|
||
* `id` - Indicates the ID of the backup. | ||
|
||
* `name` - Indicates the name of the backup. | ||
|
||
* `instance_id` - Indicates the ID of the GaussDB OpenGauss instance. | ||
|
||
* `description` - Indicates the description of the backup. | ||
|
||
* `begin_time` - Indicates the backup start time in the **yyyy-mm-ddThh:mm:ssZ** format. | ||
|
||
* `end_time` - Indicates the backup end time in the **yyyy-mm-ddThh:mm:ssZ** format. | ||
|
||
* `type` - Indicates the backup type. | ||
|
||
* `size` - Indicates the backup size in MB. | ||
|
||
* `status` - Indicates the backup status. | ||
The value can be: | ||
+ **BUILDING**: Backup in progress | ||
+ **COMPLETED**: Backup completed | ||
+ **FAILED**: Backup failed | ||
|
||
* `datastore` - Indicates the database information. | ||
|
||
The [datastore](#backups_datastore_struct) structure is documented below. | ||
|
||
<a name="backups_datastore_struct"></a> | ||
The `datastore` block supports: | ||
|
||
* `type` - Indicates the DB engine. | ||
The value is case-insensitive and can be: **GaussDB**. | ||
|
||
* `version` - Indicates the DB engine version |
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
201 changes: 201 additions & 0 deletions
201
...oud/services/acceptance/gaussdb/data_source_huaweicloud_gaussdb_opengauss_backups_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,201 @@ | ||
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 TestAccDataSourceGaussdbOpengaussBackups_basic(t *testing.T) { | ||
dataSource := "data.huaweicloud_gaussdb_opengauss_backups.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: testDataSourceGaussdbOpengaussBackups_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.instance_id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.begin_time"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.end_time"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.type"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.size"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.status"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.datastore.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.datastore.0.type"), | ||
resource.TestCheckResourceAttrSet(dataSource, "backups.0.datastore.0.version"), | ||
resource.TestCheckOutput("instance_id_filter_is_useful", "true"), | ||
resource.TestCheckOutput("backup_id_filter_is_useful", "true"), | ||
resource.TestCheckOutput("backup_type_filter_is_useful", "true"), | ||
resource.TestCheckOutput("begin_time_filter_is_useful", "true"), | ||
resource.TestCheckOutput("end_time_filter_is_useful", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceGaussdbOpengaussBackups_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 | ||
] | ||
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" | ||
enterprise_project_id = "%[3]s" | ||
availability_zone = join(",", [data.huaweicloud_availability_zones.test.names[0], | ||
data.huaweicloud_availability_zones.test.names[1], | ||
data.huaweicloud_availability_zones.test.names[2]]) | ||
ha { | ||
mode = "centralization_standard" | ||
replication_mode = "sync" | ||
consistency = "eventual" | ||
instance_mode = "basic" | ||
} | ||
volume { | ||
type = "ULTRAHIGH" | ||
size = 40 | ||
} | ||
} | ||
resource "huaweicloud_gaussdb_opengauss_backup" "backup_1" { | ||
instance_id = huaweicloud_gaussdb_opengauss_instance.test.id | ||
name = "%[2]s_backup_1" | ||
description = "test description" | ||
} | ||
resource "huaweicloud_gaussdb_opengauss_backup" "backup_2" { | ||
depends_on = [huaweicloud_gaussdb_opengauss_backup.backup_1] | ||
instance_id = huaweicloud_gaussdb_opengauss_instance.test.id | ||
name = "%[2]s_backup_2" | ||
description = "test description" | ||
} | ||
`, common.TestBaseNetwork(name), name, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST) | ||
} | ||
|
||
func testDataSourceGaussdbOpengaussBackups_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
data "huaweicloud_gaussdb_opengauss_backups" "test" { | ||
depends_on = [huaweicloud_gaussdb_opengauss_backup.backup_2] | ||
} | ||
locals { | ||
instance_id = huaweicloud_gaussdb_opengauss_instance.test.id | ||
} | ||
data "huaweicloud_gaussdb_opengauss_backups" "instance_id_filter" { | ||
depends_on = [huaweicloud_gaussdb_opengauss_backup.backup_2] | ||
instance_id = huaweicloud_gaussdb_opengauss_instance.test.id | ||
} | ||
output "instance_id_filter_is_useful" { | ||
value = length(data.huaweicloud_gaussdb_opengauss_backups.instance_id_filter.backups) > 0 && alltrue( | ||
[for v in data.huaweicloud_gaussdb_opengauss_backups.instance_id_filter.backups[*].instance_id : v == local.instance_id] | ||
) | ||
} | ||
locals { | ||
backup_id = huaweicloud_gaussdb_opengauss_backup.backup_2.id | ||
} | ||
data "huaweicloud_gaussdb_opengauss_backups" "backup_id_filter" { | ||
depends_on = [huaweicloud_gaussdb_opengauss_backup.backup_2] | ||
backup_id = huaweicloud_gaussdb_opengauss_backup.backup_2.id | ||
} | ||
output "backup_id_filter_is_useful" { | ||
value = length(data.huaweicloud_gaussdb_opengauss_backups.backup_id_filter.backups) > 0 && alltrue( | ||
[for v in data.huaweicloud_gaussdb_opengauss_backups.backup_id_filter.backups[*].id : v == local.backup_id] | ||
) | ||
} | ||
locals { | ||
backup_type = "manual" | ||
} | ||
data "huaweicloud_gaussdb_opengauss_backups" "backup_type_filter" { | ||
depends_on = [huaweicloud_gaussdb_opengauss_backup.backup_2] | ||
backup_type = "manual" | ||
} | ||
output "backup_type_filter_is_useful" { | ||
value = length(data.huaweicloud_gaussdb_opengauss_backups.backup_type_filter.backups) > 0 && alltrue( | ||
[for v in data.huaweicloud_gaussdb_opengauss_backups.backup_type_filter.backups[*].type : v == local.backup_type] | ||
) | ||
} | ||
locals { | ||
begin_time = huaweicloud_gaussdb_opengauss_backup.backup_1.begin_time | ||
} | ||
data "huaweicloud_gaussdb_opengauss_backups" "begin_time_filter" { | ||
depends_on = [huaweicloud_gaussdb_opengauss_backup.backup_2] | ||
begin_time = huaweicloud_gaussdb_opengauss_backup.backup_1.begin_time | ||
} | ||
output "begin_time_filter_is_useful" { | ||
value = length(data.huaweicloud_gaussdb_opengauss_backups.begin_time_filter.backups) > 0 | ||
} | ||
locals { | ||
end_time = huaweicloud_gaussdb_opengauss_backup.backup_2.end_time | ||
} | ||
data "huaweicloud_gaussdb_opengauss_backups" "end_time_filter" { | ||
depends_on = [huaweicloud_gaussdb_opengauss_backup.backup_2] | ||
end_time = huaweicloud_gaussdb_opengauss_backup.backup_2.end_time | ||
} | ||
output "end_time_filter_is_useful" { | ||
value = length(data.huaweicloud_gaussdb_opengauss_backups.end_time_filter.backups) > 0 | ||
} | ||
`, testDataSourceGaussdbOpengaussBackups_base(name)) | ||
} |
Oops, something went wrong.