Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(GaussDB): add gaussdb opengauss restorable instances data source #6096

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions docs/data-sources/gaussdb_opengauss_restorable_instances.md
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
19 changes: 10 additions & 9 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,15 +805,16 @@ func Provider() *schema.Provider {
"huaweicloud_gaussdb_redis_flavors": geminidb.DataSourceGaussDBRedisFlavors(),
"huaweicloud_gaussdb_influx_instances": geminidb.DataSourceGaussDBInfluxInstances(),

"huaweicloud_gaussdb_opengauss_datastores": gaussdb.DataSourceGaussdbOpengaussDatastores(),
"huaweicloud_gaussdb_opengauss_flavors": gaussdb.DataSourceGaussdbOpengaussFlavors(),
"huaweicloud_gaussdb_opengauss_instance": gaussdb.DataSourceOpenGaussInstance(),
"huaweicloud_gaussdb_opengauss_instances": gaussdb.DataSourceOpenGaussInstances(),
"huaweicloud_gaussdb_opengauss_instance_nodes": gaussdb.DataSourceGaussdbOpengaussInstanceNodes(),
"huaweicloud_gaussdb_opengauss_databases": gaussdb.DataSourceOpenGaussDatabases(),
"huaweicloud_gaussdb_opengauss_parameter_templates": gaussdb.DataSourceGaussdbOpengaussParameterTemplates(),
"huaweicloud_gaussdb_opengauss_restore_time_ranges": gaussdb.DataSourceGaussdbOpengaussRestoreTimeRanges(),
"huaweicloud_gaussdb_opengauss_backups": gaussdb.DataSourceGaussdbOpengaussBackups(),
"huaweicloud_gaussdb_opengauss_datastores": gaussdb.DataSourceGaussdbOpengaussDatastores(),
"huaweicloud_gaussdb_opengauss_flavors": gaussdb.DataSourceGaussdbOpengaussFlavors(),
"huaweicloud_gaussdb_opengauss_instance": gaussdb.DataSourceOpenGaussInstance(),
"huaweicloud_gaussdb_opengauss_instances": gaussdb.DataSourceOpenGaussInstances(),
"huaweicloud_gaussdb_opengauss_instance_nodes": gaussdb.DataSourceGaussdbOpengaussInstanceNodes(),
"huaweicloud_gaussdb_opengauss_databases": gaussdb.DataSourceOpenGaussDatabases(),
"huaweicloud_gaussdb_opengauss_parameter_templates": gaussdb.DataSourceGaussdbOpengaussParameterTemplates(),
"huaweicloud_gaussdb_opengauss_restore_time_ranges": gaussdb.DataSourceGaussdbOpengaussRestoreTimeRanges(),
"huaweicloud_gaussdb_opengauss_restorable_instances": gaussdb.DataSourceGaussdbOpengaussRestorableInstances(),
"huaweicloud_gaussdb_opengauss_backups": gaussdb.DataSourceGaussdbOpengaussBackups(),

"huaweicloud_gaussdb_mysql_engine_versions": taurusdb.DataSourceGaussdbMysqlEngineVersions(),
"huaweicloud_gaussdb_mysql_configuration": taurusdb.DataSourceGaussdbMysqlConfiguration(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ func TestAccOpenGaussInstanceDataSource_basic(t *testing.T) {
dataSourceName := "data.huaweicloud_gaussdb_opengauss_instance.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
acceptance.TestAccPreCheckHighCostAllow(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Expand All @@ -37,7 +41,11 @@ func TestAccOpenGaussInstanceDataSource_haModeCentralized(t *testing.T) {
dataSourceName := "data.huaweicloud_gaussdb_opengauss_instance.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
acceptance.TestAccPreCheckHighCostAllow(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ func TestAccOpenGaussInstancesDataSource_basic(t *testing.T) {
dataSourceName := "data.huaweicloud_gaussdb_opengauss_instances.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
acceptance.TestAccPreCheckHighCostAllow(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Expand All @@ -38,7 +42,11 @@ func TestAccOpenGaussInstancesDataSource_haModeCentralized(t *testing.T) {
dataSourceName := "data.huaweicloud_gaussdb_opengauss_instances.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
acceptance.TestAccPreCheckHighCostAllow(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Expand Down
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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func TestAccGaussDBOpenGaussBackupStop_basic(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
acceptance.TestAccPreCheckHighCostAllow(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: nil,
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ func TestAccGaussDBOpenGaussBackup_basic(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
acceptance.TestAccPreCheckHighCostAllow(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func TestAccOpenGaussInstanceRestart_basic(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
acceptance.TestAccPreCheckHighCostAllow(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: nil,
Steps: []resource.TestStep{
Expand Down
Loading
Loading