-
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 backup stop resource
- Loading branch information
Showing
4 changed files
with
256 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,43 @@ | ||
--- | ||
subcategory: "GaussDB" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_gaussdb_opengauss_backup_stop" | ||
description: |- | ||
Manages a GaussDB OpenGauss backup stop resource within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_gaussdb_opengauss_backup_stop | ||
|
||
Manages a GaussDB OpenGauss backup stop resource within HuaweiCloud. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "instance_id" {} | ||
resource "huaweicloud_gaussdb_opengauss_backup_stop" "test" { | ||
instance_id = var.instance_id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource. | ||
If omitted, the provider-level region will be used. Changing this parameter will create a new resource. | ||
|
||
* `instance_id` - (Required, String, ForceNew) Specifies the ID of the GaussDB OpenGauss instance. Changing this parameter | ||
will create a new resource. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The resource ID which equals to the `instance_id`. | ||
|
||
## Timeouts | ||
|
||
This resource provides the following timeouts configuration options: | ||
|
||
* `create` - Default is 30 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
106 changes: 106 additions & 0 deletions
106
...ud/services/acceptance/gaussdb/resource_huaweicloud_gaussdb_opengauss_backup_stop_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,106 @@ | ||
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 TestAccGaussDBOpenGaussBackupStop_basic(t *testing.T) { | ||
var obj interface{} | ||
rName := acceptance.RandomAccResourceNameWithDash() | ||
resourceName := "huaweicloud_gaussdb_opengauss_backup_stop.test" | ||
|
||
rc := acceptance.InitResourceCheck( | ||
resourceName, | ||
&obj, | ||
getOpenGaussInstanceFunc, | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.TestAccPreCheck(t) }, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccGaussDBOpenGaussBackupStop_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccGaussDBOpenGaussBackupStop_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 | ||
} | ||
} | ||
`, common.TestBaseNetwork(name), name, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST) | ||
} | ||
|
||
func testAccGaussDBOpenGaussBackupStop_basic(rName string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_gaussdb_opengauss_backup_stop" "test" { | ||
instance_id = huaweicloud_gaussdb_opengauss_instance.test.id | ||
}`, testAccGaussDBOpenGaussBackupStop_base(rName)) | ||
} |
106 changes: 106 additions & 0 deletions
106
huaweicloud/services/gaussdb/resource_huaweicloud_gaussdb_opengauss_backup_stop.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,106 @@ | ||
package gaussdb | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/chnsz/golangsdk" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils" | ||
) | ||
|
||
// @API GaussDB POST /v3/{project_id}/instances/{instance_id}/backups/stop | ||
// @API GaussDB GET /v3/{project_id}/jobs | ||
func ResourceOpenGaussBackupStop() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceOpenGaussBackupStopCreate, | ||
ReadContext: resourceOpenGaussBackupStopRead, | ||
DeleteContext: resourceOpenGaussBackupStopDelete, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(30 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
"instance_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceOpenGaussBackupStopCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
cfg := meta.(*config.Config) | ||
region := cfg.GetRegion(d) | ||
|
||
var ( | ||
httpUrl = "v3/{project_id}/instances/{instance_id}/backups/stop" | ||
product = "opengauss" | ||
) | ||
client, err := cfg.NewServiceClient(product, region) | ||
if err != nil { | ||
return diag.Errorf("error creating GaussDB client: %s", err) | ||
} | ||
|
||
instanceId := d.Get("instance_id").(string) | ||
createPath := client.Endpoint + httpUrl | ||
createPath = strings.ReplaceAll(createPath, "{project_id}", client.ProjectID) | ||
createPath = strings.ReplaceAll(createPath, "{instance_id}", instanceId) | ||
|
||
createOpt := golangsdk.RequestOpts{ | ||
KeepResponseBody: true, | ||
MoreHeaders: map[string]string{"Content-Type": "application/json"}, | ||
} | ||
|
||
createResp, err := client.Request("POST", createPath, &createOpt) | ||
if err != nil { | ||
return diag.Errorf("error stopping GaussDB OpenGauss instance(%s) backup: %s", instanceId, err) | ||
} | ||
createRespBody, err := utils.FlattenResponse(createResp) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
jobId := utils.PathSearch("job_id", createRespBody, nil) | ||
if jobId == nil { | ||
return diag.Errorf("error stopping GaussDB OpenGauss instance(%s), job_id is not found in the response", | ||
instanceId) | ||
} | ||
|
||
d.SetId(instanceId) | ||
|
||
err = checkGaussDBOpenGaussJobFinish(ctx, client, jobId.(string), 30, d.Timeout(schema.TimeoutCreate)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceOpenGaussBackupStopRead(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { | ||
return nil | ||
} | ||
|
||
func resourceOpenGaussBackupStopDelete(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { | ||
errorMsg := "Deleting GaussDB OpenGauss backup stop resource is not supported. The resource is only removed from" + | ||
" the state, the GaussDB OpenGauss instance remains in the cloud." | ||
return diag.Diagnostics{ | ||
diag.Diagnostic{ | ||
Severity: diag.Warning, | ||
Summary: errorMsg, | ||
}, | ||
} | ||
} |