diff --git a/.changelog/3236.txt b/.changelog/3236.txt new file mode 100644 index 0000000000..7073bf99a6 --- /dev/null +++ b/.changelog/3236.txt @@ -0,0 +1,15 @@ +```release-note:new-resource +tencentcloud_cdwpg_reset_account_password +``` + +```release-note:new-resource +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/provider.go b/tencentcloud/provider.go index 93b834f2a6..eaafaf3941 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -2224,6 +2224,9 @@ func Provider() *schema.Provider { "tencentcloud_bi_embed_interval_apply": bi.ResourceTencentCloudBiEmbedIntervalApply(), "tencentcloud_cdwpg_instance": cdwpg.ResourceTencentCloudCdwpgInstance(), "tencentcloud_cdwpg_dbconfig": cdwpg.ResourceTencentCloudCdwpgDbconfig(), + "tencentcloud_cdwpg_reset_account_password": cdwpg.ResourceTencentCloudCdwpgResetAccountPassword(), + "tencentcloud_cdwpg_restart_instance": cdwpg.ResourceTencentCloudCdwpgRestartInstance(), + "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..d209b5e6f7 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -2253,6 +2253,9 @@ tencentcloud_cdwpg_nodes Resource tencentcloud_cdwpg_instance tencentcloud_cdwpg_dbconfig +tencentcloud_cdwpg_reset_account_password +tencentcloud_cdwpg_restart_instance +tencentcloud_cdwpg_userhba CSIP Resource diff --git a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go index 3b83e129bf..5160c05c05 100644 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go @@ -143,6 +143,12 @@ func ResourceTencentCloudCdwpgInstance() *schema.Resource { Optional: true, Description: "Tag description list.", }, + "product_version": { + Optional: true, + Computed: true, + Type: schema.TypeString, + Description: "Version.", + }, }, } } @@ -224,6 +230,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 +375,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 +502,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..9f8df4c054 100644 --- a/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go @@ -52,6 +52,36 @@ 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", "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 +207,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-kxaxknmg" + 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-kxaxknmg" + 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_reset_account_password.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password.go new file mode 100644 index 0000000000..ec55ad77a4 --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password.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 ResourceTencentCloudCdwpgResetAccountPassword() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudCdwpgResetAccountPasswordCreate, + Read: resourceTencentCloudCdwpgResetAccountPasswordRead, + Update: resourceTencentCloudCdwpgResetAccountPasswordUpdate, + Delete: resourceTencentCloudCdwpgResetAccountPasswordDelete, + 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 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) + userName := d.Get("user_name").(string) + + d.SetId(strings.Join([]string{instanceId, userName}, tccommon.FILED_SP)) + + return resourceTencentCloudCdwpgResetAccountPasswordUpdate(d, meta) +} + +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) + + 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 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) + + 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 resourceTencentCloudCdwpgResetAccountPasswordRead(d, meta) +} + +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_reset_account_password_test.go b/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password_test.go new file mode 100644 index 0000000000..b33a65f597 --- /dev/null +++ b/tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password_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 TestAccTencentCloudCdwpgResetAccountPasswordResource_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_reset_account_password.cdwpg_account", "id")), + }, { + ResourceName: "tencentcloud_cdwpg_reset_account_password.cdwpg_account", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"new_password"}, + }}, + }) +} + +const testAccCdwpgAccount = ` +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_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_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_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/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..a3e67e7c8e 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -588,6 +588,15 @@
  • tencentcloud_cdwpg_instance
  • +
  • + tencentcloud_cdwpg_reset_account_password +
  • +
  • + tencentcloud_cdwpg_restart_instance +
  • +
  • + tencentcloud_cdwpg_userhba +