From 5c14a9ae1f623e7f9431b1ba5c6ad2169e9953d5 Mon Sep 17 00:00:00 2001 From: hellertang Date: Thu, 23 May 2024 18:29:54 +0800 Subject: [PATCH 1/2] support change pg password regardless user --- .../services/postgresql/resource_tc_postgresql_instance.go | 2 +- .../postgresql/resource_tc_postgresql_instance_test.go | 4 +++- .../services/postgresql/service_tencentcloud_postgresql.go | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tencentcloud/services/postgresql/resource_tc_postgresql_instance.go b/tencentcloud/services/postgresql/resource_tc_postgresql_instance.go index 5989b42b4d..fa3ba7fd39 100644 --- a/tencentcloud/services/postgresql/resource_tc_postgresql_instance.go +++ b/tencentcloud/services/postgresql/resource_tc_postgresql_instance.go @@ -944,7 +944,7 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i if d.HasChange("root_password") { // to avoid other updating process conflicts with updating password, set the password updating with the last step, there is no way to figure out whether changing password is done outErr = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { - inErr = postgresqlService.SetPostgresqlInstanceRootPassword(ctx, instanceId, d.Get("root_password").(string)) + inErr = postgresqlService.SetPostgresqlInstanceRootPassword(ctx, instanceId, d.Get("root_user").(string), d.Get("root_password").(string)) if inErr != nil { return tccommon.RetryError(inErr) } diff --git a/tencentcloud/services/postgresql/resource_tc_postgresql_instance_test.go b/tencentcloud/services/postgresql/resource_tc_postgresql_instance_test.go index f31c008998..50791f5332 100644 --- a/tencentcloud/services/postgresql/resource_tc_postgresql_instance_test.go +++ b/tencentcloud/services/postgresql/resource_tc_postgresql_instance_test.go @@ -676,6 +676,7 @@ resource "tencentcloud_postgresql_instance" "test" { vpc_id = tencentcloud_vpc.vpc.id subnet_id = tencentcloud_subnet.subnet.id engine_version = "13.3" + root_username = "tf-user" root_password = "t1qaA2k1wgvfa3?ZZZ" charset = "LATIN1" memory = 4 @@ -711,7 +712,8 @@ resource "tencentcloud_postgresql_instance" "test" { vpc_id = tencentcloud_vpc.vpc.id subnet_id = tencentcloud_subnet.subnet.id engine_version = "13.3" - root_password = "t1qaA2k1wgvfa3?ZZZ" + root_username = "tf-user" + root_password = "t1qaA2k1wgvfa3?ZZZ3daw" charset = "LATIN1" memory = 8 cpu = 4 diff --git a/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go b/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go index bda6927b55..7fde1882ef 100644 --- a/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go +++ b/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go @@ -623,7 +623,7 @@ func (me *PostgresqlService) DeletePostgresqlInstance(ctx context.Context, insta return err } -func (me *PostgresqlService) SetPostgresqlInstanceRootPassword(ctx context.Context, instanceId string, password string) (errRet error) { +func (me *PostgresqlService) SetPostgresqlInstanceRootPassword(ctx context.Context, instanceId string, user string, password string) (errRet error) { logId := tccommon.GetLogId(ctx) request := postgresql.NewResetAccountPasswordRequest() defer func() { @@ -632,7 +632,7 @@ func (me *PostgresqlService) SetPostgresqlInstanceRootPassword(ctx context.Conte } }() request.DBInstanceId = &instanceId - request.UserName = helper.String("root") + request.UserName = &user request.Password = &password ratelimit.Check(request.GetAction()) From cf23a0357705247d49a13f951df2d2dd38ac9886 Mon Sep 17 00:00:00 2001 From: hellertang Date: Thu, 23 May 2024 18:34:23 +0800 Subject: [PATCH 2/2] add changelog --- .changelog/2652.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2652.txt diff --git a/.changelog/2652.txt b/.changelog/2652.txt new file mode 100644 index 0000000000..c7f0528c03 --- /dev/null +++ b/.changelog/2652.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +tencentcloud_postgresql_instance: support change pg password regardless user +```