Skip to content

Commit

Permalink
feat(postgresql): [120953562]support pgsql time window
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmkn committed Jan 9, 2025
1 parent 1d9b151 commit d30b00a
Show file tree
Hide file tree
Showing 15 changed files with 666 additions and 7 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1034
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1046
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1073
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1078
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1053
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1058
Expand All @@ -70,7 +70,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.1066
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mps v1.0.853
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.1038
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.1010
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.1078
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.1038
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.1008
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1072 h1:zoo
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1072/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1073 h1:AWEtNWRQwIh9xJVarhhTB3h1CglBV5a0pMI9pvQvZ60=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1073/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1078 h1:6dDx6ePLVKl39noLeqVO22A1xPoTRXcVkQ3rW9WlnXA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1078/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
Expand Down Expand Up @@ -1019,6 +1021,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.1038
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.1038/go.mod h1:ZcauOIKWXstNwe6IlD3iBBxzljEWdQjZbTc6PfwsPxQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.1010 h1:lx554ZfB++mge+/Gk7LnDUI5Dwm9r+DgGNN9C/DqhE4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.1010/go.mod h1:GGhAf2ehV2/jwKf3Sezr2x/soJ3nDuefJFlcoZnlflA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.1078 h1:kTV4aJ8RcA7fv1vrxSw4wCcGJeur5ZFm+TZr/LB8kkI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.1078/go.mod h1:jssFHFM6jTndhOiW0bGKJ8J6QymvWbKKSTCfuOaZw18=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.1038 h1:4rzyVxkDB27v73jDXPr5eGAwjN859R7SsqniCt+46XE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.1038/go.mod h1:TAHhxxDVV36Pe4P4Gel3dgX4kHUfQO7f27GzRf8DAro=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.762 h1:rZDKucVVtTnmnbZFDyh6t47dHswkb2oSuOxOHTTkygA=
Expand Down
1 change: 1 addition & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@ func Provider() *schema.Provider {
"tencentcloud_postgresql_account_privileges_operation": postgresql.ResourceTencentCloudPostgresqlAccountPrivilegesOperation(),
"tencentcloud_postgresql_apply_parameter_template_operation": postgresql.ResourceTencentCloudPostgresqlApplyParameterTemplateOperation(),
"tencentcloud_postgresql_clone_db_instance": postgresql.ResourceTencentCloudPostgresqlCloneDbInstance(),
"tencentcloud_postgresql_time_window": postgresql.ResourceTencentCloudPostgresqlTimeWindow(),
"tencentcloud_sqlserver_instance": sqlserver.ResourceTencentCloudSqlserverInstance(),
"tencentcloud_sqlserver_db": sqlserver.ResourceTencentCloudSqlserverDB(),
"tencentcloud_sqlserver_account": sqlserver.ResourceTencentCloudSqlserverAccount(),
Expand Down
1 change: 1 addition & 0 deletions tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ TencentDB for PostgreSQL(PostgreSQL)
tencentcloud_postgresql_account
tencentcloud_postgresql_apply_parameter_template_operation
tencentcloud_postgresql_clone_db_instance
tencentcloud_postgresql_time_window

TencentDB for Redis(crs)
Data Source
Expand Down
177 changes: 177 additions & 0 deletions tencentcloud/services/postgresql/resource_tc_postgresql_time_window.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Provides a resource to create a postgres postgresql_time_window

Example Usage

```hcl
resource "tencentcloud_postgresql_time_window" "postgresql_time_window" {
db_instance_id = "postgres-45b0vlmr"
maintain_duration = 2
maintain_start_time = "04:00"
maintain_week_days = [
"friday",
"monday",
"saturday",
"sunday",
"thursday",
"tuesday",
"wednesday",
]
}
```

Import

postgres postgresql_time_window can be imported using the id, e.g.

```
terraform import tencentcloud_postgresql_time_window.postgresql_time_window instance_id
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package postgresql
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package postgresql_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
)

func TestAccTencentCloudPostgresqlTimeWindowResource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Config: testAccPostgresqlTimeWindow,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("tencentcloud_postgresql_time_window.postgresql_time_window", "id"),
resource.TestCheckResourceAttr("tencentcloud_postgresql_time_window.postgresql_time_window", "maintain_duration", "2"),
resource.TestCheckResourceAttr("tencentcloud_postgresql_time_window.postgresql_time_window", "maintain_start_time", "04:00"),
resource.TestCheckResourceAttr("tencentcloud_postgresql_time_window.postgresql_time_window", "maintain_week_days.#", "7"),
),
},
{
ResourceName: "tencentcloud_postgresql_time_window.postgresql_time_window",
ImportState: true,
ImportStateVerify: true,
},

{
Config: testAccPostgresqlTimeWindowUp,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("tencentcloud_postgresql_time_window.postgresql_time_window", "id"),
resource.TestCheckResourceAttr("tencentcloud_postgresql_time_window.postgresql_time_window", "maintain_duration", "3"),
resource.TestCheckResourceAttr("tencentcloud_postgresql_time_window.postgresql_time_window", "maintain_start_time", "05:00"),
resource.TestCheckResourceAttr("tencentcloud_postgresql_time_window.postgresql_time_window", "maintain_week_days.#", "6"),
),
},
},
})
}

const testAccPostgresqlTimeWindow = testAccPostgresqlInstance + `
resource "tencentcloud_postgresql_time_window" "postgresql_time_window" {
db_instance_id = tencentcloud_postgresql_instance.test.id
maintain_duration = 2
maintain_start_time = "04:00"
maintain_week_days = [
"friday",
"monday",
"saturday",
"sunday",
"thursday",
"tuesday",
"wednesday",
]
}
`

const testAccPostgresqlTimeWindowUp = testAccPostgresqlInstance + `
resource "tencentcloud_postgresql_time_window" "postgresql_time_window" {
db_instance_id = tencentcloud_postgresql_instance.test.id
maintain_duration = 3
maintain_start_time = "05:00"
maintain_week_days = [
"friday",
"monday",
"saturday",
"sunday",
"thursday",
"tuesday",
]
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
postgresql "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres/v20170312"
postgresv20170312 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres/v20170312"

"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
Expand Down Expand Up @@ -2186,3 +2187,33 @@ func (me *PostgresqlService) DescribePostgresqlDedicatedClustersByFilter(ctx con
ret = response.Response.DedicatedClusterSet
return
}

func (me *PostgresqlService) DescribePostgresqlTimeWindowById(ctx context.Context, dBInstanceId string) (ret *postgresv20170312.DescribeMaintainTimeWindowResponseParams, errRet error) {
logId := tccommon.GetLogId(ctx)

request := postgresv20170312.NewDescribeMaintainTimeWindowRequest()
response := postgresv20170312.NewDescribeMaintainTimeWindowResponse()
request.DBInstanceId = helper.String(dBInstanceId)

defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
}
}()

ratelimit.Check(request.GetAction())

errRet = resource.Retry(3*tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := me.client.UsePostgresV20170312Client().DescribeMaintainTimeWindow(request)
if e != nil {
return tccommon.RetryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
}
response = result
return nil
})

ret = response.Response
return
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d30b00a

Please sign in to comment.