Skip to content

Commit

Permalink
resource/alicloud_polardb_cluster: support strictConsistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
mengliux committed Dec 16, 2024
1 parent 31c36a2 commit 6ef31d0
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 2 deletions.
1 change: 1 addition & 0 deletions alicloud/connectivity/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ var ActiontrailGlobalEventsStorageRegionSupportRegions = []Region{Hangzhou, APSo
var OceanBaseSupportRegions = []Region{Hangzhou}
var ChatbotSupportRegions = []Region{Shanghai}
var SENormalPolarDBSupportRegions = []Region{EUWest1, APNorthEast2, APSouthEast2, APSouthEast3, APSouthEast6, APSouthEast7, Huhehaote, Qingdao}
var Cluster3AZPolarDBSupportRegions = []Region{EUCentral1, Huhehaote, Qingdao, ChengDu, APNorthEast2, APSouthEast6, APSouthEast7}
var GDNPolarDBSupportRegions = []Region{ChengDu}
var VpcVSwitchCidrReservationSupportRegions = []Region{APSouthEast2}
var ComputeNestSupportRegions = []Region{Hangzhou}
Expand Down
22 changes: 22 additions & 0 deletions alicloud/resource_alicloud_polardb_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ func resourceAlicloudPolarDBCluster() *schema.Resource {
Optional: true,
ValidateFunc: StringInSlice([]string{"ON", "OFF"}, false),
Computed: true,
ForceNew: true,
},
"strict_consistency": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: StringInSlice([]string{"ON", "OFF"}, false),
Computed: true,
ForceNew: true,
},
"serverless_type": {
Type: schema.TypeString,
Expand Down Expand Up @@ -1641,6 +1649,8 @@ func resourceAlicloudPolarDBClusterRead(d *schema.ResourceData, meta interface{}
d.Set("db_revision_version_list", DBRevisionVersionList)
d.Set("target_db_revision_version_code", d.Get("target_db_revision_version_code"))
d.Set("compress_storage", clusterAttribute.CompressStorageMode)
d.Set("hot_standby_cluster", convertPolarDBHotStandbyClusterStatusReadResponse(clusterAttribute.HotStandbyCluster))
d.Set("strict_consistency", clusterAttribute.StrictConsistency)
return nil
}

Expand Down Expand Up @@ -1782,6 +1792,10 @@ func buildPolarDBCreateRequest(d *schema.ResourceData, meta interface{}) (map[st
}
}

if v, ok := d.GetOk("strict_consistency"); ok && v.(string) != "" {
request["StrictConsistency"] = d.Get("strict_consistency").(string)
}

if v, ok := d.GetOk("resource_group_id"); ok && v.(string) != "" {
request["ResourceGroupId"] = v.(string)
}
Expand Down Expand Up @@ -1993,3 +2007,11 @@ func validateMaintainTimeRange(v interface{}, k string) (ws []string, errors []e
}
return
}

func convertPolarDBHotStandbyClusterStatusReadResponse(source string) string {
switch source {
case "StandbyClusterON":
return "ON"
}
return "OFF"
}
108 changes: 107 additions & 1 deletion alicloud/resource_alicloud_polardb_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ func TestAccAliCloudPolarDBClusterSENormalCreate(t *testing.T) {
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"modify_type", "hot_standby_cluster", "proxy_type", "proxy_class", "db_node_num"},
ImportStateVerifyIgnore: []string{"modify_type", "proxy_type", "proxy_class", "db_node_num"},
},
{
Config: testAccConfig(map[string]interface{}{
Expand Down Expand Up @@ -1763,6 +1763,71 @@ func TestAccAliCloudPolarDBCluster_CreateRecoverFromRecyclebin(t *testing.T) {
})
}

func TestAccAliCloudPolarDBCluster_3AZ(t *testing.T) {
var v *polardb.DescribeDBClusterAttributeResponse
name := "tf-testAccPolarDBCluster-3az"
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,
"tde_status": "Disabled",
"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, resourcePolarDBCluster3ZAConfigDependence)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWithRegions(t, false, connectivity.Cluster3AZPolarDBSupportRegions)
},
// 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_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}",
"creation_category": "Normal",
"hot_standby_cluster": "ON",
"strict_consistency": "ON",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"pay_type": "PostPaid",
"creation_category": "Normal",
"hot_standby_cluster": "ON",
"strict_consistency": "ON",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"modify_type", "creation_option", "gdn_id", "source_resource_id", "clone_data_point"},
},
},
})
}

func testAccCheckKeyValueInMapsForPolarDB(ps []map[string]interface{}, propName, key, value string) resource.TestCheckFunc {
return func(s *terraform.State) error {
for _, policy := range ps {
Expand All @@ -1774,6 +1839,47 @@ func testAccCheckKeyValueInMapsForPolarDB(ps []map[string]interface{}, propName,
}
}

func resourcePolarDBCluster3ZAConfigDependence(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 resourcePolarDBClusterXengineConfigDependence(name string) string {
return fmt.Sprintf(`
variable "name" {
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/polardb_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ The following arguments are supported:
-> **NOTE:** Valid values for PolarDB for MySQL Standard Edition: 20 to 32000. It is valid when pay_type are `PrePaid` ,`PostPaid`.
-> **NOTE:** Valid values for PolarDB for MySQL Enterprise Edition: 50 to 100000.It is valid when pay_type is `PrePaid`.
* `storage_pay_type` - (Optional, ForceNew, Computed, Available since v1.210.0) The billing method of the storage. Valid values `Postpaid`, `Prepaid`.
* `hot_standby_cluster` - (Optional, Computed, Available since v1.203.0) Whether to enable the hot standby cluster. Valid values are `ON`, `OFF`.
* `hot_standby_cluster` - (Optional, Computed, ForceNew, Available since v1.203.0) Whether to enable the hot standby cluster. Valid values are `ON`, `OFF`.
* `strict_consistency` - (Optional, Computed, ForceNew, Available since v1.238.0) Whether the cluster has enabled strong data consistency across multiple zones. Valid values are `ON`, `OFF`. Available parameters can refer to the latest docs [CreateDBCluster](https://www.alibabacloud.com/help/en/polardb/latest/createdbcluster-1)
* `serverless_type` - (Optional, Available since v1.204.0) The type of the serverless cluster. Valid values `AgileServerless`, `SteadyServerless`. This parameter is valid only for serverless clusters.
* `serverless_steady_switch` - (Optional, Available since v1.211.1) Serverless steady-state switch. Valid values are `ON`, `OFF`. This parameter is valid only for serverless clusters.
-> **NOTE:** When serverless_steady_switch is `ON` and serverless_type is `SteadyServerless`, parameters `scale_min`, `scale_max`, `scale_ro_num_min` and `scale_ro_num_max` are all required.
Expand Down

0 comments on commit 6ef31d0

Please sign in to comment.