Skip to content

Commit

Permalink
resource/alicloud_polardb_cluster: modified support the enumeration v…
Browse files Browse the repository at this point in the history
…alue RecoverFromRecyclebin to creation_option.
  • Loading branch information
mengliux committed Oct 25, 2024
1 parent eee970a commit a0a19ff
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 3 deletions.
2 changes: 1 addition & 1 deletion alicloud/resource_alicloud_polardb_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func resourceAlicloudPolarDBCluster() *schema.Resource {
},
"creation_option": {
Type: schema.TypeString,
ValidateFunc: StringInSlice([]string{"Normal", "CloneFromPolarDB", "CloneFromRDS", "MigrationFromRDS", "CreateGdnStandby"}, false),
ValidateFunc: StringInSlice([]string{"Normal", "CloneFromPolarDB", "CloneFromRDS", "MigrationFromRDS", "CreateGdnStandby", "RecoverFromRecyclebin"}, false),
Optional: true,
Computed: true,
},
Expand Down
108 changes: 108 additions & 0 deletions alicloud/resource_alicloud_polardb_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,70 @@ func TestAccAliCloudPolarDBCluster_Xengine(t *testing.T) {

}

func TestAccAliCloudPolarDBCluster_CreateRecoverFromRecyclebin(t *testing.T) {
var v *polardb.DescribeDBClusterAttributeResponse
name := "tf-testPolarDBClusterCreateRecoverFromRecyclebin"
resourceId := "alicloud_polardb_cluster.default"
var basicMap = map[string]string{
"description": CHECKSET,
"db_node_class": CHECKSET,
"vswitch_id": CHECKSET,
"db_type": CHECKSET,
"db_version": CHECKSET,
"connection_string": REGEXMATCH + clusterConnectionStringRegexp,
"port": "3306",
}
ra := resourceAttrInit(resourceId, basicMap)
serviceFunc := func() interface{} {
return &PolarDBService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, serviceFunc, "DescribePolarDBClusterAttribute")
rac := resourceAttrCheckInit(rc, ra)

testAccCheck := rac.resourceAttrMapUpdateSet()
testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceRecoverFromRecyclebinClusterConfigDependence)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},

// module name
IDRefreshName: resourceId,

Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"db_type": "MySQL",
"db_version": "8.0",
"pay_type": "PostPaid",
"db_node_count": "2",
"db_node_class": "${data.alicloud_polardb_node_classes.this.classes.0.supported_engines.0.available_resources.0.db_node_class}",
"vswitch_id": "${local.vswitch_id}",
"description": "${var.name}",
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.0}",
"creation_option": "RecoverFromRecyclebin",
"creation_category": "Normal",
"source_resource_id": "pc-bp1xzqe7d4n1s0ge9",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"resource_group_id": CHECKSET,
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"modify_type", "creation_option", "gdn_id", "source_resource_id"},
},
},
})
}

func testAccCheckKeyValueInMapsForPolarDB(ps []map[string]interface{}, propName, key, value string) resource.TestCheckFunc {
return func(s *terraform.State) error {
for _, policy := range ps {
Expand Down Expand Up @@ -2240,6 +2304,50 @@ func resourcePolarDBClusterSteadyServerlessConfigDependence(name string) string
`, name)
}

func resourceRecoverFromRecyclebinClusterConfigDependence(name string) string {
return fmt.Sprintf(`
variable "name" {
default = "%s"
}
data "alicloud_vpcs" "default" {
name_regex = "^default-NODELETING$"
}
resource "alicloud_vpc" "default" {
vpc_name = var.name
}
resource "alicloud_vswitch" "default" {
zone_id = data.alicloud_polardb_node_classes.this.classes.0.zone_id
vpc_id = alicloud_vpc.default.id
cidr_block = cidrsubnet(alicloud_vpc.default.cidr_block, 8, 4)
}
locals {
vpc_id = alicloud_vpc.default.id
vswitch_id = concat(alicloud_vswitch.default.*.id, [""])[0]
}
data "alicloud_polardb_node_classes" "this" {
db_type = "MySQL"
db_version = "8.0"
pay_type = "PostPaid"
category = "Normal"
}
data "alicloud_resource_manager_resource_groups" "default" {
status = "OK"
}
resource "alicloud_security_group" "default" {
count = 2
name = "${var.name}"
vpc_id = alicloud_vpc.default.id
}
`, name)
}

func deleteTDEPolicyAndRole() error {
// 删除策略
p := Provider().(*schema.Provider).ResourcesMap
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/polardb_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ The following arguments are supported:
-> **NOTE:** Only polardb MySQL Cluster version is available. The cluster with minor version number of 8.0.1 supports the column index feature, and the specific kernel version must be 8.0.1.1.22 or above.
-> **NOTE:** The single node, the single node version of the history library, and the cluster version of the history library do not support column save indexes.
* `sub_category` - (Optional, Available since 1.177.0) The category of the cluster. Valid values are `Exclusive`, `General`. Only MySQL supports.
* `creation_option` - (Optional, Available since 1.179.0) The method that is used to create a cluster. Valid values are `Normal`,`CloneFromPolarDB`,`CloneFromRDS`,`MigrationFromRDS`,`CreateGdnStandby`.Value options can refer to the latest docs [CreateDBCluster](https://www.alibabacloud.com/help/en/polardb/latest/createdbcluster-1) `CreationOption`.
-> **NOTE:** The default value is Normal. If DBType is set to MySQL and DBVersion is set to 5.6 or 5.7, this parameter can be set to CloneFromRDS or MigrationFromRDS. If DBType is set to MySQL and DBVersion is set to 8.0, this parameter can be set to CreateGdnStandby.
* `creation_option` - (Optional, Available since 1.179.0) The method that is used to create a cluster. Valid values are `Normal`,`CloneFromPolarDB`,`CloneFromRDS`,`MigrationFromRDS`,`CreateGdnStandby`, `RecoverFromRecyclebin`.Value options can refer to the latest docs [CreateDBCluster](https://www.alibabacloud.com/help/en/polardb/latest/createdbcluster-1) `CreationOption`.
-> **NOTE:** The default value is Normal. If DBType is set to MySQL and DBVersion is set to 5.6 or 5.7, this parameter can be set to CloneFromRDS or MigrationFromRDS. If DBType is set to MySQL and DBVersion is set to 8.0, this parameter can be set to CreateGdnStandby. If `creation_option` is RecoverFromRecyclebin, you need to pass in the released source PolarDB cluster ID for this parameter. The DBType of the cluster recovered from the recycle bin and the source cluster must be consistent. For example, if the source cluster is MySQL 8.0, the cluster recovered from the recycle bin also needs to have its DBType set to MySQL and DBVersion set to 8.0.
* `creation_category` - (Optional, ForceNew, Computed, Available since 1.179.0) The edition of the PolarDB service. Valid values are `Normal`,`Basic`,`ArchiveNormal`,`NormalMultimaster`,`SENormal`.Value options can refer to the latest docs [CreateDBCluster](https://www.alibabacloud.com/help/en/polardb/latest/createdbcluster-1) `CreationCategory`.
-> **NOTE:** You can set this parameter to Basic only when DBType is set to MySQL and DBVersion is set to 5.6, 5.7, or 8.0. You can set this parameter to Archive only when DBType is set to MySQL and DBVersion is set to 8.0. From version 1.188.0, `creation_category` can be set to `NormalMultimaster`. From version 1.203.0, `creation_category` can be set to `SENormal`.
* `source_resource_id` - (Optional, Available since 1.179.0) The ID of the source RDS instance or the ID of the source PolarDB cluster. This parameter is required only when CreationOption is set to MigrationFromRDS, CloneFromRDS, or CloneFromPolarDB.Value options can refer to the latest docs [CreateDBCluster](https://www.alibabacloud.com/help/en/polardb/latest/createdbcluster-1) `SourceResourceId`.
Expand Down

0 comments on commit a0a19ff

Please sign in to comment.