-
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 restore resource (#6093)
- Loading branch information
Showing
4 changed files
with
460 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,89 @@ | ||
--- | ||
subcategory: "GaussDB" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_gaussdb_opengauss_restore" | ||
description: |- | ||
Use this resource to restore a GaussDB OpenGauss instance with a backup within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_gaussdb_opengauss_restore | ||
|
||
Use this resource to restore a GaussDB OpenGauss instance with a backup within HuaweiCloud. | ||
|
||
-> **NOTE:** Deleting restoration record is not supported. If you destroy a resource of restoration record, | ||
the restoration record is only removed from the state, but it remains in the cloud. And the instance doesn't return to | ||
the state before restoration. | ||
|
||
## Example Usage | ||
|
||
### restore by backup_id | ||
|
||
```hcl | ||
variable "target_instance_id" {} | ||
variable "source_instance_id" {} | ||
variable "backup_id" {} | ||
resource "huaweicloud_gaussdb_opengauss_restore" "test" { | ||
target_instance_id = var.target_instance_id | ||
source_instance_id = var.source_instance_id | ||
type = "backup" | ||
backup_id = var.backup_id | ||
} | ||
``` | ||
|
||
### restore by timestamp | ||
|
||
```hcl | ||
variable "target_instance_id" {} | ||
variable "source_instance_id" {} | ||
resource "huaweicloud_gaussdb_opengauss_restore" "test" { | ||
target_instance_id = var.target_instance_id | ||
source_instance_id = var.source_instance_id | ||
type = "timestamp" | ||
restore_time = 1673852043000 | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String, ForceNew) The region in which to create the GaussDB OpenGauss restore resource. If omitted, | ||
the provider-level region will be used. Changing this creates a new resource. | ||
|
||
* `target_instance_id` - (Required, String, ForceNew) Specifies the target instance ID. | ||
|
||
Changing this creates a new resource. | ||
|
||
* `source_instance_id` - (Required, String, ForceNew) Specifies the source instance ID. | ||
|
||
Changing this creates a new resource. | ||
|
||
* `type` - (Required, String, ForceNew) Specifies the restoration type. Value options: | ||
+ **backup**: indicates restoration from backup files. In this mode, `backup_id` is mandatory. | ||
+ **timestamp**: indicates point-in-time restoration. In this mode, `restore_time` is mandatory. | ||
|
||
Changing this creates a new resource. | ||
|
||
* `backup_id` - (Optional, String, ForceNew) Specifies the ID of the backup to be restored. It indicates the ID of the | ||
full backup corresponding to schema_type. This parameter must be specified when the backup file is used for restoration. | ||
|
||
Changing this creates a new resource. | ||
|
||
* `restore_time` - (Optional, String, ForceNew) Specifies the time point of data restoration in the UNIX timestamp format. | ||
The unit is millisecond and the time zone is UTC. | ||
|
||
Changing this creates a new resource. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attribute is exported: | ||
|
||
* `id` - The resource ID. The value is the restore job ID. | ||
|
||
## Timeouts | ||
|
||
This resource provides the following timeouts configuration options: | ||
|
||
* `create` - Default is 60 minutes. |
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
214 changes: 214 additions & 0 deletions
214
...icloud/services/acceptance/gaussdb/resource_huaweicloud_gaussdb_opengauss_restore_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,214 @@ | ||
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 TestAccOpenGaussRestore_basic(t *testing.T) { | ||
name := acceptance.RandomAccResourceName() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckEpsID(t) | ||
acceptance.TestAccPreCheckHighCostAllow(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccOpenGaussRestoreonfig_basic(name), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccOpenGaussRestore_withTimestamp(t *testing.T) { | ||
name := acceptance.RandomAccResourceName() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckEpsID(t) | ||
acceptance.TestAccPreCheckHighCostAllow(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccOpenGaussRestoreonfig_withTimestamp(name), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccOpenGaussRestoreonfig_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" "source" { | ||
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_source" | ||
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 | ||
} | ||
} | ||
`, common.TestBaseNetwork(name), name, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST) | ||
} | ||
|
||
func testAccOpenGaussRestoreonfig_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_gaussdb_opengauss_instance" "target" { | ||
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_target" | ||
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" { | ||
instance_id = huaweicloud_gaussdb_opengauss_instance.source.id | ||
name = "%[2]s_backup" | ||
} | ||
resource "huaweicloud_gaussdb_opengauss_restore" "test" { | ||
target_instance_id = huaweicloud_gaussdb_opengauss_instance.target.id | ||
source_instance_id = huaweicloud_gaussdb_opengauss_instance.source.id | ||
type = "backup" | ||
backup_id = huaweicloud_gaussdb_opengauss_backup.backup.id | ||
} | ||
`, testAccOpenGaussRestoreonfig_base(name), name, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST) | ||
} | ||
|
||
func testAccOpenGaussRestoreonfig_withTimestamp(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_gaussdb_opengauss_instance" "target" { | ||
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_target" | ||
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" { | ||
instance_id = huaweicloud_gaussdb_opengauss_instance.source.id | ||
name = "%[2]s_backup" | ||
} | ||
data "huaweicloud_gaussdb_opengauss_restore_time_ranges" "restore_time" { | ||
depends_on = [huaweicloud_gaussdb_opengauss_backup.backup] | ||
instance_id = huaweicloud_gaussdb_opengauss_instance.source.id | ||
date = split("T", huaweicloud_gaussdb_opengauss_backup.backup.end_time)[0] | ||
} | ||
resource "huaweicloud_gaussdb_opengauss_restore" "test" { | ||
target_instance_id = huaweicloud_gaussdb_opengauss_instance.target.id | ||
source_instance_id = huaweicloud_gaussdb_opengauss_instance.source.id | ||
type = "timestamp" | ||
restore_time = data.huaweicloud_gaussdb_opengauss_restore_time_ranges.restore_time.restore_time[0].start_time | ||
} | ||
`, testAccOpenGaussRestoreonfig_base(name), name, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST) | ||
} |
Oops, something went wrong.