Skip to content

fix(postgresq): [124966207] tencentcloud_postgresql_clone_db_instance optmize doc and code logic #3414

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 3 commits into from
Jun 20, 2025
Merged
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
3 changes: 3 additions & 0 deletions .changelog/3414.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_postgresql_clone_db_instance: optmize doc and code logic
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Code generated by iacg; DO NOT EDIT.
package postgresql

import (
Expand Down Expand Up @@ -110,11 +109,13 @@ func ResourceTencentCloudPostgresqlCloneDbInstance() *schema.Resource {
"tag_key": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Tag key.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

为什么加forcenew?

},
"tag_value": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Tag value.",
},
},
Expand All @@ -131,16 +132,19 @@ func ResourceTencentCloudPostgresqlCloneDbInstance() *schema.Resource {
"role": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Node type. Valid values:\n`Primary`;\n`Standby`.",
},
"zone": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "AZ where the node resides, such as ap-guangzhou-1.",
},
"dedicated_cluster_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Dedicated cluster ID.",
},
},
Expand Down Expand Up @@ -182,14 +186,9 @@ func resourceTencentCloudPostgresqlCloneDbInstanceCreate(d *schema.ResourceData,
defer tccommon.LogElapsed("resource.tencentcloud_postgresql_clone_db_instance.create")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)

ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)

var (
dBInstanceId string
)
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
request = postgresv20170312.NewCloneDBInstanceRequest()
response = postgresv20170312.NewCloneDBInstanceResponse()
)
Expand Down Expand Up @@ -249,9 +248,11 @@ func resourceTencentCloudPostgresqlCloneDbInstanceCreate(d *schema.ResourceData,
if v, ok := tagListMap["tag_key"]; ok {
tag.TagKey = helper.String(v.(string))
}

if v, ok := tagListMap["tag_value"]; ok {
tag.TagValue = helper.String(v.(string))
}

request.TagList = append(request.TagList, &tag)
}
}
Expand All @@ -263,12 +264,15 @@ func resourceTencentCloudPostgresqlCloneDbInstanceCreate(d *schema.ResourceData,
if v, ok := dBNodeSetMap["role"]; ok {
dBNode.Role = helper.String(v.(string))
}

if v, ok := dBNodeSetMap["zone"]; ok {
dBNode.Zone = helper.String(v.(string))
}

if v, ok := dBNodeSetMap["dedicated_cluster_id"]; ok {
dBNode.DedicatedClusterId = helper.String(v.(string))
}

request.DBNodeSet = append(request.DBNodeSet, &dBNode)
}
}
Expand Down Expand Up @@ -296,16 +300,26 @@ func resourceTencentCloudPostgresqlCloneDbInstanceCreate(d *schema.ResourceData,
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}

if result == nil || result.Response == nil {
return resource.NonRetryableError(fmt.Errorf("Create postgresql clone db instance failed, Response is nil."))
}

response = result
return nil
})

if err != nil {
log.Printf("[CRITAL]%s create postgresql clone db instance failed, reason:%+v", logId, err)
return err
}

dBInstanceId = *response.Response.DBInstanceId
if response.Response.DBInstanceId == nil {
return fmt.Errorf("DBInstanceId is nil.")
}

// wait
dBInstanceId := *response.Response.DBInstanceId
if _, err := (&resource.StateChangeConf{
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
Expand All @@ -316,8 +330,8 @@ func resourceTencentCloudPostgresqlCloneDbInstanceCreate(d *schema.ResourceData,
}).WaitForStateContext(ctx); err != nil {
return err
}
d.SetId(dBInstanceId)

d.SetId(dBInstanceId)
return resourceTencentCloudPostgresqlCloneDbInstanceRead(d, meta)
}

Expand All @@ -342,23 +356,27 @@ func resourcePostgresqlCloneDbInstanceCreateStateRefreshFunc_0_0(ctx context.Con
if meta == nil {
return nil, "", fmt.Errorf("resource data can not be nil")
}

if req == nil {
d := tccommon.ResourceDataFromContext(ctx)
if d == nil {
return nil, "", fmt.Errorf("resource data can not be nil")
}

_ = d
req = postgresv20170312.NewDescribeDBInstanceAttributeRequest()
req.DBInstanceId = helper.String(dBInstanceId)

}

resp, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UsePostgresV20170312Client().DescribeDBInstanceAttributeWithContext(ctx, req)
if err != nil {
return nil, "", err
}

if resp == nil || resp.Response == nil {
return nil, "", nil
}

state := fmt.Sprintf("%v", *resp.Response.DBInstance.DBInstanceStatus)
return resp.Response, state, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Provides a resource to create a postgresql clone db instance

Example Usage

Clone db instance by `recovery_target_time`
Clone db instance by recovery_target_time

```hcl
resource "tencentcloud_postgresql_clone_db_instance" "example" {
Expand Down Expand Up @@ -30,12 +30,12 @@ resource "tencentcloud_postgresql_clone_db_instance" "example" {

tag_list {
tag_key = "createBy"
tag_value = "terraform"
tag_value = "Terraform"
}
}
```

Clone db instance by `backup_set_id`
Clone db instance by backup_set_id

```hcl
data "tencentcloud_postgresql_base_backups" "base_backups" {
Expand Down Expand Up @@ -73,7 +73,7 @@ resource "tencentcloud_postgresql_clone_db_instance" "example" {

tag_list {
tag_key = "createBy"
tag_value = "terraform"
tag_value = "Terraform"
}
}
```
Expand Down Expand Up @@ -108,7 +108,7 @@ resource "tencentcloud_postgresql_clone_db_instance" "example" {

tag_list {
tag_key = "createBy"
tag_value = "terraform"
tag_value = "Terraform"
}
}
```
20 changes: 11 additions & 9 deletions website/docs/r/postgresql_clone_db_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Provides a resource to create a postgresql clone db instance

## Example Usage

### Clone db instance by recovery_target_time

```hcl
resource "tencentcloud_postgresql_clone_db_instance" "example" {
db_instance_id = "postgres-evsqpyap"
Expand All @@ -39,12 +41,12 @@ resource "tencentcloud_postgresql_clone_db_instance" "example" {

tag_list {
tag_key = "createBy"
tag_value = "terraform"
tag_value = "Terraform"
}
}
```


### Clone db instance by backup_set_id

```hcl
data "tencentcloud_postgresql_base_backups" "base_backups" {
Expand Down Expand Up @@ -82,7 +84,7 @@ resource "tencentcloud_postgresql_clone_db_instance" "example" {

tag_list {
tag_key = "createBy"
tag_value = "terraform"
tag_value = "Terraform"
}
}
```
Expand Down Expand Up @@ -117,7 +119,7 @@ resource "tencentcloud_postgresql_clone_db_instance" "example" {

tag_list {
tag_key = "createBy"
tag_value = "terraform"
tag_value = "Terraform"
}
}
```
Expand Down Expand Up @@ -163,16 +165,16 @@ Default value for the read-only instance: Async.

The `db_node_set` object supports the following:

* `role` - (Required, String) Node type. Valid values:
* `role` - (Required, String, ForceNew) Node type. Valid values:
`Primary`;
`Standby`.
* `zone` - (Required, String) AZ where the node resides, such as ap-guangzhou-1.
* `dedicated_cluster_id` - (Optional, String) Dedicated cluster ID.
* `zone` - (Required, String, ForceNew) AZ where the node resides, such as ap-guangzhou-1.
* `dedicated_cluster_id` - (Optional, String, ForceNew) Dedicated cluster ID.

The `tag_list` object supports the following:

* `tag_key` - (Required, String) Tag key.
* `tag_value` - (Required, String) Tag value.
* `tag_key` - (Required, String, ForceNew) Tag key.
* `tag_value` - (Required, String, ForceNew) Tag value.

## Attributes Reference

Expand Down
Loading