Skip to content

fix(postgresql): [117252443] support params db_major_version create resource #2618

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

Merged
merged 9 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions .changelog/2618.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_postgresql_instance: support params db_major_version create resource
```
36 changes: 23 additions & 13 deletions tencentcloud/services/postgresql/resource_tc_postgresql_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,25 @@ func ResourceTencentCloudPostgresqlInstance() *schema.Resource {
},
"engine_version": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Default: "10.4",
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里去掉 default 会有不兼容变更问题吗

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

如果用户engine_version和db_major_version都不填写 会在代码中手动设置engine_version:10.4

Description: "Version of the postgresql database engine. Valid values: `10.4`, `11.8`, `12.4`.",
Computed: true,
Description: "Version of the postgresql database engine. Valid values: `10.4`, `10.17`, `10.23`, `11.8`, `11.12`, `11.22`, `12.4`, `12.7`, `12.18`, `13.3`, `14.2`, `14.11`, `15.1`, `16.0`.",
},
"db_major_vesion": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Deprecated: "`db_major_vesion` will be deprecated, use `db_major_version` instead.",
ConflictsWith: []string{"db_major_version"},
Description: "PostgreSQL major version number. Valid values: 10, 11, 12, 13. " +
Description: "PostgreSQL major version number. Valid values: 10, 11, 12, 13, 14, 15, 16. " +
"If it is specified, an instance running the latest kernel of PostgreSQL DBMajorVersion will be created.",
},
"db_major_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{"db_major_vesion"},
Description: "PostgreSQL major version number. Valid values: 10, 11, 12, 13. " +
Description: "PostgreSQL major version number. Valid values: 10, 11, 12, 13, 14, 15, 16. " +
"If it is specified, an instance running the latest kernel of PostgreSQL DBMajorVersion will be created.",
},
"db_kernel_version": {
Expand All @@ -101,7 +100,6 @@ func ResourceTencentCloudPostgresqlInstance() *schema.Resource {
Description: "PostgreSQL kernel version number. " +
"If it is specified, an instance running kernel DBKernelVersion will be created. It supports updating the minor kernel version immediately.",
},

"vpc_id": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -344,9 +342,9 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i

// the sdk asks to set value with 1 when paytype is postpaid

var instanceId, specVersion, specCode string
var instanceId, majorVersion, specVersion, specCode string
var outErr, inErr error
var allowVersion, allowSpec []string
var allowMajorVersion, allowSpecVersion, allowSpec []string

var (
dbMajorVersion = ""
Expand Down Expand Up @@ -411,10 +409,16 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
return tccommon.RetryError(inErr)
}
for _, info := range speccodes {
if !tccommon.IsContains(allowVersion, *info.Version) {
allowVersion = append(allowVersion, *info.Version)
if !tccommon.IsContains(allowSpecVersion, *info.Version) {
allowSpecVersion = append(allowSpecVersion, *info.Version)
}

if !tccommon.IsContains(allowMajorVersion, *info.MajorVersion) {
allowMajorVersion = append(allowMajorVersion, *info.MajorVersion)
}
if *info.Version == dbVersion {

if *info.MajorVersion == dbMajorVersion || *info.Version == dbVersion {
majorVersion = *info.MajorVersion
specVersion = *info.Version
specString := fmt.Sprintf("(%d, %d)", int(*info.Memory)/1024, int(*info.Cpu))
if !tccommon.IsContains(allowSpec, specString) {
Expand All @@ -438,8 +442,8 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
return outErr
}

if specVersion == "" {
return fmt.Errorf(`The "engine_version" value: "%s" is invalid, Valid values are one of: "%s"`, dbVersion, strings.Join(allowVersion, `", "`))
if majorVersion == "" && specVersion == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

majorVersion 和 specVersion 参数必须传一个是吗

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

必须传一个或者都传入

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

majorVersion和specVersion参数主要对应的是客户传入的engine_version和db_major_version

return fmt.Errorf(`The "db_major_version" value: "%s" is invalid, Valid values are one of: "%s", The "engine_version" value: "%s" is invalid, Valid values are one of: "%s"`, dbMajorVersion, strings.Join(allowMajorVersion, `", "`), dbVersion, strings.Join(allowSpecVersion, `", "`))
}

if specCode == "" {
Expand Down Expand Up @@ -1126,13 +1130,19 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i
paramEntrys["max_standby_streaming_delay"] = strconv.Itoa(v.(int))
}
}

if d.HasChange("db_major_vesion") || d.HasChange("db_major_version") {
return fmt.Errorf("Not support change db major version.")
}

if d.HasChange("engine_version") {
return fmt.Errorf("Not support change engine_version.")
}

if d.HasChange("need_support_tde") || d.HasChange("kms_key_id") || d.HasChange("kms_region") {
return fmt.Errorf("Not support change params contact with data transparent encryption.")
}

if len(paramEntrys) != 0 {
outErr = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
inErr := postgresqlService.ModifyPgParams(ctx, instanceId, paramEntrys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ resource "tencentcloud_postgresql_instance" "foo" {
charge_type = "POSTPAID_BY_HOUR"
vpc_id = tencentcloud_vpc.vpc.id
subnet_id = tencentcloud_subnet.subnet.id
engine_version = "10.4"
db_major_version = "10"
root_user = "root123"
root_password = "Root123$"
charset = "UTF8"
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/postgresql_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ resource "tencentcloud_postgresql_instance" "foo" {
charge_type = "POSTPAID_BY_HOUR"
vpc_id = tencentcloud_vpc.vpc.id
subnet_id = tencentcloud_subnet.subnet.id
engine_version = "10.4"
db_major_version = "10"
root_user = "root123"
root_password = "Root123$"
charset = "UTF8"
Expand Down Expand Up @@ -196,10 +196,10 @@ The following arguments are supported:
* `charset` - (Optional, String, ForceNew) Charset of the root account. Valid values are `UTF8`,`LATIN1`.
* `cpu` - (Optional, Int) Number of CPU cores. Allowed value must be equal `cpu` that data source `tencentcloud_postgresql_specinfos` provides.
* `db_kernel_version` - (Optional, String) PostgreSQL kernel version number. If it is specified, an instance running kernel DBKernelVersion will be created. It supports updating the minor kernel version immediately.
* `db_major_version` - (Optional, String) PostgreSQL major version number. Valid values: 10, 11, 12, 13. If it is specified, an instance running the latest kernel of PostgreSQL DBMajorVersion will be created.
* `db_major_vesion` - (Optional, String, **Deprecated**) `db_major_vesion` will be deprecated, use `db_major_version` instead. PostgreSQL major version number. Valid values: 10, 11, 12, 13. If it is specified, an instance running the latest kernel of PostgreSQL DBMajorVersion will be created.
* `db_major_version` - (Optional, String) PostgreSQL major version number. Valid values: 10, 11, 12, 13, 14, 15, 16. If it is specified, an instance running the latest kernel of PostgreSQL DBMajorVersion will be created.
* `db_major_vesion` - (Optional, String, **Deprecated**) `db_major_vesion` will be deprecated, use `db_major_version` instead. PostgreSQL major version number. Valid values: 10, 11, 12, 13, 14, 15, 16. If it is specified, an instance running the latest kernel of PostgreSQL DBMajorVersion will be created.
* `db_node_set` - (Optional, Set) Specify instance node info for disaster migration.
* `engine_version` - (Optional, String, ForceNew) Version of the postgresql database engine. Valid values: `10.4`, `11.8`, `12.4`.
* `engine_version` - (Optional, String) Version of the postgresql database engine. Valid values: `10.4`, `10.17`, `10.23`, `11.8`, `11.12`, `11.22`, `12.4`, `12.7`, `12.18`, `13.3`, `14.2`, `14.11`, `15.1`, `16.0`.
* `kms_key_id` - (Optional, String) KeyId of the custom key.
* `kms_region` - (Optional, String) Region of the custom key.
* `max_standby_archive_delay` - (Optional, Int) max_standby_archive_delay applies when WAL data is being read from WAL archive (and is therefore not current). Units are milliseconds if not specified.
Expand Down
Loading