From 20247fd191c108d72251c83ec7f73dfac77148dc Mon Sep 17 00:00:00 2001 From: mikatong Date: Mon, 24 Mar 2025 17:54:41 +0800 Subject: [PATCH 1/7] add resource --- tencentcloud/provider.go | 4 + tencentcloud/provider.md | 4 + .../cdwpg/resource_tc_cdwpg_account.go | 160 ++++++++++++ .../cdwpg/resource_tc_cdwpg_account.md | 19 ++ .../cdwpg/resource_tc_cdwpg_account_test.go | 36 +++ .../resource_tc_cdwpg_restart_instance.go | 129 ++++++++++ .../resource_tc_cdwpg_restart_instance.md | 10 + ...resource_tc_cdwpg_restart_instance_test.go | 30 +++ .../resource_tc_cdwpg_upgrade_instance.go | 105 ++++++++ .../resource_tc_cdwpg_upgrade_instance.md | 10 + ...resource_tc_cdwpg_upgrade_instance_test.go | 32 +++ .../cdwpg/resource_tc_cdwpg_userhba.go | 231 ++++++++++++++++++ .../cdwpg/resource_tc_cdwpg_userhba.md | 24 ++ .../cdwpg/resource_tc_cdwpg_userhba_test.go | 41 ++++ .../cdwpg/service_tencentcloud_cdwpg.go | 54 ++++ website/docs/r/cdwpg_account.html.markdown | 47 ++++ .../r/cdwpg_restart_instance.html.markdown | 38 +++ .../r/cdwpg_upgrade_instance.html.markdown | 37 +++ website/docs/r/cdwpg_userhba.html.markdown | 60 +++++ website/tencentcloud.erb | 12 + 20 files changed, 1083 insertions(+) create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_account.go create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_account.md create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_account_test.go create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance.go create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance.md create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance_test.go create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.go create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.md create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance_test.go create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba.go create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba.md create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba_test.go create mode 100644 website/docs/r/cdwpg_account.html.markdown create mode 100644 website/docs/r/cdwpg_restart_instance.html.markdown create mode 100644 website/docs/r/cdwpg_upgrade_instance.html.markdown create mode 100644 website/docs/r/cdwpg_userhba.html.markdown diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 93b834f2a6..850872e902 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -2224,6 +2224,10 @@ func Provider() *schema.Provider { "tencentcloud_bi_embed_interval_apply": bi.ResourceTencentCloudBiEmbedIntervalApply(), "tencentcloud_cdwpg_instance": cdwpg.ResourceTencentCloudCdwpgInstance(), "tencentcloud_cdwpg_dbconfig": cdwpg.ResourceTencentCloudCdwpgDbconfig(), + "tencentcloud_cdwpg_account": cdwpg.ResourceTencentCloudCdwpgAccount(), + "tencentcloud_cdwpg_restart_instance": cdwpg.ResourceTencentCloudCdwpgRestartInstance(), + "tencentcloud_cdwpg_upgrade_instance": cdwpg.ResourceTencentCloudCdwpgUpgradeInstance(), + "tencentcloud_cdwpg_userhba": cdwpg.ResourceTencentCloudCdwpgUserhba(), "tencentcloud_clickhouse_keyval_config": cdwch.ResourceTencentCloudClickhouseKeyvalConfig(), "tencentcloud_clickhouse_xml_config": cdwch.ResourceTencentCloudClickhouseXmlConfig(), "tencentcloud_clb_target_group_attachments": clb.ResourceTencentCloudClbTargetGroupAttachments(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index db631f71bf..db0de6b1d5 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -2253,6 +2253,10 @@ tencentcloud_cdwpg_nodes Resource tencentcloud_cdwpg_instance tencentcloud_cdwpg_dbconfig +tencentcloud_cdwpg_account +tencentcloud_cdwpg_restart_instance +tencentcloud_cdwpg_upgrade_instance +tencentcloud_cdwpg_userhba CSIP Resource diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.go new file mode 100644 index 0000000000..8547544962 --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.go @@ -0,0 +1,160 @@ +package cdwpg + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + cdwpgv20201230 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwpg/v20201230" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudCdwpgAccount() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudCdwpgAccountCreate, + Read: resourceTencentCloudCdwpgAccountRead, + Update: resourceTencentCloudCdwpgAccountUpdate, + Delete: resourceTencentCloudCdwpgAccountDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Instance id.", + }, + + "user_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Username.", + }, + + "new_password": { + Type: schema.TypeString, + Required: true, + Sensitive: true, + Description: "New password.", + }, + }, + } +} + +func resourceTencentCloudCdwpgAccountCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.create")() + defer tccommon.InconsistentCheck(d, meta)() + + instanceId := d.Get("instance_id").(string) + userName := d.Get("user_name").(string) + + d.SetId(strings.Join([]string{instanceId, userName}, tccommon.FILED_SP)) + + return resourceTencentCloudCdwpgAccountUpdate(d, meta) +} + +func resourceTencentCloudCdwpgAccountRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.read")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + service := CdwpgService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + instanceId := idSplit[0] + userName := idSplit[1] + + respData, err := service.DescribeCdwpgAccountById(ctx, instanceId) + if err != nil { + return err + } + + if respData == nil { + d.SetId("") + log.Printf("[WARN]%s resource `cdwpg_account` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil + } + if respData.InstanceId != nil { + _ = d.Set("instance_id", respData.InstanceId) + } + + if respData.UserName != nil { + _ = d.Set("user_name", respData.UserName) + } + + _ = userName + return nil +} + +func resourceTencentCloudCdwpgAccountUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.update")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + instanceId := idSplit[0] + userName := idSplit[1] + + needChange := false + mutableArgs := []string{"new_password"} + for _, v := range mutableArgs { + if d.HasChange(v) { + needChange = true + break + } + } + + if needChange { + request := cdwpgv20201230.NewResetAccountPasswordRequest() + + request.InstanceId = helper.String(instanceId) + + request.UserName = helper.String(userName) + + if v, ok := d.GetOk("new_password"); ok { + request.NewPassword = helper.String(v.(string)) + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCdwpgV20201230Client().ResetAccountPasswordWithContext(ctx, 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(), result.ToJsonString()) + } + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s update cdwpg account failed, reason:%+v", logId, err) + return err + } + } + + return resourceTencentCloudCdwpgAccountRead(d, meta) +} + +func resourceTencentCloudCdwpgAccountDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.md b/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.md new file mode 100644 index 0000000000..44f6a37df0 --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.md @@ -0,0 +1,19 @@ +Provides a resource to create a cdwpg cdwpg_account + +Example Usage + +```hcl +resource "tencentcloud_cdwpg_account" "cdwpg_account" { + instance_id = "cdwpg-zpiemnyd" + user_name = "dbadmin" + new_password = "testpassword" +} +``` + +Import + +cdwpg cdwpg_account can be imported using the id, e.g. + +``` +terraform import tencentcloud_cdwpg_account.cdwpg_account cdwpg_account_id +``` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_account_test.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_account_test.go new file mode 100644 index 0000000000..d456a58307 --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_account_test.go @@ -0,0 +1,36 @@ +package cdwpg_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudCdwpgAccountResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccCdwpgAccount, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_account.cdwpg_account", "id")), + }, { + ResourceName: "tencentcloud_cdwpg_account.cdwpg_account", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"new_password"}, + }}, + }) +} + +const testAccCdwpgAccount = ` +resource "tencentcloud_cdwpg_account" "cdwpg_account" { + instance_id = "cdwpg-zpiemnyd" + user_name = "dbadmin" + new_password = "testpassword" +} +` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance.go new file mode 100644 index 0000000000..22fbddf26f --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance.go @@ -0,0 +1,129 @@ +package cdwpg + +import ( + "context" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + cdwpgv20201230 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwpg/v20201230" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudCdwpgRestartInstance() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudCdwpgRestartInstanceCreate, + Read: resourceTencentCloudCdwpgRestartInstanceRead, + Delete: resourceTencentCloudCdwpgRestartInstanceDelete, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Instance id (e.g., \"cdwpg-xxxx\").", + }, + + "node_types": { + Type: schema.TypeSet, + Optional: true, + ForceNew: true, + Description: "Node types to restart (gtm/cn/dn).", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + + "node_ids": { + Type: schema.TypeSet, + Optional: true, + ForceNew: true, + Description: "Node ids to restart (specify nodes to reboot).", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + } +} + +func resourceTencentCloudCdwpgRestartInstanceCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_restart_instance.create")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + var ( + instanceId string + ) + var ( + request = cdwpgv20201230.NewRestartInstanceRequest() + response = cdwpgv20201230.NewRestartInstanceResponse() + ) + + if v, ok := d.GetOk("instance_id"); ok { + instanceId = v.(string) + request.InstanceId = helper.String(instanceId) + } + + if v, ok := d.GetOk("node_types"); ok { + nodeTypesSet := v.(*schema.Set).List() + for i := range nodeTypesSet { + nodeTypes := nodeTypesSet[i].(string) + request.NodeTypes = append(request.NodeTypes, helper.String(nodeTypes)) + } + } + + if v, ok := d.GetOk("node_ids"); ok { + nodeIdsSet := v.(*schema.Set).List() + for i := range nodeIdsSet { + nodeIds := nodeIdsSet[i].(string) + request.NodeIds = append(request.NodeIds, helper.String(nodeIds)) + } + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCdwpgV20201230Client().RestartInstanceWithContext(ctx, 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(), result.ToJsonString()) + } + response = result + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s create cdwpg restart instance failed, reason:%+v", logId, err) + return err + } + + _ = response + + service := CdwpgService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + conf := tccommon.BuildStateChangeConf([]string{}, []string{"Serving"}, 10*tccommon.ReadRetryTimeout, time.Second, service.InstanceStateRefreshFunc(instanceId, []string{})) + + if _, e := conf.WaitForState(); e != nil { + return e + } + d.SetId(instanceId) + + return resourceTencentCloudCdwpgRestartInstanceRead(d, meta) +} + +func resourceTencentCloudCdwpgRestartInstanceRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_restart_instance.read")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} + +func resourceTencentCloudCdwpgRestartInstanceDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_restart_instance.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance.md b/tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance.md new file mode 100644 index 0000000000..3dc2cae23a --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance.md @@ -0,0 +1,10 @@ +Provides a resource to create a cdwpg cdwpg_restart_instance + +Example Usage + +```hcl +resource "tencentcloud_cdwpg_restart_instance" "cdwpg_restart_instance" { + instance_id = "cdwpg-zpiemnyd" + node_types = ["gtm"] +} +``` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance_test.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance_test.go new file mode 100644 index 0000000000..e18f80fe3e --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_restart_instance_test.go @@ -0,0 +1,30 @@ +package cdwpg_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudCdwpgRestartInstanceResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccCdwpgRestartInstance, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_restart_instance.cdwpg_restart_instance", "id")), + }}, + }) +} + +const testAccCdwpgRestartInstance = ` +resource "tencentcloud_cdwpg_restart_instance" "cdwpg_restart_instance" { + instance_id = "cdwpg-zpiemnyd" + node_types = ["gtm"] +} +` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.go new file mode 100644 index 0000000000..bc7a295bdb --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.go @@ -0,0 +1,105 @@ +package cdwpg + +import ( + "context" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + cdwpgv20201230 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwpg/v20201230" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudCdwpgUpgradeInstance() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudCdwpgUpgradeInstanceCreate, + Read: resourceTencentCloudCdwpgUpgradeInstanceRead, + Delete: resourceTencentCloudCdwpgUpgradeInstanceDelete, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Instance id.", + }, + + "package_version": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Package version.", + }, + }, + } +} + +func resourceTencentCloudCdwpgUpgradeInstanceCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_upgrade_instance.create")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + var ( + instanceId string + ) + var ( + request = cdwpgv20201230.NewUpgradeInstanceRequest() + response = cdwpgv20201230.NewUpgradeInstanceResponse() + ) + + if v, ok := d.GetOk("instance_id"); ok { + instanceId = v.(string) + request.InstanceId = helper.String(instanceId) + } + + if v, ok := d.GetOk("package_version"); ok { + request.PackageVersion = helper.String(v.(string)) + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCdwpgV20201230Client().UpgradeInstanceWithContext(ctx, 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(), result.ToJsonString()) + } + response = result + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s create cdwpg upgrade instance failed, reason:%+v", logId, err) + return err + } + + _ = response + + service := CdwpgService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + conf := tccommon.BuildStateChangeConf([]string{}, []string{"Serving"}, 10*tccommon.ReadRetryTimeout, time.Second, service.InstanceStateRefreshFunc(instanceId, []string{})) + + if _, e := conf.WaitForState(); e != nil { + return e + } + + d.SetId(instanceId) + + return resourceTencentCloudCdwpgUpgradeInstanceRead(d, meta) +} + +func resourceTencentCloudCdwpgUpgradeInstanceRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_upgrade_instance.read")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} + +func resourceTencentCloudCdwpgUpgradeInstanceDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_upgrade_instance.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.md b/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.md new file mode 100644 index 0000000000..85426f359f --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.md @@ -0,0 +1,10 @@ +Provides a resource to create a cdwpg cdwpg_upgrade_instance + +Example Usage + +```hcl +resource "tencentcloud_cdwpg_upgrade_instance" "cdwpg_upgrade_instance" { + instance_id = "cdwpg-zpiemnyd" + package_version = "3.16.9.4" +} +``` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance_test.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance_test.go new file mode 100644 index 0000000000..a1a6d3a782 --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance_test.go @@ -0,0 +1,32 @@ +package cdwpg_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudCdwpgUpgradeInstanceResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCdwpgUpgradeInstance, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_upgrade_instance.cdwpg_upgrade_instance", "id")), + }, + }, + }) +} + +const testAccCdwpgUpgradeInstance = ` +resource "tencentcloud_cdwpg_upgrade_instance" "cdwpg_upgrade_instance" { + instance_id = "cdwpg-zpiemnyd" + package_version = "3.16.9.4" +} +` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba.go new file mode 100644 index 0000000000..75b9c34407 --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba.go @@ -0,0 +1,231 @@ +package cdwpg + +import ( + "context" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + cdwpgv20201230 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwpg/v20201230" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudCdwpgUserhba() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudCdwpgUserhbaCreate, + Read: resourceTencentCloudCdwpgUserhbaRead, + Update: resourceTencentCloudCdwpgUserhbaUpdate, + Delete: resourceTencentCloudCdwpgUserhbaDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Instance id.", + }, + + "hba_configs": { + Type: schema.TypeList, + Optional: true, + Description: "HBA configuration array.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + Required: true, + Description: "Type.", + }, + "database": { + Type: schema.TypeString, + Required: true, + Description: "Database.", + }, + "user": { + Type: schema.TypeString, + Required: true, + Description: "User.", + }, + "address": { + Type: schema.TypeString, + Required: true, + Description: "IP address.", + }, + "mask": { + Type: schema.TypeString, + Optional: true, + Description: "Mask.", + }, + "method": { + Type: schema.TypeString, + Required: true, + Description: "Method.", + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudCdwpgUserhbaCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_userhba.create")() + defer tccommon.InconsistentCheck(d, meta)() + + instanceId := d.Get("instance_id").(string) + + d.SetId(instanceId) + + return resourceTencentCloudCdwpgUserhbaUpdate(d, meta) +} + +func resourceTencentCloudCdwpgUserhbaRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_userhba.read")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + service := CdwpgService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + + instanceId := d.Id() + _ = d.Set("instance_id", instanceId) + respData, err := service.DescribeCdwpgUserhbaById(ctx, instanceId) + if err != nil { + return err + } + + if respData == nil { + d.SetId("") + log.Printf("[WARN]%s resource `cdwpg_userhba` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil + } + hbaConfigsList := make([]map[string]interface{}, 0, len(respData.HbaConfigs)) + if respData.HbaConfigs != nil { + for _, hbaConfigs := range respData.HbaConfigs { + hbaConfigsMap := map[string]interface{}{} + + if hbaConfigs.Type != nil { + hbaConfigsMap["type"] = hbaConfigs.Type + } + + if hbaConfigs.Database != nil { + hbaConfigsMap["database"] = hbaConfigs.Database + } + + if hbaConfigs.User != nil { + hbaConfigsMap["user"] = hbaConfigs.User + } + + if hbaConfigs.Address != nil { + hbaConfigsMap["address"] = hbaConfigs.Address + } + + if hbaConfigs.Mask != nil { + hbaConfigsMap["mask"] = hbaConfigs.Mask + } + + if hbaConfigs.Method != nil { + hbaConfigsMap["method"] = hbaConfigs.Method + } + + hbaConfigsList = append(hbaConfigsList, hbaConfigsMap) + } + + _ = d.Set("hba_configs", hbaConfigsList) + } + + return nil +} + +func resourceTencentCloudCdwpgUserhbaUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_userhba.update")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + instanceId := d.Id() + + needChange := false + mutableArgs := []string{"hba_configs"} + for _, v := range mutableArgs { + if d.HasChange(v) { + needChange = true + break + } + } + + if needChange { + request := cdwpgv20201230.NewModifyUserHbaRequest() + + if v, ok := d.GetOk("instance_id"); ok { + request.InstanceId = helper.String(v.(string)) + } + + if v, ok := d.GetOk("hba_configs"); ok { + for _, item := range v.([]interface{}) { + hbaConfigsMap := item.(map[string]interface{}) + hbaConfig := cdwpgv20201230.HbaConfig{} + if v, ok := hbaConfigsMap["type"]; ok { + hbaConfig.Type = helper.String(v.(string)) + } + if v, ok := hbaConfigsMap["database"]; ok { + hbaConfig.Database = helper.String(v.(string)) + } + if v, ok := hbaConfigsMap["user"]; ok { + hbaConfig.User = helper.String(v.(string)) + } + if v, ok := hbaConfigsMap["address"]; ok { + hbaConfig.Address = helper.String(v.(string)) + } + if v, ok := hbaConfigsMap["mask"]; ok { + hbaConfig.Mask = helper.String(v.(string)) + } + if v, ok := hbaConfigsMap["method"]; ok { + hbaConfig.Method = helper.String(v.(string)) + } + request.HbaConfigs = append(request.HbaConfigs, &hbaConfig) + } + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCdwpgV20201230Client().ModifyUserHbaWithContext(ctx, 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(), result.ToJsonString()) + } + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s update cdwpg userhba failed, reason:%+v", logId, err) + return err + } + } + + _ = instanceId + + service := CdwpgService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + conf := tccommon.BuildStateChangeConf([]string{}, []string{"Serving"}, 10*tccommon.ReadRetryTimeout, time.Second, service.InstanceStateRefreshFunc(instanceId, []string{})) + + if _, e := conf.WaitForState(); e != nil { + return e + } + + return resourceTencentCloudCdwpgUserhbaRead(d, meta) +} + +func resourceTencentCloudCdwpgUserhbaDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_userhba.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba.md b/tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba.md new file mode 100644 index 0000000000..d70ceca9a4 --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba.md @@ -0,0 +1,24 @@ +Provides a resource to create a cdwpg cdwpg_userhba + +Example Usage + +```hcl +resource "tencentcloud_cdwpg_userhba" "cdwpg_userhba" { + instance_id = "cdwpg-zpiemnyd" + hba_configs { + type = "host" + database = "all" + user = "all" + address = "0.0.0.0/0" + method = "md5" + } +} +``` + +Import + +cdwpg cdwpg_userhba can be imported using the id, e.g. + +``` +terraform import tencentcloud_cdwpg_userhba.cdwpg_userhba cdwpg_userhba_id +``` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba_test.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba_test.go new file mode 100644 index 0000000000..1188d43471 --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_userhba_test.go @@ -0,0 +1,41 @@ +package cdwpg_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudCdwpgUserhbaResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccCdwpgUserhba, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_userhba.cdwpg_userhba", "id")), + }, { + ResourceName: "tencentcloud_cdwpg_userhba.cdwpg_userhba", + ImportState: true, + ImportStateVerify: true, + }}, + }) +} + +const testAccCdwpgUserhba = ` + +resource "tencentcloud_cdwpg_userhba" "cdwpg_userhba" { + instance_id = "cdwpg-zpiemnyd" + hba_configs { + type = "host" + database = "all" + user = "all" + address = "0.0.0.0/0" + method = "md5" + } +} +` diff --git a/tencentcloud/services/cdwpg/service_tencentcloud_cdwpg.go b/tencentcloud/services/cdwpg/service_tencentcloud_cdwpg.go index 989ff95a41..cc16725c2b 100644 --- a/tencentcloud/services/cdwpg/service_tencentcloud_cdwpg.go +++ b/tencentcloud/services/cdwpg/service_tencentcloud_cdwpg.go @@ -346,3 +346,57 @@ func (me *CdwpgService) DescribeCdwpgDbconfigByFilter(ctx context.Context, param return } + +func (me *CdwpgService) DescribeCdwpgAccountById(ctx context.Context, instanceId string) (ret *cdwpg.AccountInfo, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := cdwpg.NewDescribeAccountsRequest() + request.InstanceId = helper.String(instanceId) + + 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()) + + response, err := me.client.UseCdwpgV20201230Client().DescribeAccounts(request) + if err != nil { + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + if len(response.Response.Accounts) < 1 { + return + } + + ret = response.Response.Accounts[0] + return +} + +func (me *CdwpgService) DescribeCdwpgUserhbaById(ctx context.Context, instanceId string) (ret *cdwpg.DescribeUserHbaConfigResponseParams, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := cdwpg.NewDescribeUserHbaConfigRequest() + request.InstanceId = helper.String(instanceId) + + 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()) + + response, err := me.client.UseCdwpgV20201230Client().DescribeUserHbaConfig(request) + if err != nil { + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + ret = response.Response + return +} diff --git a/website/docs/r/cdwpg_account.html.markdown b/website/docs/r/cdwpg_account.html.markdown new file mode 100644 index 0000000000..21bf344a71 --- /dev/null +++ b/website/docs/r/cdwpg_account.html.markdown @@ -0,0 +1,47 @@ +--- +subcategory: "CDWPG" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_cdwpg_account" +sidebar_current: "docs-tencentcloud-resource-cdwpg_account" +description: |- + Provides a resource to create a cdwpg cdwpg_account +--- + +# tencentcloud_cdwpg_account + +Provides a resource to create a cdwpg cdwpg_account + +## Example Usage + +```hcl +resource "tencentcloud_cdwpg_account" "cdwpg_account" { + instance_id = "cdwpg-zpiemnyd" + user_name = "dbadmin" + new_password = "testpassword" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String, ForceNew) Instance id. +* `new_password` - (Required, String) New password. +* `user_name` - (Required, String, ForceNew) Username. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + +## Import + +cdwpg cdwpg_account can be imported using the id, e.g. + +``` +terraform import tencentcloud_cdwpg_account.cdwpg_account cdwpg_account_id +``` + diff --git a/website/docs/r/cdwpg_restart_instance.html.markdown b/website/docs/r/cdwpg_restart_instance.html.markdown new file mode 100644 index 0000000000..9cb9fabd80 --- /dev/null +++ b/website/docs/r/cdwpg_restart_instance.html.markdown @@ -0,0 +1,38 @@ +--- +subcategory: "CDWPG" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_cdwpg_restart_instance" +sidebar_current: "docs-tencentcloud-resource-cdwpg_restart_instance" +description: |- + Provides a resource to create a cdwpg cdwpg_restart_instance +--- + +# tencentcloud_cdwpg_restart_instance + +Provides a resource to create a cdwpg cdwpg_restart_instance + +## Example Usage + +```hcl +resource "tencentcloud_cdwpg_restart_instance" "cdwpg_restart_instance" { + instance_id = "cdwpg-zpiemnyd" + node_types = ["gtm"] +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String, ForceNew) Instance id (e.g., "cdwpg-xxxx"). +* `node_ids` - (Optional, Set: [`String`], ForceNew) Node ids to restart (specify nodes to reboot). +* `node_types` - (Optional, Set: [`String`], ForceNew) Node types to restart (gtm/cn/dn). + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + diff --git a/website/docs/r/cdwpg_upgrade_instance.html.markdown b/website/docs/r/cdwpg_upgrade_instance.html.markdown new file mode 100644 index 0000000000..958e0d8e2c --- /dev/null +++ b/website/docs/r/cdwpg_upgrade_instance.html.markdown @@ -0,0 +1,37 @@ +--- +subcategory: "CDWPG" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_cdwpg_upgrade_instance" +sidebar_current: "docs-tencentcloud-resource-cdwpg_upgrade_instance" +description: |- + Provides a resource to create a cdwpg cdwpg_upgrade_instance +--- + +# tencentcloud_cdwpg_upgrade_instance + +Provides a resource to create a cdwpg cdwpg_upgrade_instance + +## Example Usage + +```hcl +resource "tencentcloud_cdwpg_upgrade_instance" "cdwpg_upgrade_instance" { + instance_id = "cdwpg-zpiemnyd" + package_version = "3.16.9.4" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String, ForceNew) Instance id. +* `package_version` - (Required, String, ForceNew) Package version. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + diff --git a/website/docs/r/cdwpg_userhba.html.markdown b/website/docs/r/cdwpg_userhba.html.markdown new file mode 100644 index 0000000000..16a2497911 --- /dev/null +++ b/website/docs/r/cdwpg_userhba.html.markdown @@ -0,0 +1,60 @@ +--- +subcategory: "CDWPG" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_cdwpg_userhba" +sidebar_current: "docs-tencentcloud-resource-cdwpg_userhba" +description: |- + Provides a resource to create a cdwpg cdwpg_userhba +--- + +# tencentcloud_cdwpg_userhba + +Provides a resource to create a cdwpg cdwpg_userhba + +## Example Usage + +```hcl +resource "tencentcloud_cdwpg_userhba" "cdwpg_userhba" { + instance_id = "cdwpg-zpiemnyd" + hba_configs { + type = "host" + database = "all" + user = "all" + address = "0.0.0.0/0" + method = "md5" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String, ForceNew) Instance id. +* `hba_configs` - (Optional, List) HBA configuration array. + +The `hba_configs` object supports the following: + +* `address` - (Required, String) IP address. +* `database` - (Required, String) Database. +* `method` - (Required, String) Method. +* `type` - (Required, String) Type. +* `user` - (Required, String) User. +* `mask` - (Optional, String) Mask. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + +## Import + +cdwpg cdwpg_userhba can be imported using the id, e.g. + +``` +terraform import tencentcloud_cdwpg_userhba.cdwpg_userhba cdwpg_userhba_id +``` + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 0c4f56224c..7b3aaa248b 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -585,9 +585,21 @@
  • tencentcloud_cdwpg_dbconfig
  • +
  • + tencentcloud_cdwpg_account +
  • tencentcloud_cdwpg_instance
  • +
  • + tencentcloud_cdwpg_restart_instance +
  • +
  • + tencentcloud_cdwpg_upgrade_instance +
  • +
  • + tencentcloud_cdwpg_userhba +
  • From 7b141d12590a08cdc64cb06a0f20a6bdd1f0f011 Mon Sep 17 00:00:00 2001 From: mikatong Date: Mon, 24 Mar 2025 17:58:05 +0800 Subject: [PATCH 2/7] add changelog --- .changelog/3236.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .changelog/3236.txt diff --git a/.changelog/3236.txt b/.changelog/3236.txt new file mode 100644 index 0000000000..00a6dad362 --- /dev/null +++ b/.changelog/3236.txt @@ -0,0 +1,15 @@ +```release-note:new-resource +tencentcloud_cdwpg_account +``` + +```release-note:new-resource +tencentcloud_cdwpg_restart_instance +``` + +```release-note:new-resource +tencentcloud_cdwpg_upgrade_instance +``` + +```release-note:new-resource +tencentcloud_cdwpg_userhba +``` From b1739ef614e5ba0591b59c33b70f6414a95163ee Mon Sep 17 00:00:00 2001 From: mikatong Date: Thu, 27 Mar 2025 15:33:38 +0800 Subject: [PATCH 3/7] update resource --- tencentcloud/provider.go | 3 +- tencentcloud/provider.md | 3 +- .../cdwpg/resource_tc_cdwpg_account.md | 19 --- .../cdwpg/resource_tc_cdwpg_instance.go | 40 ++++++ .../cdwpg/resource_tc_cdwpg_instance_test.go | 117 ++++++++++++++++++ ...source_tc_cdwpg_reset_account_password.go} | 30 ++--- ...esource_tc_cdwpg_reset_account_password.md | 19 +++ ...e_tc_cdwpg_reset_account_password_test.go} | 10 +- .../resource_tc_cdwpg_upgrade_instance.go | 105 ---------------- .../resource_tc_cdwpg_upgrade_instance.md | 10 -- ...resource_tc_cdwpg_upgrade_instance_test.go | 32 ----- 11 files changed, 198 insertions(+), 190 deletions(-) delete mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_account.md rename tencentcloud/services/cdwpg/{resource_tc_cdwpg_account.go => resource_tc_cdwpg_reset_account_password.go} (74%) create mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password.md rename tencentcloud/services/cdwpg/{resource_tc_cdwpg_account_test.go => resource_tc_cdwpg_reset_account_password_test.go} (66%) delete mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.go delete mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.md delete mode 100644 tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance_test.go diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 850872e902..eaafaf3941 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -2224,9 +2224,8 @@ func Provider() *schema.Provider { "tencentcloud_bi_embed_interval_apply": bi.ResourceTencentCloudBiEmbedIntervalApply(), "tencentcloud_cdwpg_instance": cdwpg.ResourceTencentCloudCdwpgInstance(), "tencentcloud_cdwpg_dbconfig": cdwpg.ResourceTencentCloudCdwpgDbconfig(), - "tencentcloud_cdwpg_account": cdwpg.ResourceTencentCloudCdwpgAccount(), + "tencentcloud_cdwpg_reset_account_password": cdwpg.ResourceTencentCloudCdwpgResetAccountPassword(), "tencentcloud_cdwpg_restart_instance": cdwpg.ResourceTencentCloudCdwpgRestartInstance(), - "tencentcloud_cdwpg_upgrade_instance": cdwpg.ResourceTencentCloudCdwpgUpgradeInstance(), "tencentcloud_cdwpg_userhba": cdwpg.ResourceTencentCloudCdwpgUserhba(), "tencentcloud_clickhouse_keyval_config": cdwch.ResourceTencentCloudClickhouseKeyvalConfig(), "tencentcloud_clickhouse_xml_config": cdwch.ResourceTencentCloudClickhouseXmlConfig(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index db0de6b1d5..d209b5e6f7 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -2253,9 +2253,8 @@ tencentcloud_cdwpg_nodes Resource tencentcloud_cdwpg_instance tencentcloud_cdwpg_dbconfig -tencentcloud_cdwpg_account +tencentcloud_cdwpg_reset_account_password tencentcloud_cdwpg_restart_instance -tencentcloud_cdwpg_upgrade_instance tencentcloud_cdwpg_userhba CSIP diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.md b/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.md deleted file mode 100644 index 44f6a37df0..0000000000 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.md +++ /dev/null @@ -1,19 +0,0 @@ -Provides a resource to create a cdwpg cdwpg_account - -Example Usage - -```hcl -resource "tencentcloud_cdwpg_account" "cdwpg_account" { - instance_id = "cdwpg-zpiemnyd" - user_name = "dbadmin" - new_password = "testpassword" -} -``` - -Import - -cdwpg cdwpg_account can be imported using the id, e.g. - -``` -terraform import tencentcloud_cdwpg_account.cdwpg_account cdwpg_account_id -``` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go index 3b83e129bf..5720f61aa5 100644 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go @@ -143,6 +143,11 @@ func ResourceTencentCloudCdwpgInstance() *schema.Resource { Optional: true, Description: "Tag description list.", }, + "product_version": { + Optional: true, + Type: schema.TypeString, + Description: "Version.", + }, }, } } @@ -224,6 +229,9 @@ func resourceTencentCloudCdwpgInstanceCreate(d *schema.ResourceData, meta interf request.Resources = append(request.Resources, &resourceSpecNew) } } + if v, ok := d.GetOk("product_version"); ok { + request.ProductVersion = helper.String(v.(string)) + } err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCdwpgClient().CreateInstanceByApi(request) @@ -366,6 +374,10 @@ func resourceTencentCloudCdwpgInstanceRead(d *schema.ResourceData, meta interfac } + if instance.Version != nil { + _ = d.Set("product_version", instance.Version) + } + tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn() tagService := svctag.NewTagService(tcClient) tags, err := tagService.DescribeResourceTags(ctx, "cdwpg", "cdwpgInstance", tcClient.Region, d.Id()) @@ -489,6 +501,34 @@ func resourceTencentCloudCdwpgInstanceUpdate(d *schema.ResourceData, meta interf } } } + if d.HasChange("product_version") { + if v, ok := d.GetOk("product_version"); ok { + request := cdwpg.NewUpgradeInstanceRequest() + request.InstanceId = helper.String(instanceId) + request.PackageVersion = helper.String(v.(string)) + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCdwpgV20201230Client().UpgradeInstance(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(), result.ToJsonString()) + } + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s create cdwpg upgrade instance failed, reason:%+v", logId, err) + return err + } + + service := CdwpgService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + conf := tccommon.BuildStateChangeConf([]string{}, []string{"Serving"}, 10*tccommon.ReadRetryTimeout, time.Second, service.InstanceStateRefreshFunc(instanceId, []string{})) + + if _, e := conf.WaitForState(); e != nil { + return e + } + } + } + return resourceTencentCloudCdwpgInstanceRead(d, meta) } diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go index 7bb10c6ec8..fa9f0dff5a 100644 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go @@ -52,6 +52,37 @@ func TestAccTencentCloudCdwpgInstanceResource_basic(t *testing.T) { }) } +func TestAccTencentCloudCdwpgInstanceResource_withVersion(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_PREPAY) }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCdwpgInstanceWithVersion, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_instance.instance", "id"), + resource.TestCheckResourceAttr("tencentcloud_cdwpg_instance.instance", "product_version", "3.16.9.3"), + ), + }, + { + Config: testAccCdwpgInstanceWithVersionUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_instance.instance", "id"), + resource.TestCheckResourceAttr("tencentcloud_cdwpg_instance.instance", "instance_name", "test_pg_update"), + resource.TestCheckResourceAttr("tencentcloud_cdwpg_instance.instance", "product_version", "3.16.9.4"), + ), + }, + { + ResourceName: "tencentcloud_cdwpg_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"admin_password"}, + }, + }, + }) +} + const testAccCdwpgInstance = ` resource "tencentcloud_cdwpg_instance" "instance" { instance_name = "test_pg" @@ -177,3 +208,89 @@ resource "tencentcloud_cdwpg_instance" "instance" { } } ` + +const testAccCdwpgInstanceWithVersion = ` +resource "tencentcloud_cdwpg_instance" "instance" { + instance_name = "test_pg" + zone = "ap-guangzhou-6" + user_vpc_id = "vpc-axrsmmrv" + user_subnet_id = "subnet-o6qcrhzo" + charge_properties { + renew_flag = 0 + time_span = 1 + time_unit = "h" + charge_type = "POSTPAID_BY_HOUR" + + } + admin_password = "bWJSZDVtVmZkNExJ" + resources { + spec_name = "S_4_16_H_CN" + count = 2 + disk_spec { + disk_type = "CLOUD_HSSD" + disk_size = 200 + disk_count = 1 + } + type = "cn" + + } + resources { + spec_name = "S_4_16_H_CN" + count = 2 + disk_spec { + disk_type = "CLOUD_HSSD" + disk_size = 20 + disk_count = 10 + } + type = "dn" + + } + tags = { + "tagKey" = "tagValue" + } + product_version = "3.16.9.3" +} +` + +const testAccCdwpgInstanceWithVersionUpdate = ` +resource "tencentcloud_cdwpg_instance" "instance" { + instance_name = "test_pg" + zone = "ap-guangzhou-6" + user_vpc_id = "vpc-axrsmmrv" + user_subnet_id = "subnet-o6qcrhzo" + charge_properties { + renew_flag = 0 + time_span = 1 + time_unit = "h" + charge_type = "POSTPAID_BY_HOUR" + + } + admin_password = "bWJSZDVtVmZkNExJ" + resources { + spec_name = "S_4_16_H_CN" + count = 2 + disk_spec { + disk_type = "CLOUD_HSSD" + disk_size = 200 + disk_count = 1 + } + type = "cn" + + } + resources { + spec_name = "S_4_16_H_CN" + count = 2 + disk_spec { + disk_type = "CLOUD_HSSD" + disk_size = 20 + disk_count = 10 + } + type = "dn" + + } + tags = { + "tagKey" = "tagValue" + } + product_version = "3.16.9.4" +} +` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password.go similarity index 74% rename from tencentcloud/services/cdwpg/resource_tc_cdwpg_account.go rename to tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password.go index 8547544962..ec55ad77a4 100644 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_account.go +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password.go @@ -14,12 +14,12 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" ) -func ResourceTencentCloudCdwpgAccount() *schema.Resource { +func ResourceTencentCloudCdwpgResetAccountPassword() *schema.Resource { return &schema.Resource{ - Create: resourceTencentCloudCdwpgAccountCreate, - Read: resourceTencentCloudCdwpgAccountRead, - Update: resourceTencentCloudCdwpgAccountUpdate, - Delete: resourceTencentCloudCdwpgAccountDelete, + Create: resourceTencentCloudCdwpgResetAccountPasswordCreate, + Read: resourceTencentCloudCdwpgResetAccountPasswordRead, + Update: resourceTencentCloudCdwpgResetAccountPasswordUpdate, + Delete: resourceTencentCloudCdwpgResetAccountPasswordDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -48,8 +48,8 @@ func ResourceTencentCloudCdwpgAccount() *schema.Resource { } } -func resourceTencentCloudCdwpgAccountCreate(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.create")() +func resourceTencentCloudCdwpgResetAccountPasswordCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_reset_account_password.create")() defer tccommon.InconsistentCheck(d, meta)() instanceId := d.Get("instance_id").(string) @@ -57,11 +57,11 @@ func resourceTencentCloudCdwpgAccountCreate(d *schema.ResourceData, meta interfa d.SetId(strings.Join([]string{instanceId, userName}, tccommon.FILED_SP)) - return resourceTencentCloudCdwpgAccountUpdate(d, meta) + return resourceTencentCloudCdwpgResetAccountPasswordUpdate(d, meta) } -func resourceTencentCloudCdwpgAccountRead(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.read")() +func resourceTencentCloudCdwpgResetAccountPasswordRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_reset_account_password.read")() defer tccommon.InconsistentCheck(d, meta)() logId := tccommon.GetLogId(tccommon.ContextNil) @@ -99,8 +99,8 @@ func resourceTencentCloudCdwpgAccountRead(d *schema.ResourceData, meta interface return nil } -func resourceTencentCloudCdwpgAccountUpdate(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.update")() +func resourceTencentCloudCdwpgResetAccountPasswordUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_reset_account_password.update")() defer tccommon.InconsistentCheck(d, meta)() logId := tccommon.GetLogId(tccommon.ContextNil) @@ -149,11 +149,11 @@ func resourceTencentCloudCdwpgAccountUpdate(d *schema.ResourceData, meta interfa } } - return resourceTencentCloudCdwpgAccountRead(d, meta) + return resourceTencentCloudCdwpgResetAccountPasswordRead(d, meta) } -func resourceTencentCloudCdwpgAccountDelete(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.delete")() +func resourceTencentCloudCdwpgResetAccountPasswordDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_reset_account_password.delete")() defer tccommon.InconsistentCheck(d, meta)() return nil diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password.md b/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password.md new file mode 100644 index 0000000000..4e8ae1155a --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password.md @@ -0,0 +1,19 @@ +Provides a resource to reset cdwpg account password + +Example Usage + +```hcl +resource "tencentcloud_cdwpg_reset_account_password" "cdwpg_reset_account_password" { + instance_id = "cdwpg-zpiemnyd" + user_name = "dbadmin" + new_password = "testpassword" +} +``` + +Import + +cdwpg reset account password can be imported using the id, e.g. + +``` +terraform import tencentcloud_cdwpg_reset_account_password.cdwpg_account cdwpg_reset_account_password_id +``` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_account_test.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password_test.go similarity index 66% rename from tencentcloud/services/cdwpg/resource_tc_cdwpg_account_test.go rename to tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password_test.go index d456a58307..b33a65f597 100644 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_account_test.go +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password_test.go @@ -8,7 +8,7 @@ import ( tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" ) -func TestAccTencentCloudCdwpgAccountResource_basic(t *testing.T) { +func TestAccTencentCloudCdwpgResetAccountPasswordResource_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -17,9 +17,9 @@ func TestAccTencentCloudCdwpgAccountResource_basic(t *testing.T) { Providers: tcacctest.AccProviders, Steps: []resource.TestStep{{ Config: testAccCdwpgAccount, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_account.cdwpg_account", "id")), + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_reset_account_password.cdwpg_account", "id")), }, { - ResourceName: "tencentcloud_cdwpg_account.cdwpg_account", + ResourceName: "tencentcloud_cdwpg_reset_account_password.cdwpg_account", ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"new_password"}, @@ -28,8 +28,8 @@ func TestAccTencentCloudCdwpgAccountResource_basic(t *testing.T) { } const testAccCdwpgAccount = ` -resource "tencentcloud_cdwpg_account" "cdwpg_account" { - instance_id = "cdwpg-zpiemnyd" +resource "tencentcloud_cdwpg_reset_account_password" "cdwpg_account" { + instance_id = "cdwpg-r3xgk6w3" user_name = "dbadmin" new_password = "testpassword" } diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.go deleted file mode 100644 index bc7a295bdb..0000000000 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.go +++ /dev/null @@ -1,105 +0,0 @@ -package cdwpg - -import ( - "context" - "log" - "time" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - cdwpgv20201230 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwpg/v20201230" - - tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" - "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" -) - -func ResourceTencentCloudCdwpgUpgradeInstance() *schema.Resource { - return &schema.Resource{ - Create: resourceTencentCloudCdwpgUpgradeInstanceCreate, - Read: resourceTencentCloudCdwpgUpgradeInstanceRead, - Delete: resourceTencentCloudCdwpgUpgradeInstanceDelete, - Schema: map[string]*schema.Schema{ - "instance_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Instance id.", - }, - - "package_version": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Package version.", - }, - }, - } -} - -func resourceTencentCloudCdwpgUpgradeInstanceCreate(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_upgrade_instance.create")() - defer tccommon.InconsistentCheck(d, meta)() - - logId := tccommon.GetLogId(tccommon.ContextNil) - - ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) - - var ( - instanceId string - ) - var ( - request = cdwpgv20201230.NewUpgradeInstanceRequest() - response = cdwpgv20201230.NewUpgradeInstanceResponse() - ) - - if v, ok := d.GetOk("instance_id"); ok { - instanceId = v.(string) - request.InstanceId = helper.String(instanceId) - } - - if v, ok := d.GetOk("package_version"); ok { - request.PackageVersion = helper.String(v.(string)) - } - - err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { - result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCdwpgV20201230Client().UpgradeInstanceWithContext(ctx, 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(), result.ToJsonString()) - } - response = result - return nil - }) - if err != nil { - log.Printf("[CRITAL]%s create cdwpg upgrade instance failed, reason:%+v", logId, err) - return err - } - - _ = response - - service := CdwpgService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} - conf := tccommon.BuildStateChangeConf([]string{}, []string{"Serving"}, 10*tccommon.ReadRetryTimeout, time.Second, service.InstanceStateRefreshFunc(instanceId, []string{})) - - if _, e := conf.WaitForState(); e != nil { - return e - } - - d.SetId(instanceId) - - return resourceTencentCloudCdwpgUpgradeInstanceRead(d, meta) -} - -func resourceTencentCloudCdwpgUpgradeInstanceRead(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_upgrade_instance.read")() - defer tccommon.InconsistentCheck(d, meta)() - - return nil -} - -func resourceTencentCloudCdwpgUpgradeInstanceDelete(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_upgrade_instance.delete")() - defer tccommon.InconsistentCheck(d, meta)() - - return nil -} diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.md b/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.md deleted file mode 100644 index 85426f359f..0000000000 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance.md +++ /dev/null @@ -1,10 +0,0 @@ -Provides a resource to create a cdwpg cdwpg_upgrade_instance - -Example Usage - -```hcl -resource "tencentcloud_cdwpg_upgrade_instance" "cdwpg_upgrade_instance" { - instance_id = "cdwpg-zpiemnyd" - package_version = "3.16.9.4" -} -``` diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance_test.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance_test.go deleted file mode 100644 index a1a6d3a782..0000000000 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_upgrade_instance_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package cdwpg_test - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - - tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" -) - -func TestAccTencentCloudCdwpgUpgradeInstanceResource_basic(t *testing.T) { - t.Parallel() - resource.Test(t, resource.TestCase{ - PreCheck: func() { - tcacctest.AccPreCheck(t) - }, - Providers: tcacctest.AccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCdwpgUpgradeInstance, - Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_upgrade_instance.cdwpg_upgrade_instance", "id")), - }, - }, - }) -} - -const testAccCdwpgUpgradeInstance = ` -resource "tencentcloud_cdwpg_upgrade_instance" "cdwpg_upgrade_instance" { - instance_id = "cdwpg-zpiemnyd" - package_version = "3.16.9.4" -} -` From bf7d0d16bf6731111467d267596520b96e9cf125 Mon Sep 17 00:00:00 2001 From: mikatong Date: Thu, 27 Mar 2025 16:43:56 +0800 Subject: [PATCH 4/7] update --- .changelog/3236.txt | 6 +-- website/docs/r/cdwpg_instance.html.markdown | 1 + ...cdwpg_reset_account_password.html.markdown | 47 +++++++++++++++++++ website/tencentcloud.erb | 7 +-- 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 website/docs/r/cdwpg_reset_account_password.html.markdown diff --git a/.changelog/3236.txt b/.changelog/3236.txt index 00a6dad362..f451b3840f 100644 --- a/.changelog/3236.txt +++ b/.changelog/3236.txt @@ -1,15 +1,11 @@ ```release-note:new-resource -tencentcloud_cdwpg_account +tencentcloud_cdwpg_reset_account_password ``` ```release-note:new-resource tencentcloud_cdwpg_restart_instance ``` -```release-note:new-resource -tencentcloud_cdwpg_upgrade_instance -``` - ```release-note:new-resource tencentcloud_cdwpg_userhba ``` diff --git a/website/docs/r/cdwpg_instance.html.markdown b/website/docs/r/cdwpg_instance.html.markdown index 5fbabc9193..37999ff353 100644 --- a/website/docs/r/cdwpg_instance.html.markdown +++ b/website/docs/r/cdwpg_instance.html.markdown @@ -66,6 +66,7 @@ The following arguments are supported: * `user_subnet_id` - (Required, String) subnet. * `user_vpc_id` - (Required, String) private network. * `zone` - (Required, String) Availability Zone. +* `product_version` - (Optional, String) Version. * `tags` - (Optional, Map) Tag description list. The `charge_properties` object supports the following: diff --git a/website/docs/r/cdwpg_reset_account_password.html.markdown b/website/docs/r/cdwpg_reset_account_password.html.markdown new file mode 100644 index 0000000000..e52ece8842 --- /dev/null +++ b/website/docs/r/cdwpg_reset_account_password.html.markdown @@ -0,0 +1,47 @@ +--- +subcategory: "CDWPG" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_cdwpg_reset_account_password" +sidebar_current: "docs-tencentcloud-resource-cdwpg_reset_account_password" +description: |- + Provides a resource to reset cdwpg account password +--- + +# tencentcloud_cdwpg_reset_account_password + +Provides a resource to reset cdwpg account password + +## Example Usage + +```hcl +resource "tencentcloud_cdwpg_reset_account_password" "cdwpg_reset_account_password" { + instance_id = "cdwpg-zpiemnyd" + user_name = "dbadmin" + new_password = "testpassword" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String, ForceNew) Instance id. +* `new_password` - (Required, String) New password. +* `user_name` - (Required, String, ForceNew) Username. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + +## Import + +cdwpg reset account password can be imported using the id, e.g. + +``` +terraform import tencentcloud_cdwpg_reset_account_password.cdwpg_account cdwpg_reset_account_password_id +``` + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 7b3aaa248b..a3e67e7c8e 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -585,17 +585,14 @@
  • tencentcloud_cdwpg_dbconfig
  • -
  • - tencentcloud_cdwpg_account -
  • tencentcloud_cdwpg_instance
  • - tencentcloud_cdwpg_restart_instance + tencentcloud_cdwpg_reset_account_password
  • - tencentcloud_cdwpg_upgrade_instance + tencentcloud_cdwpg_restart_instance
  • tencentcloud_cdwpg_userhba From fa4c983fc901443166ac9b3382fd66baa856978d Mon Sep 17 00:00:00 2001 From: mikatong Date: Thu, 27 Mar 2025 17:27:44 +0800 Subject: [PATCH 5/7] update --- .../services/cdwpg/resource_tc_cdwpg_instance_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go index fa9f0dff5a..a6375b5ad0 100644 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go @@ -214,7 +214,7 @@ resource "tencentcloud_cdwpg_instance" "instance" { instance_name = "test_pg" zone = "ap-guangzhou-6" user_vpc_id = "vpc-axrsmmrv" - user_subnet_id = "subnet-o6qcrhzo" + user_subnet_id = "subnet-kxaxknmg" charge_properties { renew_flag = 0 time_span = 1 @@ -257,7 +257,7 @@ resource "tencentcloud_cdwpg_instance" "instance" { instance_name = "test_pg" zone = "ap-guangzhou-6" user_vpc_id = "vpc-axrsmmrv" - user_subnet_id = "subnet-o6qcrhzo" + user_subnet_id = "subnet-kxaxknmg" charge_properties { renew_flag = 0 time_span = 1 From 8e343a3e1b4b673331edffe69b9b67d7c40db038 Mon Sep 17 00:00:00 2001 From: mikatong Date: Thu, 27 Mar 2025 17:40:47 +0800 Subject: [PATCH 6/7] update --- tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go index a6375b5ad0..9f8df4c054 100644 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go @@ -69,7 +69,6 @@ func TestAccTencentCloudCdwpgInstanceResource_withVersion(t *testing.T) { Config: testAccCdwpgInstanceWithVersionUpdate, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_instance.instance", "id"), - resource.TestCheckResourceAttr("tencentcloud_cdwpg_instance.instance", "instance_name", "test_pg_update"), resource.TestCheckResourceAttr("tencentcloud_cdwpg_instance.instance", "product_version", "3.16.9.4"), ), }, From aba9cb1c6a17e32cc3b4ac2facf774f37189715d Mon Sep 17 00:00:00 2001 From: mikatong Date: Fri, 28 Mar 2025 20:05:29 +0800 Subject: [PATCH 7/7] update --- .changelog/3236.txt | 4 ++++ tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go | 1 + 2 files changed, 5 insertions(+) diff --git a/.changelog/3236.txt b/.changelog/3236.txt index f451b3840f..7073bf99a6 100644 --- a/.changelog/3236.txt +++ b/.changelog/3236.txt @@ -9,3 +9,7 @@ tencentcloud_cdwpg_restart_instance ```release-note:new-resource tencentcloud_cdwpg_userhba ``` + +```release-note:enhancement +resource/tencentcloud_cdwpg_instance: support product_version +``` \ No newline at end of file diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go index 5720f61aa5..5160c05c05 100644 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go @@ -145,6 +145,7 @@ func ResourceTencentCloudCdwpgInstance() *schema.Resource { }, "product_version": { Optional: true, + Computed: true, Type: schema.TypeString, Description: "Version.", },