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

resource/alicloud_db_instance: add new attributes:bursting_enabled and modify sql_collector_config_value #7840

Closed
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
22 changes: 21 additions & 1 deletion alicloud/resource_alicloud_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,12 @@ func resourceAliCloudDBInstance() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: IntInSlice([]int{30, 180, 365, 1095, 1825}),
Default: 30,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么删除默认值,并加上压制函数?

Copy link
Contributor Author

@chaitiansheng0524 chaitiansheng0524 Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为DescribeSQLCollectorRetention接口的返回值有改动,之前没这个参数,现在有该参数的返回值了,导致线上存量实例产生了diff,所以要删除默认值和加上压制函数

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if v, ok := d.GetOk("sql_collector_status"); ok && strings.ToLower(v.(string)) == "enabled" {
return false
}
return true
},
},
"resource_group_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -638,6 +643,10 @@ func resourceAliCloudDBInstance() *schema.Resource {
return d.Get("engine").(string) != "SQLServer"
},
},
"bursting_enabled": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议显式设置默认值,在tf中,针对bool类型的字段,除非后端返回的是true,否则默认值是false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该参数未开启时会默认为false 记得这种情况好像会影响创建实例吧
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么意思?如果集成bursting_enabled字段,资源都必须给他赋值为true,才能让实例创建成功吗?如果是,影响存量资源。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已去掉显式默认值设置

Type: schema.TypeBool,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -1455,6 +1464,13 @@ func resourceAliCloudDBInstanceUpdate(d *schema.ResourceData, meta interface{})
}
request["DBInstanceStorage"] = d.Get("instance_storage")

if d.HasChange("bursting_enabled") {
update = true
}
if v, ok := d.GetOkExists("bursting_enabled"); ok {
request["BurstingEnabled"] = v
}

if d.HasChange("serverless_config") {
update = true
if v, ok := d.GetOk("serverless_config"); ok {
Expand Down Expand Up @@ -1814,6 +1830,7 @@ func resourceAliCloudDBInstanceRead(d *schema.ResourceData, meta interface{}) er
d.Set("zone_id", instance["ZoneId"])
d.Set("status", instance["DBInstanceStatus"])
d.Set("create_time", instance["CreationTime"])
d.Set("bursting_enabled", instance["BurstingEnabled"])
d.Set("pg_bouncer_enabled", instance["PGBouncerEnabled"])

// MySQL Serverless instance query PayType return SERVERLESS, need to be consistent with the participant.
Expand Down Expand Up @@ -2075,6 +2092,9 @@ func buildDBCreateRequest(d *schema.ResourceData, meta interface{}) (map[string]
if v, ok := d.GetOk("port"); ok && v.(string) != "" {
request["Port"] = v
}
if v, ok := d.GetOkExists("bursting_enabled"); ok {
request["BurstingEnabled"] = v
}

if request["Engine"] == "MySQL" || request["Engine"] == "PostgreSQL" || request["Engine"] == "SQLServer" {
if v, ok := d.GetOk("role_arn"); ok && v.(string) != "" {
Expand Down
25 changes: 23 additions & 2 deletions alicloud/resource_alicloud_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ func TestAccAliCloudRdsDBInstance_Mysql_5_7_HighAvailabilityInstance(t *testing.
Config: testAccConfig(map[string]interface{}{
"engine": "MySQL",
"engine_version": "5.7",
"instance_type": "${data.alicloud_db_instance_classes.default.instance_classes.1.instance_class}",
"instance_type": "rds.mysql.t1.small",
"instance_storage": "${data.alicloud_db_instance_classes.default.instance_classes.1.storage_range.min}",
"instance_charge_type": "Postpaid",
"instance_name": "${var.name}",
Expand Down Expand Up @@ -1382,7 +1382,6 @@ func TestAccAliCloudRdsDBInstance_PostgreSQL_12_0(t *testing.T) {
"vswitch_id": "${local.vswitch_id}",
"security_group_ids": []string{},
"monitoring_period": "60",
"encryption_key": "${alicloud_kms_key.default.id}",
"category": "HighAvailability",
"db_instance_storage_type": "cloud_essd2",
"connection_string_prefix": connectionStringPrefixSecond,
Expand Down Expand Up @@ -3925,6 +3924,7 @@ func TestAccAliCloudRdsDBInstanceMysql_general_essd(t *testing.T) {
"instance_name": "${var.name}",
"vswitch_id": "${data.alicloud_vswitches.default.ids.0}",
"db_instance_storage_type": "general_essd",
"bursting_enabled": "true",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
Expand All @@ -3936,6 +3936,27 @@ func TestAccAliCloudRdsDBInstanceMysql_general_essd(t *testing.T) {
"instance_name": name,
"db_instance_storage_type": "general_essd",
"monitoring_period": CHECKSET,
"bursting_enabled": CHECKSET,
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"bursting_enabled": "false",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"bursting_enabled": "false",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"bursting_enabled": "true",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"bursting_enabled": "true",
}),
),
},
Expand Down
5 changes: 4 additions & 1 deletion website/docs/r/db_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,10 @@ The following arguments are supported:
-> **NOTE:** This parameter is not required when you create an instance that runs MySQL, PostgreSQL, or SQL Server. You need to only specify the RoleARN parameter to create an instance that has cloud disk encryption enabled by using the obtained key ID.
You can configure RAM authorization to require a RAM user to enable cloud disk encryption when the RAM user is used to create an instance. If cloud disk encryption is disabled during the instance creation, the creation operation fails. To complete the configuration, you can attach the following policy to the RAM user: {"Version":"1","Statement":[{"Effect":"Deny","Action":"rds:CreateDBInstance","Resource":"*","Condition":{"StringEquals":{"rds:DiskEncryptionRequired":"false"}}}]}
* `direction` - (Optional, Available since v1.209.1) The instance configuration type. Valid values: ["Up", "Down", "TempUpgrade", "Serverless"]

* `bursting_enabled` - (Optional, Available since 1.241.0) Specifies whether to enable the I/O burst feature of general
ESSDs. Valid values:
- true
- false

* `node_id` - (Optional, Available since v1.213.1) The globally unique identifier (GUID) of the secondary instance. You can call the DescribeDBInstanceHAConfig operation to query the GUID of the secondary instance.
* `force` - (Optional, ForceNew, Available since v1.213.1) Specifies whether to enable forcible switching. Valid values:
Expand Down
Loading