From ea3b46cded4c98cb5c5e02b6df60e2be1e13535f Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 8 Jun 2023 17:21:14 +0800 Subject: [PATCH 1/3] feat/support-mariadb-data-source --- .../data_source_tc_mariadb_dcn_detail.go | 358 +++++++++++ .../data_source_tc_mariadb_dcn_detail_test.go | 32 + ...ata_source_tc_mariadb_file_download_url.go | 102 ++++ ...ource_tc_mariadb_file_download_url_test.go | 33 ++ tencentcloud/data_source_tc_mariadb_flow.go | 93 +++ .../data_source_tc_mariadb_flow_test.go | 30 + ...ta_source_tc_mariadb_instance_node_info.go | 121 ++++ ...urce_tc_mariadb_instance_node_info_test.go | 32 + .../data_source_tc_mariadb_instance_specs.go | 200 +++++++ ...a_source_tc_mariadb_instance_specs_test.go | 31 + .../data_source_tc_mariadb_log_files.go | 166 ++++++ .../data_source_tc_mariadb_log_files_test.go | 33 ++ tencentcloud/data_source_tc_mariadb_orders.go | 157 +++++ .../data_source_tc_mariadb_orders_test.go | 32 + tencentcloud/data_source_tc_mariadb_price.go | 172 ++++++ .../data_source_tc_mariadb_price_test.go | 38 ++ ...urce_tc_mariadb_project_security_groups.go | 269 +++++++++ ...tc_mariadb_project_security_groups_test.go | 33 ++ .../data_source_tc_mariadb_renewal_price.go | 119 ++++ ...ta_source_tc_mariadb_renewal_price_test.go | 33 ++ .../data_source_tc_mariadb_sale_info.go | 304 ++++++++++ .../data_source_tc_mariadb_sale_info_test.go | 31 + .../data_source_tc_mariadb_slow_logs.go | 359 +++++++++++ .../data_source_tc_mariadb_slow_logs_test.go | 36 ++ .../data_source_tc_mariadb_upgrade_price.go | 148 +++++ ...ta_source_tc_mariadb_upgrade_price_test.go | 35 ++ tencentcloud/provider.go | 26 + tencentcloud/service_tencentcloud_mariadb.go | 558 ++++++++++++++++++ .../docs/d/mariadb_dcn_detail.html.markdown | 62 ++ .../d/mariadb_file_download_url.html.markdown | 37 ++ website/docs/d/mariadb_flow.html.markdown | 35 ++ .../d/mariadb_instance_specs.html.markdown | 44 ++ .../docs/d/mariadb_log_files.html.markdown | 43 ++ website/docs/d/mariadb_orders.html.markdown | 41 ++ website/docs/d/mariadb_price.html.markdown | 49 ++ ...iadb_project_security_groups.html.markdown | 52 ++ .../d/mariadb_renewal_price.html.markdown | 39 ++ .../docs/d/mariadb_sale_info.html.markdown | 52 ++ .../docs/d/mariadb_slow_logs.html.markdown | 67 +++ .../d/mariadb_upgrade_price.html.markdown | 44 ++ website/tencentcloud.erb | 36 ++ 41 files changed, 4182 insertions(+) create mode 100644 tencentcloud/data_source_tc_mariadb_dcn_detail.go create mode 100644 tencentcloud/data_source_tc_mariadb_dcn_detail_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_file_download_url.go create mode 100644 tencentcloud/data_source_tc_mariadb_file_download_url_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_flow.go create mode 100644 tencentcloud/data_source_tc_mariadb_flow_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_instance_node_info.go create mode 100644 tencentcloud/data_source_tc_mariadb_instance_node_info_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_instance_specs.go create mode 100644 tencentcloud/data_source_tc_mariadb_instance_specs_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_log_files.go create mode 100644 tencentcloud/data_source_tc_mariadb_log_files_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_orders.go create mode 100644 tencentcloud/data_source_tc_mariadb_orders_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_price.go create mode 100644 tencentcloud/data_source_tc_mariadb_price_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_project_security_groups.go create mode 100644 tencentcloud/data_source_tc_mariadb_project_security_groups_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_renewal_price.go create mode 100644 tencentcloud/data_source_tc_mariadb_renewal_price_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_sale_info.go create mode 100644 tencentcloud/data_source_tc_mariadb_sale_info_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_slow_logs.go create mode 100644 tencentcloud/data_source_tc_mariadb_slow_logs_test.go create mode 100644 tencentcloud/data_source_tc_mariadb_upgrade_price.go create mode 100644 tencentcloud/data_source_tc_mariadb_upgrade_price_test.go create mode 100644 website/docs/d/mariadb_dcn_detail.html.markdown create mode 100644 website/docs/d/mariadb_file_download_url.html.markdown create mode 100644 website/docs/d/mariadb_flow.html.markdown create mode 100644 website/docs/d/mariadb_instance_specs.html.markdown create mode 100644 website/docs/d/mariadb_log_files.html.markdown create mode 100644 website/docs/d/mariadb_orders.html.markdown create mode 100644 website/docs/d/mariadb_price.html.markdown create mode 100644 website/docs/d/mariadb_project_security_groups.html.markdown create mode 100644 website/docs/d/mariadb_renewal_price.html.markdown create mode 100644 website/docs/d/mariadb_sale_info.html.markdown create mode 100644 website/docs/d/mariadb_slow_logs.html.markdown create mode 100644 website/docs/d/mariadb_upgrade_price.html.markdown diff --git a/tencentcloud/data_source_tc_mariadb_dcn_detail.go b/tencentcloud/data_source_tc_mariadb_dcn_detail.go new file mode 100644 index 0000000000..2f47de346c --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_dcn_detail.go @@ -0,0 +1,358 @@ +/* +Use this data source to query detailed information of mariadb dcn_detail + +Example Usage + +```hcl +data "tencentcloud_mariadb_dcn_detail" "dcn_detail" { + instance_id = "tdsql-9vqvls95" +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbDcnDetail() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbDcnDetailRead, + Schema: map[string]*schema.Schema{ + "instance_id": { + Required: true, + Type: schema.TypeString, + Description: "Instance ID.", + }, + "dcn_details": { + Computed: true, + Type: schema.TypeList, + Description: "DCN synchronization details.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Computed: true, + Description: "Instance ID.", + }, + "instance_name": { + Type: schema.TypeString, + Computed: true, + Description: "Instance name.", + }, + "region": { + Type: schema.TypeString, + Computed: true, + Description: "Region where the instance resides.", + }, + "zone": { + Type: schema.TypeString, + Computed: true, + Description: "Availability zone where the instance resides.", + }, + "vip": { + Type: schema.TypeString, + Computed: true, + Description: "Instance IP address.", + }, + "vipv6": { + Type: schema.TypeString, + Computed: true, + Description: "Instance IPv6 address.", + }, + "vport": { + Type: schema.TypeInt, + Computed: true, + Description: "Instance port.", + }, + "status": { + Type: schema.TypeInt, + Computed: true, + Description: "Instance status.", + }, + "status_desc": { + Type: schema.TypeString, + Computed: true, + Description: "Instance status description.", + }, + "dcn_flag": { + Type: schema.TypeInt, + Computed: true, + Description: "DCN flag. Valid values: `1` (primary), `2` (disaster recovery).", + }, + "dcn_status": { + Type: schema.TypeInt, + Computed: true, + Description: "DCN status. Valid values: `0` (none), `1` (creating), `2` (syncing), `3` (disconnected).", + }, + "cpu": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of CPU cores of the instance.", + }, + "memory": { + Type: schema.TypeInt, + Computed: true, + Description: "Instance memory capacity in GB.", + }, + "storage": { + Type: schema.TypeInt, + Computed: true, + Description: "Instance storage capacity in GB.", + }, + "pay_mode": { + Type: schema.TypeInt, + Computed: true, + Description: "Billing mode.", + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: "Creation time of the instance in the format of 2006-01-02 15:04:05.", + }, + "period_end_time": { + Type: schema.TypeString, + Computed: true, + Description: "Expiration time of the instance in the format of 2006-01-02 15:04:05.", + }, + "instance_type": { + Type: schema.TypeInt, + Computed: true, + Description: "Instance type. Valid values: `1` (dedicated primary instance), `2` (non-dedicated primary instance), `3` (non-dedicated disaster recovery instance), `4` (dedicated disaster recovery instance).", + }, + "replica_config": { + Type: schema.TypeList, + Computed: true, + Description: "Configuration information of DCN replication. This field is null for a primary instance.Note: This field may return null, indicating that no valid values can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ro_replication_mode": { + Type: schema.TypeString, + Computed: true, + Description: "DCN running status. Valid values: `START` (running), `STOP` (pause)Note: This field may return null, indicating that no valid values can be obtained.", + }, + "delay_replication_type": { + Type: schema.TypeString, + Computed: true, + Description: "Delayed replication type. Valid values: `DEFAULT` (no delay), `DUE_TIME` (specified replication time)Note: This field may return null, indicating that no valid values can be obtained.", + }, + "due_time": { + Type: schema.TypeString, + Computed: true, + Description: "Specified time for delayed replicationNote: This field may return null, indicating that no valid values can be obtained.", + }, + "replication_delay": { + Type: schema.TypeInt, + Computed: true, + Description: "The number of seconds to delay the replicationNote: This field may return null, indicating that no valid values can be obtained.", + }, + }, + }, + }, + "replica_status": { + Type: schema.TypeList, + Computed: true, + Description: "DCN replication status. This field is null for the primary instance.Note: This field may return null, indicating that no valid values can be obtained.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "status": { + Type: schema.TypeString, + Computed: true, + Description: "DCN running status. Valid values: `START` (running), `STOP` (pause).Note: This field may return null, indicating that no valid values can be obtained.", + }, + "delay": { + Type: schema.TypeInt, + Computed: true, + Description: "The current delay, which takes the delay value of the replica instance.", + }, + }, + }, + }, + "encrypt_status": { + Type: schema.TypeInt, + Computed: true, + Description: "Whether KMS is enabled.", + }, + }, + }, + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbDcnDetailRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_dcn_detail.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + dcnDetails []*mariadb.DcnDetailItem + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("instance_id"); ok { + paramMap["InstanceId"] = helper.String(v.(string)) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbDcnDetailByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + + dcnDetails = result + return nil + }) + + if err != nil { + return err + } + + ids := make([]string, 0, len(dcnDetails)) + tmpList := make([]map[string]interface{}, 0, len(dcnDetails)) + + if dcnDetails != nil { + for _, dcnDetailItem := range dcnDetails { + dcnDetailItemMap := map[string]interface{}{} + + if dcnDetailItem.InstanceId != nil { + dcnDetailItemMap["instance_id"] = dcnDetailItem.InstanceId + } + + if dcnDetailItem.InstanceName != nil { + dcnDetailItemMap["instance_name"] = dcnDetailItem.InstanceName + } + + if dcnDetailItem.Region != nil { + dcnDetailItemMap["region"] = dcnDetailItem.Region + } + + if dcnDetailItem.Zone != nil { + dcnDetailItemMap["zone"] = dcnDetailItem.Zone + } + + if dcnDetailItem.Vip != nil { + dcnDetailItemMap["vip"] = dcnDetailItem.Vip + } + + if dcnDetailItem.Vipv6 != nil { + dcnDetailItemMap["vipv6"] = dcnDetailItem.Vipv6 + } + + if dcnDetailItem.Vport != nil { + dcnDetailItemMap["vport"] = dcnDetailItem.Vport + } + + if dcnDetailItem.Status != nil { + dcnDetailItemMap["status"] = dcnDetailItem.Status + } + + if dcnDetailItem.StatusDesc != nil { + dcnDetailItemMap["status_desc"] = dcnDetailItem.StatusDesc + } + + if dcnDetailItem.DcnFlag != nil { + dcnDetailItemMap["dcn_flag"] = dcnDetailItem.DcnFlag + } + + if dcnDetailItem.DcnStatus != nil { + dcnDetailItemMap["dcn_status"] = dcnDetailItem.DcnStatus + } + + if dcnDetailItem.Cpu != nil { + dcnDetailItemMap["cpu"] = dcnDetailItem.Cpu + } + + if dcnDetailItem.Memory != nil { + dcnDetailItemMap["memory"] = dcnDetailItem.Memory + } + + if dcnDetailItem.Storage != nil { + dcnDetailItemMap["storage"] = dcnDetailItem.Storage + } + + if dcnDetailItem.PayMode != nil { + dcnDetailItemMap["pay_mode"] = dcnDetailItem.PayMode + } + + if dcnDetailItem.CreateTime != nil { + dcnDetailItemMap["create_time"] = dcnDetailItem.CreateTime + } + + if dcnDetailItem.PeriodEndTime != nil { + dcnDetailItemMap["period_end_time"] = dcnDetailItem.PeriodEndTime + } + + if dcnDetailItem.InstanceType != nil { + dcnDetailItemMap["instance_type"] = dcnDetailItem.InstanceType + } + + if dcnDetailItem.ReplicaConfig != nil { + replicaConfigMap := map[string]interface{}{} + + if dcnDetailItem.ReplicaConfig.RoReplicationMode != nil { + replicaConfigMap["ro_replication_mode"] = dcnDetailItem.ReplicaConfig.RoReplicationMode + } + + if dcnDetailItem.ReplicaConfig.DelayReplicationType != nil { + replicaConfigMap["delay_replication_type"] = dcnDetailItem.ReplicaConfig.DelayReplicationType + } + + if dcnDetailItem.ReplicaConfig.DueTime != nil { + replicaConfigMap["due_time"] = dcnDetailItem.ReplicaConfig.DueTime + } + + if dcnDetailItem.ReplicaConfig.ReplicationDelay != nil { + replicaConfigMap["replication_delay"] = dcnDetailItem.ReplicaConfig.ReplicationDelay + } + + dcnDetailItemMap["replica_config"] = []interface{}{replicaConfigMap} + } + + if dcnDetailItem.ReplicaStatus != nil { + replicaStatusMap := map[string]interface{}{} + + if dcnDetailItem.ReplicaStatus.Status != nil { + replicaStatusMap["status"] = dcnDetailItem.ReplicaStatus.Status + } + + if dcnDetailItem.ReplicaStatus.Delay != nil { + replicaStatusMap["delay"] = dcnDetailItem.ReplicaStatus.Delay + } + + dcnDetailItemMap["replica_status"] = []interface{}{replicaStatusMap} + } + + if dcnDetailItem.EncryptStatus != nil { + dcnDetailItemMap["encrypt_status"] = dcnDetailItem.EncryptStatus + } + + ids = append(ids, *dcnDetailItem.InstanceId) + tmpList = append(tmpList, dcnDetailItemMap) + } + + _ = d.Set("dcn_details", tmpList) + } + + d.SetId(helper.DataResourceIdsHash(ids)) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), tmpList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_dcn_detail_test.go b/tencentcloud/data_source_tc_mariadb_dcn_detail_test.go new file mode 100644 index 0000000000..76a4b8cf6b --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_dcn_detail_test.go @@ -0,0 +1,32 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudMariadbDcnDetailDataSource_basic -v +func TestAccTencentCloudMariadbDcnDetailDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbDcnDetailDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_dcn_detail.dcn_detail"), + ), + }, + }, + }) +} + +const testAccMariadbDcnDetailDataSource = ` +data "tencentcloud_mariadb_dcn_detail" "dcn_detail" { + instance_id = "tdsql-9vqvls95" +} +` diff --git a/tencentcloud/data_source_tc_mariadb_file_download_url.go b/tencentcloud/data_source_tc_mariadb_file_download_url.go new file mode 100644 index 0000000000..4f2ecddf76 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_file_download_url.go @@ -0,0 +1,102 @@ +/* +Use this data source to query detailed information of mariadb file_download_url + +Example Usage + +```hcl +data "tencentcloud_mariadb_file_download_url" "file_download_url" { + instance_id = "tdsql-9vqvls95" + file_path = "/cos_backup/test.txt" +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbFileDownloadUrl() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbFileDownloadUrlRead, + Schema: map[string]*schema.Schema{ + "instance_id": { + Required: true, + Type: schema.TypeString, + Description: "Instance ID.", + }, + "file_path": { + Required: true, + Type: schema.TypeString, + Description: "Unsigned file path.", + }, + "pre_signed_url": { + Computed: true, + Type: schema.TypeString, + Description: "Signed download URL.", + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbFileDownloadUrlRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_file_download_url.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + responseParams *mariadb.DescribeFileDownloadUrlResponseParams + instanceId string + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("instance_id"); ok { + paramMap["InstanceId"] = helper.String(v.(string)) + instanceId = v.(string) + } + + if v, ok := d.GetOk("file_path"); ok { + paramMap["FilePath"] = helper.String(v.(string)) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbFileDownloadUrlByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + + responseParams = result + return nil + }) + + if err != nil { + return err + } + + if responseParams.PreSignedUrl != nil { + _ = d.Set("pre_signed_url", responseParams.PreSignedUrl) + } + + d.SetId(instanceId) + + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), d); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_file_download_url_test.go b/tencentcloud/data_source_tc_mariadb_file_download_url_test.go new file mode 100644 index 0000000000..fcce751fab --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_file_download_url_test.go @@ -0,0 +1,33 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudNeedFixMariadbFileDownloadUrlDataSource_basic -v +func TestAccTencentCloudNeedFixMariadbFileDownloadUrlDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbFileDownloadUrlDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_file_download_url.file_download_url"), + ), + }, + }, + }) +} + +const testAccMariadbFileDownloadUrlDataSource = ` +data "tencentcloud_mariadb_file_download_url" "file_download_url" { + instance_id = "tdsql-9vqvls95" + file_path = "/cos_backup/test.txt" +} +` diff --git a/tencentcloud/data_source_tc_mariadb_flow.go b/tencentcloud/data_source_tc_mariadb_flow.go new file mode 100644 index 0000000000..667bea3146 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_flow.go @@ -0,0 +1,93 @@ +/* +Use this data source to query detailed information of mariadb flow + +Example Usage + +```hcl +data "tencentcloud_mariadb_flow" "flow" { + flow_id = 1307 +} +``` +*/ +package tencentcloud + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbFlow() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbFlowRead, + Schema: map[string]*schema.Schema{ + "flow_id": { + Required: true, + Type: schema.TypeInt, + Description: "Flow ID returned by async request API.", + }, + "status": { + Computed: true, + Type: schema.TypeInt, + Description: "Flow status. 0: succeeded, 1: failed, 2: running.", + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbFlowRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_flow.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + status *mariadb.DescribeFlowResponseParams + flowId int + ) + + paramMap := make(map[string]interface{}) + if v, _ := d.GetOk("flow_id"); v != nil { + paramMap["FlowId"] = helper.IntInt64(v.(int)) + flowId = v.(int) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbFlowByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + + status = result + return nil + }) + + if err != nil { + return err + } + + if status.Status != nil { + _ = d.Set("status", status.Status) + } + + d.SetId(strconv.Itoa(flowId)) + + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), d); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_flow_test.go b/tencentcloud/data_source_tc_mariadb_flow_test.go new file mode 100644 index 0000000000..fafb2a6b48 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_flow_test.go @@ -0,0 +1,30 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudNeedFixMariadbFlowDataSource_basic -v +func TestAccTencentCloudNeedFixMariadbFlowDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbFlowDataSource, + Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_flow.flow")), + }, + }, + }) +} + +const testAccMariadbFlowDataSource = ` +data "tencentcloud_mariadb_flow" "flow" { + flow_id = 1307 +} +` diff --git a/tencentcloud/data_source_tc_mariadb_instance_node_info.go b/tencentcloud/data_source_tc_mariadb_instance_node_info.go new file mode 100644 index 0000000000..6176308261 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_instance_node_info.go @@ -0,0 +1,121 @@ +/* +Use this data source to query detailed information of mariadb instance_node_info + +Example Usage + +```hcl +data "tencentcloud_mariadb_instance_node_info" "instance_node_info" { + instance_id = "tdsql-9vqvls95" +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbInstanceNodeInfo() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbInstanceNodeInfoRead, + Schema: map[string]*schema.Schema{ + "instance_id": { + Required: true, + Type: schema.TypeString, + Description: "Instance ID, such as tdsql-6ltok4u9.", + }, + "nodes_info": { + Computed: true, + Type: schema.TypeList, + Description: "Node information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "node_id": { + Type: schema.TypeString, + Computed: true, + Description: "Node ID.", + }, + "role": { + Type: schema.TypeString, + Computed: true, + Description: "Node role. Valid values: `master`, `slave`.", + }, + }, + }, + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbInstanceNodeInfoRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_instance_node_info.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + nodesInfo []*mariadb.NodeInfo + instanceId string + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("instance_id"); ok { + paramMap["InstanceId"] = helper.String(v.(string)) + instanceId = v.(string) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbInstanceNodeInfoByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + + nodesInfo = result + return nil + }) + + if err != nil { + return err + } + + tmpList := make([]map[string]interface{}, 0, len(nodesInfo)) + + if nodesInfo != nil { + for _, nodeInfo := range nodesInfo { + nodeInfoMap := map[string]interface{}{} + + if nodeInfo.NodeId != nil { + nodeInfoMap["node_id"] = nodeInfo.NodeId + } + + if nodeInfo.Role != nil { + nodeInfoMap["role"] = nodeInfo.Role + } + + tmpList = append(tmpList, nodeInfoMap) + } + + _ = d.Set("nodes_info", tmpList) + } + + d.SetId(instanceId) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), tmpList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_instance_node_info_test.go b/tencentcloud/data_source_tc_mariadb_instance_node_info_test.go new file mode 100644 index 0000000000..819a4e7e14 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_instance_node_info_test.go @@ -0,0 +1,32 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudMariadbInstanceNodeInfoDataSource_basic -v +func TestAccTencentCloudMariadbInstanceNodeInfoDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbInstanceNodeInfoDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_instance_node_info.instance_node_info"), + ), + }, + }, + }) +} + +const testAccMariadbInstanceNodeInfoDataSource = ` +data "tencentcloud_mariadb_instance_node_info" "instance_node_info" { + instance_id = "tdsql-9vqvls95" +} +` diff --git a/tencentcloud/data_source_tc_mariadb_instance_specs.go b/tencentcloud/data_source_tc_mariadb_instance_specs.go new file mode 100644 index 0000000000..d6070ccfe2 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_instance_specs.go @@ -0,0 +1,200 @@ +/* +Use this data source to query detailed information of mariadb instance_specs + +Example Usage + +```hcl +data "tencentcloud_mariadb_instance_specs" "instance_specs" { +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbInstanceSpecs() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbInstanceSpecsRead, + Schema: map[string]*schema.Schema{ + "specs": { + Computed: true, + Type: schema.TypeList, + Description: "list of instance specifications.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "machine": { + Type: schema.TypeString, + Computed: true, + Description: "machine type.", + }, + "spec_infos": { + Type: schema.TypeList, + Computed: true, + Description: "list of machine specifications.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "machine": { + Type: schema.TypeString, + Computed: true, + Description: "machine type.", + }, + "memory": { + Type: schema.TypeInt, + Computed: true, + Description: "memory, in GB.", + }, + "min_storage": { + Type: schema.TypeInt, + Computed: true, + Description: "minimum storage size, in GB.", + }, + "max_storage": { + Type: schema.TypeInt, + Computed: true, + Description: "maximum storage size, in GB.", + }, + "suit_info": { + Type: schema.TypeString, + Computed: true, + Description: "recommended usage scenarios.", + }, + "qps": { + Type: schema.TypeInt, + Computed: true, + Description: "maximum QPS.", + }, + "pid": { + Type: schema.TypeInt, + Computed: true, + Description: "product price id.", + }, + "node_count": { + Type: schema.TypeInt, + Computed: true, + Description: "node count.", + }, + "cpu": { + Type: schema.TypeInt, + Computed: true, + Description: "CPU cores.", + }, + }, + }, + }, + }, + }, + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbInstanceSpecsRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_instance_specs.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + specs []*mariadb.InstanceSpec + ) + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbInstanceSpecsByFilter(ctx) + if e != nil { + return retryError(e) + } + + specs = result + return nil + }) + + if err != nil { + return err + } + + ids := make([]string, 0, len(specs)) + tmpList := make([]map[string]interface{}, 0, len(specs)) + if specs != nil { + for _, instanceSpec := range specs { + instanceSpecMap := map[string]interface{}{} + + if instanceSpec.Machine != nil { + instanceSpecMap["machine"] = instanceSpec.Machine + } + + if instanceSpec.SpecInfos != nil { + specInfosList := []interface{}{} + for _, specInfos := range instanceSpec.SpecInfos { + specInfosMap := map[string]interface{}{} + + if specInfos.Machine != nil { + specInfosMap["machine"] = specInfos.Machine + } + + if specInfos.Memory != nil { + specInfosMap["memory"] = specInfos.Memory + } + + if specInfos.MinStorage != nil { + specInfosMap["min_storage"] = specInfos.MinStorage + } + + if specInfos.MaxStorage != nil { + specInfosMap["max_storage"] = specInfos.MaxStorage + } + + if specInfos.SuitInfo != nil { + specInfosMap["suit_info"] = specInfos.SuitInfo + } + + if specInfos.Qps != nil { + specInfosMap["qps"] = specInfos.Qps + } + + if specInfos.Pid != nil { + specInfosMap["pid"] = specInfos.Pid + } + + if specInfos.NodeCount != nil { + specInfosMap["node_count"] = specInfos.NodeCount + } + + if specInfos.Cpu != nil { + specInfosMap["cpu"] = specInfos.Cpu + } + + specInfosList = append(specInfosList, specInfosMap) + } + + instanceSpecMap["spec_infos"] = specInfosList + } + + ids = append(ids, *instanceSpec.Machine) + tmpList = append(tmpList, instanceSpecMap) + } + _ = d.Set("specs", tmpList) + } + + d.SetId(helper.DataResourceIdsHash(ids)) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), tmpList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_instance_specs_test.go b/tencentcloud/data_source_tc_mariadb_instance_specs_test.go new file mode 100644 index 0000000000..20961abadd --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_instance_specs_test.go @@ -0,0 +1,31 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudMariadbInstanceSpecsDataSource_basic -v +func TestAccTencentCloudMariadbInstanceSpecsDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbInstanceSpecsDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_instance_specs.instance_specs"), + ), + }, + }, + }) +} + +const testAccMariadbInstanceSpecsDataSource = ` +data "tencentcloud_mariadb_instance_specs" "instance_specs" { +} +` diff --git a/tencentcloud/data_source_tc_mariadb_log_files.go b/tencentcloud/data_source_tc_mariadb_log_files.go new file mode 100644 index 0000000000..8da627d221 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_log_files.go @@ -0,0 +1,166 @@ +/* +Use this data source to query detailed information of mariadb log_files + +Example Usage + +```hcl +data "tencentcloud_mariadb_log_files" "log_files" { + instance_id = "tdsql-9vqvls95" + type = 1 +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbLogFiles() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbLogFilesRead, + Schema: map[string]*schema.Schema{ + "instance_id": { + Required: true, + Type: schema.TypeString, + Description: "Instance ID in the format of `tdsql-ow728lmc`.", + }, + "type": { + Required: true, + Type: schema.TypeInt, + Description: "Requested log type. Valid values: 1 (binlog), 2 (cold backup), 3 (errlog), 4 (slowlog).", + }, + "files": { + Computed: true, + Type: schema.TypeList, + Description: "Information such as `uri`, `length`, and `mtime` (modification time).", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "mtime": { + Type: schema.TypeInt, + Computed: true, + Description: "Last modified time of log.", + }, + "length": { + Type: schema.TypeInt, + Computed: true, + Description: "File length.", + }, + "uri": { + Type: schema.TypeString, + Computed: true, + Description: "Uniform resource identifier (URI) used during log download.", + }, + "file_name": { + Type: schema.TypeString, + Computed: true, + Description: "Filename.", + }, + }, + }, + }, + "vpc_prefix": { + Computed: true, + Type: schema.TypeString, + Description: "For an instance in a VPC, this prefix plus URI can be used as the download address.", + }, + "normal_prefix": { + Computed: true, + Type: schema.TypeString, + Description: "For an instance in a common network, this prefix plus URI can be used as the download address.", + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbLogFilesRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_log_files.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + logFiles *mariadb.DescribeDBLogFilesResponseParams + instanceId string + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("instance_id"); ok { + paramMap["InstanceId"] = helper.String(v.(string)) + instanceId = v.(string) + } + + if v, ok := d.GetOkExists("type"); ok { + paramMap["Type"] = helper.IntUint64(v.(int)) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbLogFilesByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + + logFiles = result + return nil + }) + + if err != nil { + return err + } + + tmpList := make([]map[string]interface{}, 0) + if logFiles != nil { + for _, logFileInfo := range logFiles.Files { + logFileInfoMap := map[string]interface{}{} + + if logFileInfo.Mtime != nil { + logFileInfoMap["mtime"] = logFileInfo.Mtime + } + + if logFileInfo.Length != nil { + logFileInfoMap["length"] = logFileInfo.Length + } + + if logFileInfo.Uri != nil { + logFileInfoMap["uri"] = logFileInfo.Uri + } + + if logFileInfo.FileName != nil { + logFileInfoMap["file_name"] = logFileInfo.FileName + } + + tmpList = append(tmpList, logFileInfoMap) + } + + _ = d.Set("files", tmpList) + + if logFiles.VpcPrefix != nil { + _ = d.Set("vpc_prefix", logFiles.VpcPrefix) + } + + if logFiles.NormalPrefix != nil { + _ = d.Set("normal_prefix", logFiles.NormalPrefix) + } + } + + d.SetId(instanceId) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), d); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_log_files_test.go b/tencentcloud/data_source_tc_mariadb_log_files_test.go new file mode 100644 index 0000000000..dc311b1301 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_log_files_test.go @@ -0,0 +1,33 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudMariadbLogFilesDataSource_basic -v +func TestAccTencentCloudMariadbLogFilesDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbLogFilesDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_log_files.log_files"), + ), + }, + }, + }) +} + +const testAccMariadbLogFilesDataSource = ` +data "tencentcloud_mariadb_log_files" "log_files" { + instance_id = "tdsql-9vqvls95" + type = 1 +} +` diff --git a/tencentcloud/data_source_tc_mariadb_orders.go b/tencentcloud/data_source_tc_mariadb_orders.go new file mode 100644 index 0000000000..755a0ba8a8 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_orders.go @@ -0,0 +1,157 @@ +/* +Use this data source to query detailed information of mariadb orders + +Example Usage + +```hcl +data "tencentcloud_mariadb_orders" "orders" { + deal_name = "20230607164033835942781" +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" +) + +func dataSourceTencentCloudMariadbOrders() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbOrdersRead, + Schema: map[string]*schema.Schema{ + "deal_name": { + Required: true, + Type: schema.TypeString, + Description: "List of long order numbers to be queried, which are returned for the APIs for creating, renewing, or scaling instances.", + }, + "deals": { + Computed: true, + Type: schema.TypeList, + Description: "Order information list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "deal_name": { + Type: schema.TypeString, + Computed: true, + Description: "Order number.", + }, + "owner_uin": { + Type: schema.TypeString, + Computed: true, + Description: "Account.", + }, + "count": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of items.", + }, + "flow_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the associated process, which can be used to query the process execution status.", + }, + "instance_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Computed: true, + Description: "The ID of the created instance, which is required only for the order that creates an instance.Note: This field may return null, indicating that no valid values can be obtained.", + }, + "pay_mode": { + Type: schema.TypeInt, + Computed: true, + Description: "Payment mode. Valid values: 0 (postpaid), 1 (prepaid).", + }, + }, + }, + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbOrdersRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_orders.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + deals []*mariadb.Deal + dealName string + ) + + if v, ok := d.GetOk("deal_name"); ok { + dealName = v.(string) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbOrdersByFilter(ctx, dealName) + if e != nil { + return retryError(e) + } + + deals = result + return nil + }) + + if err != nil { + return err + } + + tmpList := make([]map[string]interface{}, 0, len(deals)) + + if deals != nil { + for _, deal := range deals { + dealMap := map[string]interface{}{} + + if deal.DealName != nil { + dealMap["deal_name"] = deal.DealName + } + + if deal.OwnerUin != nil { + dealMap["owner_uin"] = deal.OwnerUin + } + + if deal.Count != nil { + dealMap["count"] = deal.Count + } + + if deal.FlowId != nil { + dealMap["flow_id"] = deal.FlowId + } + + if deal.InstanceIds != nil { + dealMap["instance_ids"] = deal.InstanceIds + } + + if deal.PayMode != nil { + dealMap["pay_mode"] = deal.PayMode + } + + tmpList = append(tmpList, dealMap) + } + + _ = d.Set("deals", tmpList) + } + + d.SetId(dealName) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), tmpList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_orders_test.go b/tencentcloud/data_source_tc_mariadb_orders_test.go new file mode 100644 index 0000000000..179e4ddb61 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_orders_test.go @@ -0,0 +1,32 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudMariadbOrdersDataSource_basic -v +func TestAccTencentCloudMariadbOrdersDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbOrdersDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_orders.orders"), + ), + }, + }, + }) +} + +const testAccMariadbOrdersDataSource = ` +data "tencentcloud_mariadb_orders" "orders" { + deal_name = "20230607164033835942781" +} +` diff --git a/tencentcloud/data_source_tc_mariadb_price.go b/tencentcloud/data_source_tc_mariadb_price.go new file mode 100644 index 0000000000..bac81d0ab3 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_price.go @@ -0,0 +1,172 @@ +/* +Use this data source to query detailed information of mariadb price + +Example Usage + +```hcl +data "tencentcloud_mariadb_price" "price" { + zone = "ap-guangzhou-3" + node_count = 2 + memory = 2 + storage = 20 + buy_count = 1 + period = 1 + paymode = "prepaid" +} +``` +*/ +package tencentcloud + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbPrice() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbPriceRead, + Schema: map[string]*schema.Schema{ + "zone": { + Required: true, + Type: schema.TypeString, + Description: "AZ ID of the purchased instance.", + }, + "node_count": { + Required: true, + Type: schema.TypeInt, + Description: "Number of instance nodes, which can be obtained by querying the instance specification through the `DescribeDBInstanceSpecs` API.", + }, + "memory": { + Required: true, + Type: schema.TypeInt, + Description: "Memory size in GB, which can be obtained by querying the instance specification through the `DescribeDBInstanceSpecs` API.", + }, + "storage": { + Required: true, + Type: schema.TypeInt, + Description: "Storage capacity in GB. The maximum and minimum storage space can be obtained by querying instance specification through the `DescribeDBInstanceSpecs` API.", + }, + "buy_count": { + Required: true, + Type: schema.TypeInt, + ValidateFunc: validateIntegerMin(1), + Description: "The quantity you want to purchase is queried by default for the price of purchasing 1 instance.", + }, + "period": { + Optional: true, + Type: schema.TypeInt, + Description: "Purchase period in months.", + }, + "paymode": { + Optional: true, + Type: schema.TypeString, + Description: "Billing type. Valid values: `postpaid` (pay-as-you-go), `prepaid` (monthly subscription).", + }, + "amount_unit": { + Optional: true, + Type: schema.TypeString, + Description: "Price unit. Valid values: `* pent` (cent), `* microPent` (microcent).", + }, + "original_price": { + Computed: true, + Type: schema.TypeInt, + Description: "Original price * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site).", + }, + "price": { + Computed: true, + Type: schema.TypeInt, + Description: "The actual price may be different from the original price due to discounts. * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site).", + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbPriceRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_price.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + price *mariadb.DescribePriceResponseParams + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("zone"); ok { + paramMap["Zone"] = helper.String(v.(string)) + } + + if v, _ := d.GetOk("node_count"); v != nil { + paramMap["NodeCount"] = helper.IntInt64(v.(int)) + } + + if v, _ := d.GetOk("memory"); v != nil { + paramMap["Memory"] = helper.IntInt64(v.(int)) + } + + if v, _ := d.GetOk("storage"); v != nil { + paramMap["Storage"] = helper.IntInt64(v.(int)) + } + + if v, _ := d.GetOk("buy_count"); v != nil { + paramMap["Count"] = helper.IntInt64(v.(int)) + } + + if v, _ := d.GetOk("period"); v != nil { + paramMap["Period"] = helper.IntInt64(v.(int)) + } + + if v, ok := d.GetOk("paymode"); ok { + paramMap["Paymode"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("amount_unit"); ok { + paramMap["AmountUnit"] = helper.String(v.(string)) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbPriceByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + + price = result + return nil + }) + + if err != nil { + return err + } + + ids := make([]string, 0) + if price.OriginalPrice != nil { + _ = d.Set("original_price", price.OriginalPrice) + ids = append(ids, strconv.Itoa(int(*price.OriginalPrice))) + } + + if price.Price != nil { + _ = d.Set("price", price.Price) + ids = append(ids, strconv.Itoa(int(*price.Price))) + } + + d.SetId(helper.DataResourceIdsHash(ids)) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), d); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_price_test.go b/tencentcloud/data_source_tc_mariadb_price_test.go new file mode 100644 index 0000000000..bbbeb839f6 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_price_test.go @@ -0,0 +1,38 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudMariadbPriceDataSource_basic -v +func TestAccTencentCloudMariadbPriceDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbPriceDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_price.price"), + ), + }, + }, + }) +} + +const testAccMariadbPriceDataSource = ` +data "tencentcloud_mariadb_price" "price" { + zone = "ap-guangzhou-3" + node_count = 2 + memory = 2 + storage = 20 + buy_count = 1 + period = 1 + paymode = "prepaid" +} +` diff --git a/tencentcloud/data_source_tc_mariadb_project_security_groups.go b/tencentcloud/data_source_tc_mariadb_project_security_groups.go new file mode 100644 index 0000000000..5031723c8b --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_project_security_groups.go @@ -0,0 +1,269 @@ +/* +Use this data source to query detailed information of mariadb project_security_groups + +Example Usage + +```hcl +data "tencentcloud_mariadb_project_security_groups" "project_security_groups" { + product = "mariadb" + project_id = 0 +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbProjectSecurityGroups() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbProjectSecurityGroupsRead, + Schema: map[string]*schema.Schema{ + "product": { + Required: true, + Type: schema.TypeString, + Description: "Database engine name. Valid value: `mariadb`.", + }, + "project_id": { + Optional: true, + Type: schema.TypeInt, + Description: "Project ID.", + }, + "groups": { + Computed: true, + Type: schema.TypeList, + Description: "Security group details.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "project_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Project ID.", + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: "Creation time in the format of yyyy-mm-dd hh:mm:ss.", + }, + "security_group_id": { + Type: schema.TypeString, + Computed: true, + Description: "Security group ID.", + }, + "security_group_name": { + Type: schema.TypeString, + Computed: true, + Description: "Security group name.", + }, + "security_group_remark": { + Type: schema.TypeString, + Computed: true, + Description: "Security group remarks.", + }, + "inbound": { + Type: schema.TypeList, + Computed: true, + Description: "Inbound rule.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Computed: true, + Description: "Policy, which can be `ACCEPT` or `DROP`.", + }, + "cidr_ip": { + Type: schema.TypeString, + Computed: true, + Description: "Source IP or source IP range, such as 192.168.0.0/16.", + }, + "port_range": { + Type: schema.TypeString, + Computed: true, + Description: "Port.", + }, + "ip_protocol": { + Type: schema.TypeString, + Computed: true, + Description: "Network protocol. UDP and TCP are supported.", + }, + }, + }, + }, + "outbound": { + Type: schema.TypeList, + Computed: true, + Description: "Outbound rule.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Computed: true, + Description: "Policy, which can be `ACCEPT` or `DROP`.", + }, + "cidr_ip": { + Type: schema.TypeString, + Computed: true, + Description: "Source IP or source IP range, such as 192.168.0.0/16.", + }, + "port_range": { + Type: schema.TypeString, + Computed: true, + Description: "Port.", + }, + "ip_protocol": { + Type: schema.TypeString, + Computed: true, + Description: "Network protocol. UDP and TCP are supported.", + }, + }, + }, + }, + }, + }, + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbProjectSecurityGroupsRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_project_security_groups.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + groups []*mariadb.SecurityGroup + Product string + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("product"); ok { + paramMap["Product"] = helper.String(v.(string)) + Product = v.(string) + } + + if v, _ := d.GetOk("project_id"); v != nil { + paramMap["ProjectId"] = helper.IntInt64(v.(int)) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbProjectSecurityGroupsByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + + groups = result + return nil + }) + + if err != nil { + return err + } + + tmpList := make([]map[string]interface{}, 0, len(groups)) + + if groups != nil { + for _, securityGroup := range groups { + securityGroupMap := map[string]interface{}{} + + if securityGroup.ProjectId != nil { + securityGroupMap["project_id"] = securityGroup.ProjectId + } + + if securityGroup.CreateTime != nil { + securityGroupMap["create_time"] = securityGroup.CreateTime + } + + if securityGroup.SecurityGroupId != nil { + securityGroupMap["security_group_id"] = securityGroup.SecurityGroupId + } + + if securityGroup.SecurityGroupName != nil { + securityGroupMap["security_group_name"] = securityGroup.SecurityGroupName + } + + if securityGroup.SecurityGroupRemark != nil { + securityGroupMap["security_group_remark"] = securityGroup.SecurityGroupRemark + } + + if securityGroup.Inbound != nil { + inboundList := []interface{}{} + for _, inbound := range securityGroup.Inbound { + inboundMap := map[string]interface{}{} + + if inbound.Action != nil { + inboundMap["action"] = inbound.Action + } + + if inbound.CidrIp != nil { + inboundMap["cidr_ip"] = inbound.CidrIp + } + + if inbound.PortRange != nil { + inboundMap["port_range"] = inbound.PortRange + } + + if inbound.IpProtocol != nil { + inboundMap["ip_protocol"] = inbound.IpProtocol + } + + inboundList = append(inboundList, inboundMap) + } + + securityGroupMap["inbound"] = inboundList + } + + if securityGroup.Outbound != nil { + outboundList := []interface{}{} + for _, outbound := range securityGroup.Outbound { + outboundMap := map[string]interface{}{} + + if outbound.Action != nil { + outboundMap["action"] = outbound.Action + } + + if outbound.CidrIp != nil { + outboundMap["cidr_ip"] = outbound.CidrIp + } + + if outbound.PortRange != nil { + outboundMap["port_range"] = outbound.PortRange + } + + if outbound.IpProtocol != nil { + outboundMap["ip_protocol"] = outbound.IpProtocol + } + + outboundList = append(outboundList, outboundMap) + } + + securityGroupMap["outbound"] = outboundList + } + tmpList = append(tmpList, securityGroupMap) + } + + _ = d.Set("groups", tmpList) + } + + d.SetId(Product) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), tmpList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_project_security_groups_test.go b/tencentcloud/data_source_tc_mariadb_project_security_groups_test.go new file mode 100644 index 0000000000..dbda9393b7 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_project_security_groups_test.go @@ -0,0 +1,33 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudMariadbProjectSecurityGroupsDataSource_basic -v +func TestAccTencentCloudMariadbProjectSecurityGroupsDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbProjectSecurityGroupsDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_project_security_groups.project_security_groups"), + ), + }, + }, + }) +} + +const testAccMariadbProjectSecurityGroupsDataSource = ` +data "tencentcloud_mariadb_project_security_groups" "project_security_groups" { + product = "mariadb" + project_id = 0 +} +` diff --git a/tencentcloud/data_source_tc_mariadb_renewal_price.go b/tencentcloud/data_source_tc_mariadb_renewal_price.go new file mode 100644 index 0000000000..90f746ce8b --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_renewal_price.go @@ -0,0 +1,119 @@ +/* +Use this data source to query detailed information of mariadb renewal_price + +Example Usage + +```hcl +data "tencentcloud_mariadb_renewal_price" "renewal_price" { + instance_id = "tdsql-9vqvls95" + period = 2 +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbRenewalPrice() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbRenewalPriceRead, + Schema: map[string]*schema.Schema{ + "instance_id": { + Required: true, + Type: schema.TypeString, + Description: "Instance ID.", + }, + "period": { + Optional: true, + Type: schema.TypeInt, + Description: "Renewal duration, default: 1 month.", + }, + "amount_unit": { + Optional: true, + Type: schema.TypeString, + Description: "Price unit. Valid values: `* pent` (cent), `* microPent` (microcent).", + }, + "original_price": { + Computed: true, + Type: schema.TypeInt, + Description: "Original price * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site).", + }, + "price": { + Computed: true, + Type: schema.TypeInt, + Description: "The actual price may be different from the original price due to discounts. * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site).", + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbRenewalPriceRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_renewal_price.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + price *mariadb.DescribeRenewalPriceResponseParams + instanceId string + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("instance_id"); ok { + paramMap["InstanceId"] = helper.String(v.(string)) + instanceId = v.(string) + } + + if v, _ := d.GetOk("period"); v != nil { + paramMap["Period"] = helper.IntInt64(v.(int)) + } + + if v, ok := d.GetOk("amount_unit"); ok { + paramMap["AmountUnit"] = helper.String(v.(string)) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbRenewalPriceByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + + price = result + return nil + }) + + if err != nil { + return err + } + + if price.OriginalPrice != nil { + _ = d.Set("original_price", price.OriginalPrice) + } + + if price.Price != nil { + _ = d.Set("price", price.Price) + } + + d.SetId(instanceId) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), d); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_renewal_price_test.go b/tencentcloud/data_source_tc_mariadb_renewal_price_test.go new file mode 100644 index 0000000000..3005835aba --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_renewal_price_test.go @@ -0,0 +1,33 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudMariadbRenewalPriceDataSource_basic -v +func TestAccTencentCloudMariadbRenewalPriceDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbRenewalPriceDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_renewal_price.renewal_price"), + ), + }, + }, + }) +} + +const testAccMariadbRenewalPriceDataSource = ` +data "tencentcloud_mariadb_renewal_price" "renewal_price" { + instance_id = "tdsql-9vqvls95" + period = 2 +} +` diff --git a/tencentcloud/data_source_tc_mariadb_sale_info.go b/tencentcloud/data_source_tc_mariadb_sale_info.go new file mode 100644 index 0000000000..04d70a3fd5 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_sale_info.go @@ -0,0 +1,304 @@ +/* +Use this data source to query detailed information of mariadb sale_info + +Example Usage + +```hcl +data "tencentcloud_mariadb_sale_info" "sale_info" { +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbSaleInfo() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbSaleInfoRead, + Schema: map[string]*schema.Schema{ + "region_list": { + Computed: true, + Type: schema.TypeList, + Description: "list of sale region info.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "region": { + Type: schema.TypeString, + Computed: true, + Description: "region name(en).", + }, + "region_id": { + Type: schema.TypeInt, + Computed: true, + Description: "region id.", + }, + "region_name": { + Type: schema.TypeString, + Computed: true, + Description: "region name(zh).", + }, + "zone_list": { + Type: schema.TypeList, + Computed: true, + Description: "list of az zone.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "zone": { + Type: schema.TypeString, + Computed: true, + Description: "zone name(en).", + }, + "zone_id": { + Type: schema.TypeInt, + Computed: true, + Description: "zone id.", + }, + "zone_name": { + Type: schema.TypeString, + Computed: true, + Description: "zone name(zh).", + }, + "on_sale": { + Type: schema.TypeBool, + Computed: true, + Description: "is zone on sale.", + }, + }, + }, + }, + "available_choice": { + Type: schema.TypeList, + Computed: true, + Description: "available zone choice.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "master_zone": { + Type: schema.TypeList, + Computed: true, + Description: "master zone.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "zone": { + Type: schema.TypeString, + Computed: true, + Description: "zone name(en).", + }, + "zone_id": { + Type: schema.TypeInt, + Computed: true, + Description: "zone id.", + }, + "zone_name": { + Type: schema.TypeString, + Computed: true, + Description: "zone name(zh).", + }, + "on_sale": { + Type: schema.TypeBool, + Computed: true, + Description: "is zone on sale.", + }, + }, + }, + }, + "slave_zones": { + Type: schema.TypeList, + Computed: true, + Description: "slave zones.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "zone": { + Type: schema.TypeString, + Computed: true, + Description: "zone name(en).", + }, + "zone_id": { + Type: schema.TypeInt, + Computed: true, + Description: "zone id.", + }, + "zone_name": { + Type: schema.TypeString, + Computed: true, + Description: "zone name(zh).", + }, + "on_sale": { + Type: schema.TypeBool, + Computed: true, + Description: "is zone on sale.", + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbSaleInfoRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_sale_info.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + regionList []*mariadb.RegionInfo + ) + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbSaleInfoByFilter(ctx) + if e != nil { + return retryError(e) + } + + regionList = result + return nil + }) + + if err != nil { + return err + } + + ids := make([]string, 0, len(regionList)) + tmpList := make([]map[string]interface{}, 0, len(regionList)) + + if regionList != nil { + for _, regionInfo := range regionList { + regionInfoMap := map[string]interface{}{} + + if regionInfo.Region != nil { + regionInfoMap["region"] = regionInfo.Region + } + + if regionInfo.RegionId != nil { + regionInfoMap["region_id"] = regionInfo.RegionId + } + + if regionInfo.RegionName != nil { + regionInfoMap["region_name"] = regionInfo.RegionName + } + + if regionInfo.ZoneList != nil { + zoneListList := []interface{}{} + for _, zoneList := range regionInfo.ZoneList { + zoneListMap := map[string]interface{}{} + + if zoneList.Zone != nil { + zoneListMap["zone"] = zoneList.Zone + } + + if zoneList.ZoneId != nil { + zoneListMap["zone_id"] = zoneList.ZoneId + } + + if zoneList.ZoneName != nil { + zoneListMap["zone_name"] = zoneList.ZoneName + } + + if zoneList.OnSale != nil { + zoneListMap["on_sale"] = zoneList.OnSale + } + + zoneListList = append(zoneListList, zoneListMap) + } + + regionInfoMap["zone_list"] = zoneListList + } + + if regionInfo.AvailableChoice != nil { + availableChoiceList := []interface{}{} + for _, availableChoice := range regionInfo.AvailableChoice { + availableChoiceMap := map[string]interface{}{} + + if availableChoice.MasterZone != nil { + masterZoneList := []interface{}{} + masterZoneMap := map[string]interface{}{} + + if availableChoice.MasterZone.Zone != nil { + masterZoneMap["zone"] = availableChoice.MasterZone.Zone + } + + if availableChoice.MasterZone.ZoneId != nil { + masterZoneMap["zone_id"] = availableChoice.MasterZone.ZoneId + } + + if availableChoice.MasterZone.ZoneName != nil { + masterZoneMap["zone_name"] = availableChoice.MasterZone.ZoneName + } + + if availableChoice.MasterZone.OnSale != nil { + masterZoneMap["on_sale"] = availableChoice.MasterZone.OnSale + } + + masterZoneList = append(masterZoneList, masterZoneMap) + availableChoiceMap["master_zone"] = masterZoneList + } + + if availableChoice.SlaveZones != nil { + slaveZonesList := []interface{}{} + for _, slaveZones := range availableChoice.SlaveZones { + slaveZonesMap := map[string]interface{}{} + + if slaveZones.Zone != nil { + slaveZonesMap["zone"] = slaveZones.Zone + } + + if slaveZones.ZoneId != nil { + slaveZonesMap["zone_id"] = slaveZones.ZoneId + } + + if slaveZones.ZoneName != nil { + slaveZonesMap["zone_name"] = slaveZones.ZoneName + } + + if slaveZones.OnSale != nil { + slaveZonesMap["on_sale"] = slaveZones.OnSale + } + + slaveZonesList = append(slaveZonesList, slaveZonesMap) + } + + availableChoiceMap["slave_zones"] = slaveZonesList + } + + availableChoiceList = append(availableChoiceList, availableChoiceMap) + } + + regionInfoMap["available_choice"] = availableChoiceList + } + + ids = append(ids, *regionInfo.Region) + tmpList = append(tmpList, regionInfoMap) + } + + _ = d.Set("region_list", tmpList) + } + + d.SetId(helper.DataResourceIdsHash(ids)) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), tmpList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_sale_info_test.go b/tencentcloud/data_source_tc_mariadb_sale_info_test.go new file mode 100644 index 0000000000..6a40f81238 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_sale_info_test.go @@ -0,0 +1,31 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudMariadbSaleInfoDataSource_basic -v +func TestAccTencentCloudMariadbSaleInfoDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbSaleInfoDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_sale_info.sale_info"), + ), + }, + }, + }) +} + +const testAccMariadbSaleInfoDataSource = ` +data "tencentcloud_mariadb_sale_info" "sale_info" { +} +` diff --git a/tencentcloud/data_source_tc_mariadb_slow_logs.go b/tencentcloud/data_source_tc_mariadb_slow_logs.go new file mode 100644 index 0000000000..40951937e3 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_slow_logs.go @@ -0,0 +1,359 @@ +/* +Use this data source to query detailed information of mariadb slow_logs + +Example Usage + +```hcl +data "tencentcloud_mariadb_slow_logs" "slow_logs" { + instance_id = "tdsql-9vqvls95" + start_time = "2023-06-01 14:55:20" + order_by = "query_time_sum" + order_by_type = "desc" + slave = 0 +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbSlowLogs() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbSlowLogsRead, + Schema: map[string]*schema.Schema{ + "instance_id": { + Required: true, + Type: schema.TypeString, + Description: "Instance ID in the format of `tdsql-ow728lmc`.", + }, + "start_time": { + Required: true, + Type: schema.TypeString, + Description: "Query start time in the format of 2016-07-23 14:55:20.", + }, + "end_time": { + Optional: true, + Type: schema.TypeString, + Description: "Query end time in the format of 2016-08-22 14:55:20.", + }, + "db": { + Optional: true, + Type: schema.TypeString, + Description: "Specific name of the database to be queried.", + }, + "order_by": { + Optional: true, + Type: schema.TypeString, + Description: "Sorting metric. Valid values: query_time_sum, query_count.", + }, + "order_by_type": { + Optional: true, + Type: schema.TypeString, + Description: "Sorting order. Valid values: desc, asc.", + }, + "slave": { + Optional: true, + Type: schema.TypeInt, + Description: "Query slow queries from either the primary or the replica. Valid values: 0 (primary), 1 (replica).", + }, + "data": { + Computed: true, + Type: schema.TypeList, + Description: "Slow query log data.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "check_sum": { + Type: schema.TypeString, + Computed: true, + Description: "Statement checksum for querying details.", + }, + "db": { + Type: schema.TypeString, + Computed: true, + Description: "Database name.", + }, + "finger_print": { + Type: schema.TypeString, + Computed: true, + Description: "Abstracted SQL statement.", + }, + "lock_time_avg": { + Type: schema.TypeString, + Computed: true, + Description: "Average lock time.", + }, + "lock_time_max": { + Type: schema.TypeString, + Computed: true, + Description: "Maximum lock time.", + }, + "lock_time_min": { + Type: schema.TypeString, + Computed: true, + Description: "Minimum lock time.", + }, + "lock_time_sum": { + Type: schema.TypeString, + Computed: true, + Description: "Total lock time.", + }, + "query_count": { + Type: schema.TypeString, + Computed: true, + Description: "Number of queries.", + }, + "query_time_avg": { + Type: schema.TypeString, + Computed: true, + Description: "Average query time.", + }, + "query_time_max": { + Type: schema.TypeString, + Computed: true, + Description: "Maximum query time.", + }, + "query_time_min": { + Type: schema.TypeString, + Computed: true, + Description: "Minimum query time.", + }, + "query_time_sum": { + Type: schema.TypeString, + Computed: true, + Description: "Total query time.", + }, + "rows_examined_sum": { + Type: schema.TypeString, + Computed: true, + Description: "Number of scanned rows.", + }, + "rows_sent_sum": { + Type: schema.TypeString, + Computed: true, + Description: "Number of sent rows.", + }, + "ts_max": { + Type: schema.TypeString, + Computed: true, + Description: "Last execution time.", + }, + "ts_min": { + Type: schema.TypeString, + Computed: true, + Description: "First execution time.", + }, + "user": { + Type: schema.TypeString, + Computed: true, + Description: "Account.", + }, + "example_sql": { + Type: schema.TypeString, + Computed: true, + Description: "Sample SQLNote: This field may return null, indicating that no valid values can be obtained.", + }, + "host": { + Type: schema.TypeString, + Computed: true, + Description: "Host address of account.", + }, + }, + }, + }, + "lock_time_sum": { + Computed: true, + Type: schema.TypeFloat, + Description: "Total statement lock time.", + }, + "query_count": { + Computed: true, + Type: schema.TypeInt, + Description: "Total number of statement queries.", + }, + "query_time_sum": { + Computed: true, + Type: schema.TypeFloat, + Description: "Total statement query time.", + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbSlowLogsRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_slow_logs.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + data *mariadb.DescribeDBSlowLogsResponseParams + instanceId string + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("instance_id"); ok { + paramMap["InstanceId"] = helper.String(v.(string)) + instanceId = v.(string) + } + + if v, ok := d.GetOk("start_time"); ok { + paramMap["StartTime"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("end_time"); ok { + paramMap["EndTime"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("db"); ok { + paramMap["Db"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("order_by"); ok { + paramMap["OrderBy"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("order_by_type"); ok { + paramMap["OrderByType"] = helper.String(v.(string)) + } + + if v, _ := d.GetOk("slave"); v != nil { + paramMap["Slave"] = helper.IntInt64(v.(int)) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbSlowLogsByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + + data = result + return nil + }) + + if err != nil { + return err + } + + tmpList := make([]map[string]interface{}, 0) + + if data != nil { + for _, slowLogData := range data.Data { + slowLogDataMap := map[string]interface{}{} + + if slowLogData.CheckSum != nil { + slowLogDataMap["check_sum"] = slowLogData.CheckSum + } + + if slowLogData.Db != nil { + slowLogDataMap["db"] = slowLogData.Db + } + + if slowLogData.FingerPrint != nil { + slowLogDataMap["finger_print"] = slowLogData.FingerPrint + } + + if slowLogData.LockTimeAvg != nil { + slowLogDataMap["lock_time_avg"] = slowLogData.LockTimeAvg + } + + if slowLogData.LockTimeMax != nil { + slowLogDataMap["lock_time_max"] = slowLogData.LockTimeMax + } + + if slowLogData.LockTimeMin != nil { + slowLogDataMap["lock_time_min"] = slowLogData.LockTimeMin + } + + if slowLogData.LockTimeSum != nil { + slowLogDataMap["lock_time_sum"] = slowLogData.LockTimeSum + } + + if slowLogData.QueryCount != nil { + slowLogDataMap["query_count"] = slowLogData.QueryCount + } + + if slowLogData.QueryTimeAvg != nil { + slowLogDataMap["query_time_avg"] = slowLogData.QueryTimeAvg + } + + if slowLogData.QueryTimeMax != nil { + slowLogDataMap["query_time_max"] = slowLogData.QueryTimeMax + } + + if slowLogData.QueryTimeMin != nil { + slowLogDataMap["query_time_min"] = slowLogData.QueryTimeMin + } + + if slowLogData.QueryTimeSum != nil { + slowLogDataMap["query_time_sum"] = slowLogData.QueryTimeSum + } + + if slowLogData.RowsExaminedSum != nil { + slowLogDataMap["rows_examined_sum"] = slowLogData.RowsExaminedSum + } + + if slowLogData.RowsSentSum != nil { + slowLogDataMap["rows_sent_sum"] = slowLogData.RowsSentSum + } + + if slowLogData.TsMax != nil { + slowLogDataMap["ts_max"] = slowLogData.TsMax + } + + if slowLogData.TsMin != nil { + slowLogDataMap["ts_min"] = slowLogData.TsMin + } + + if slowLogData.User != nil { + slowLogDataMap["user"] = slowLogData.User + } + + if slowLogData.ExampleSql != nil { + slowLogDataMap["example_sql"] = slowLogData.ExampleSql + } + + if slowLogData.Host != nil { + slowLogDataMap["host"] = slowLogData.Host + } + + tmpList = append(tmpList, slowLogDataMap) + } + + _ = d.Set("data", tmpList) + + if data.LockTimeSum != nil { + _ = d.Set("lock_time_sum", data.LockTimeSum) + } + + if data.QueryCount != nil { + _ = d.Set("query_count", data.QueryCount) + } + + if data.QueryTimeSum != nil { + _ = d.Set("query_time_sum", data.QueryTimeSum) + } + } + + d.SetId(instanceId) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), tmpList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_slow_logs_test.go b/tencentcloud/data_source_tc_mariadb_slow_logs_test.go new file mode 100644 index 0000000000..15c25c6251 --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_slow_logs_test.go @@ -0,0 +1,36 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudMariadbSlowLogsDataSource_basic -v +func TestAccTencentCloudMariadbSlowLogsDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbSlowLogsDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_slow_logs.slow_logs"), + ), + }, + }, + }) +} + +const testAccMariadbSlowLogsDataSource = ` +data "tencentcloud_mariadb_slow_logs" "slow_logs" { + instance_id = "tdsql-9vqvls95" + start_time = "2023-06-01 14:55:20" + order_by = "query_time_sum" + order_by_type = "desc" + slave = 0 +} +` diff --git a/tencentcloud/data_source_tc_mariadb_upgrade_price.go b/tencentcloud/data_source_tc_mariadb_upgrade_price.go new file mode 100644 index 0000000000..0d6ed8ec8a --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_upgrade_price.go @@ -0,0 +1,148 @@ +/* +Use this data source to query detailed information of mariadb upgrade_price + +Example Usage + +```hcl +data "tencentcloud_mariadb_upgrade_price" "upgrade_price" { + instance_id = "tdsql-9vqvls95" + memory = 4 + storage = 40 + node_count = 2 +} +``` +*/ +package tencentcloud + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func dataSourceTencentCloudMariadbUpgradePrice() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudMariadbUpgradePriceRead, + Schema: map[string]*schema.Schema{ + "instance_id": { + Required: true, + Type: schema.TypeString, + Description: "Instance ID.", + }, + "memory": { + Required: true, + Type: schema.TypeInt, + Description: "Memory size in GB, which can be obtained by querying the instance specification through the `DescribeDBInstanceSpecs` API.", + }, + "storage": { + Required: true, + Type: schema.TypeInt, + Description: "Storage capacity in GB. The maximum and minimum storage space can be obtained by querying instance specification through the `DescribeDBInstanceSpecs` API.", + }, + "node_count": { + Optional: true, + Type: schema.TypeInt, + Description: "New instance nodes, zero means not change.", + }, + "amount_unit": { + Optional: true, + Type: schema.TypeString, + Description: "Price unit. Valid values: `* pent` (cent), `* microPent` (microcent).", + }, + "original_price": { + Computed: true, + Type: schema.TypeInt, + Description: "Original price * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site).", + }, + "price": { + Computed: true, + Type: schema.TypeInt, + Description: "The actual price may be different from the original price due to discounts. * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site).", + }, + "formula": { + Computed: true, + Type: schema.TypeString, + Description: "Price calculation formula.", + }, + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudMariadbUpgradePriceRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("data_source.tencentcloud_mariadb_upgrade_price.read")() + defer inconsistentCheck(d, meta)() + + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + service = MariadbService{client: meta.(*TencentCloudClient).apiV3Conn} + price *mariadb.DescribeUpgradePriceResponseParams + instanceId string + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("instance_id"); ok { + paramMap["InstanceId"] = helper.String(v.(string)) + instanceId = v.(string) + } + + if v, _ := d.GetOk("memory"); v != nil { + paramMap["Memory"] = helper.IntInt64(v.(int)) + } + + if v, _ := d.GetOk("storage"); v != nil { + paramMap["Storage"] = helper.IntInt64(v.(int)) + } + + if v, _ := d.GetOk("node_count"); v != nil { + paramMap["NodeCount"] = helper.IntInt64(v.(int)) + } + + if v, ok := d.GetOk("amount_unit"); ok { + paramMap["AmountUnit"] = helper.String(v.(string)) + } + + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeMariadbUpgradePriceByFilter(ctx, paramMap) + if e != nil { + return retryError(e) + } + + price = result + return nil + }) + + if err != nil { + return err + } + + if price.OriginalPrice != nil { + _ = d.Set("original_price", price.OriginalPrice) + } + + if price.Price != nil { + _ = d.Set("price", price.Price) + } + + if price.Formula != nil { + _ = d.Set("formula", price.Formula) + } + + d.SetId(instanceId) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := writeToFile(output.(string), d); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/data_source_tc_mariadb_upgrade_price_test.go b/tencentcloud/data_source_tc_mariadb_upgrade_price_test.go new file mode 100644 index 0000000000..31321d3d6c --- /dev/null +++ b/tencentcloud/data_source_tc_mariadb_upgrade_price_test.go @@ -0,0 +1,35 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudNeedFixMariadbUpgradePriceDataSource_basic -v +func TestAccTencentCloudNeedFixMariadbUpgradePriceDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccMariadbUpgradePriceDataSource, + Check: resource.ComposeTestCheckFunc( + testAccCheckTencentCloudDataSourceID("data.tencentcloud_mariadb_upgrade_price.upgrade_price"), + ), + }, + }, + }) +} + +const testAccMariadbUpgradePriceDataSource = ` +data "tencentcloud_mariadb_upgrade_price" "upgrade_price" { + instance_id = "tdsql-9vqvls95" + memory = 4 + storage = 40 + node_count = 2 +} +` diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index f36b02ee91..9ce29590f1 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1140,6 +1140,19 @@ TencentDB for MariaDB(MariaDB) tencentcloud_mariadb_database_objects tencentcloud_mariadb_databases tencentcloud_mariadb_database_table + tencentcloud_mariadb_dcn_detail + tencentcloud_mariadb_file_download_url + tencentcloud_mariadb_flow + tencentcloud_mariadb_instance_specs + tencentcloud_mariadb_log_files + tencentcloud_mariadb_orders + tencentcloud_mariadb_price + tencentcloud_mariadb_project_security_groups + tencentcloud_mariadb_renewal_price + tencentcloud_mariadb_sale_info + tencentcloud_mariadb_slow_logs + tencentcloud_mariadb_upgrade_price + Resource tencentcloud_mariadb_dedicatedcluster_db_instance tencentcloud_mariadb_instance @@ -1863,6 +1876,19 @@ func Provider() *schema.Provider { "tencentcloud_mariadb_database_objects": dataSourceTencentCloudMariadbDatabaseObjects(), "tencentcloud_mariadb_databases": dataSourceTencentCloudMariadbDatabases(), "tencentcloud_mariadb_database_table": dataSourceTencentCloudMariadbDatabaseTable(), + "tencentcloud_mariadb_dcn_detail": dataSourceTencentCloudMariadbDcnDetail(), + "tencentcloud_mariadb_file_download_url": dataSourceTencentCloudMariadbFileDownloadUrl(), + "tencentcloud_mariadb_flow": dataSourceTencentCloudMariadbFlow(), + "tencentcloud_mariadb_instance_node_info": dataSourceTencentCloudMariadbInstanceNodeInfo(), + "tencentcloud_mariadb_instance_specs": dataSourceTencentCloudMariadbInstanceSpecs(), + "tencentcloud_mariadb_log_files": dataSourceTencentCloudMariadbLogFiles(), + "tencentcloud_mariadb_orders": dataSourceTencentCloudMariadbOrders(), + "tencentcloud_mariadb_price": dataSourceTencentCloudMariadbPrice(), + "tencentcloud_mariadb_project_security_groups": dataSourceTencentCloudMariadbProjectSecurityGroups(), + "tencentcloud_mariadb_renewal_price": dataSourceTencentCloudMariadbRenewalPrice(), + "tencentcloud_mariadb_sale_info": dataSourceTencentCloudMariadbSaleInfo(), + "tencentcloud_mariadb_slow_logs": dataSourceTencentCloudMariadbSlowLogs(), + "tencentcloud_mariadb_upgrade_price": dataSourceTencentCloudMariadbUpgradePrice(), "tencentcloud_tdcpg_clusters": dataSourceTencentCloudTdcpgClusters(), "tencentcloud_tdcpg_instances": dataSourceTencentCloudTdcpgInstances(), "tencentcloud_cat_probe_data": dataSourceTencentCloudCatProbeData(), diff --git a/tencentcloud/service_tencentcloud_mariadb.go b/tencentcloud/service_tencentcloud_mariadb.go index fd27b458dd..e6336e7b87 100644 --- a/tencentcloud/service_tencentcloud_mariadb.go +++ b/tencentcloud/service_tencentcloud_mariadb.go @@ -6,6 +6,7 @@ import ( "log" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312" @@ -142,6 +143,563 @@ func (me *MariadbService) DescribeMariadbDbInstancesByFilter(ctx context.Context return } +func (me *MariadbService) DescribeMariadbDcnDetailByFilter(ctx context.Context, param map[string]interface{}) (dcnDetail []*mariadb.DcnDetailItem, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeDcnDetailRequest() + ) + + 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()) + } + }() + + for k, v := range param { + if k == "InstanceId" { + request.InstanceId = v.(*string) + } + } + + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseMariadbClient().DescribeDcnDetail(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 response == nil { + return + } + + dcnDetail = response.Response.DcnDetails + + return +} + +func (me *MariadbService) DescribeMariadbFileDownloadUrlByFilter(ctx context.Context, param map[string]interface{}) (fileDownloadUrl *mariadb.DescribeFileDownloadUrlResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeFileDownloadUrlRequest() + ) + + 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()) + } + }() + + for k, v := range param { + if k == "InstanceId" { + request.InstanceId = v.(*string) + } + if k == "FilePath" { + request.FilePath = v.(*string) + } + } + + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseMariadbClient().DescribeFileDownloadUrl(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 response == nil { + return + } + + fileDownloadUrl = response.Response + + return +} + +func (me *MariadbService) DescribeMariadbFlowByFilter(ctx context.Context, param map[string]interface{}) (flow *mariadb.DescribeFlowResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeFlowRequest() + ) + + 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()) + } + }() + + for k, v := range param { + if k == "FlowId" { + request.FlowId = v.(*int64) + } + } + + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseMariadbClient().DescribeFlow(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 response == nil { + return + } + + flow = response.Response + + return +} + +func (me *MariadbService) DescribeMariadbInstanceNodeInfoByFilter(ctx context.Context, param map[string]interface{}) (instanceNodeInfo []*mariadb.NodeInfo, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeInstanceNodeInfoRequest() + ) + + 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()) + } + }() + + for k, v := range param { + if k == "InstanceId" { + request.InstanceId = v.(*string) + } + } + + ratelimit.Check(request.GetAction()) + + var ( + offset uint64 = 0 + limit uint64 = 20 + ) + + for { + request.Offset = &offset + request.Limit = &limit + response, err := me.client.UseMariadbClient().DescribeInstanceNodeInfo(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 response == nil || *response.Response.TotalCount == 0 { + break + } + + instanceNodeInfo = append(instanceNodeInfo, response.Response.NodesInfo...) + if len(response.Response.NodesInfo) < int(limit) { + break + } + + offset += limit + } + + return +} + +func (me *MariadbService) DescribeMariadbInstanceSpecsByFilter(ctx context.Context) (instanceSpecs []*mariadb.InstanceSpec, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeDBInstanceSpecsRequest() + ) + + 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.UseMariadbClient().DescribeDBInstanceSpecs(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 response == nil { + return + } + + instanceSpecs = response.Response.Specs + + return +} + +func (me *MariadbService) DescribeMariadbOrdersByFilter(ctx context.Context, dealName string) (orders []*mariadb.Deal, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeOrdersRequest() + ) + + 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()) + } + }() + + request.DealNames = common.StringPtrs([]string{dealName}) + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseMariadbClient().DescribeOrders(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 response == nil || *response.Response.TotalCount == 0 { + return + } + + orders = response.Response.Deals + + return +} + +func (me *MariadbService) DescribeMariadbPriceByFilter(ctx context.Context, param map[string]interface{}) (price *mariadb.DescribePriceResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribePriceRequest() + ) + + 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()) + } + }() + + for k, v := range param { + if k == "Zone" { + request.Zone = v.(*string) + } + if k == "NodeCount" { + request.NodeCount = v.(*int64) + } + if k == "Memory" { + request.Memory = v.(*int64) + } + if k == "Storage" { + request.Storage = v.(*int64) + } + if k == "Count" { + request.Count = v.(*int64) + } + if k == "Period" { + request.Period = v.(*int64) + } + if k == "Paymode" { + request.Paymode = v.(*string) + } + if k == "AmountUnit" { + request.AmountUnit = v.(*string) + } + } + + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseMariadbClient().DescribePrice(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 response == nil { + return + } + + price = response.Response + + return +} + +func (me *MariadbService) DescribeMariadbProjectSecurityGroupsByFilter(ctx context.Context, param map[string]interface{}) (projectSecurityGroups []*mariadb.SecurityGroup, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeProjectSecurityGroupsRequest() + ) + + 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()) + } + }() + + for k, v := range param { + if k == "Product" { + request.Product = v.(*string) + } + if k == "ProjectId" { + request.ProjectId = v.(*int64) + } + } + + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseMariadbClient().DescribeProjectSecurityGroups(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 response == nil || *response.Response.Total == 0 { + return + } + + projectSecurityGroups = response.Response.Groups + + return +} + +func (me *MariadbService) DescribeMariadbRenewalPriceByFilter(ctx context.Context, param map[string]interface{}) (renewalPrice *mariadb.DescribeRenewalPriceResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeRenewalPriceRequest() + ) + + 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()) + } + }() + + for k, v := range param { + if k == "InstanceId" { + request.InstanceId = v.(*string) + } + if k == "Period" { + request.Period = v.(*int64) + } + if k == "AmountUnit" { + request.AmountUnit = v.(*string) + } + } + + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseMariadbClient().DescribeRenewalPrice(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 response == nil { + return + } + + renewalPrice = response.Response + + return +} + +func (me *MariadbService) DescribeMariadbSaleInfoByFilter(ctx context.Context) (saleInfo []*mariadb.RegionInfo, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeSaleInfoRequest() + ) + + 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.UseMariadbClient().DescribeSaleInfo(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 response == nil || len(response.Response.RegionList) < 1 { + return + } + + saleInfo = response.Response.RegionList + + return +} + +func (me *MariadbService) DescribeMariadbSlowLogsByFilter(ctx context.Context, param map[string]interface{}) (slowLogs *mariadb.DescribeDBSlowLogsResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeDBSlowLogsRequest() + ) + + 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()) + } + }() + + for k, v := range param { + if k == "InstanceId" { + request.InstanceId = v.(*string) + } + if k == "StartTime" { + request.StartTime = v.(*string) + } + if k == "EndTime" { + request.EndTime = v.(*string) + } + if k == "Db" { + request.Db = v.(*string) + } + if k == "OrderBy" { + request.OrderBy = v.(*string) + } + if k == "OrderByType" { + request.OrderByType = v.(*string) + } + if k == "Slave" { + request.Slave = v.(*int64) + } + } + + ratelimit.Check(request.GetAction()) + + var ( + offset uint64 = 0 + limit uint64 = 20 + ) + for { + request.Offset = &offset + request.Limit = &limit + response, err := me.client.UseMariadbClient().DescribeDBSlowLogs(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 response == nil || *response.Response.Total == 0 { + break + } + + slowLogs.Data = append(slowLogs.Data, response.Response.Data...) + if len(response.Response.Data) < int(limit) { + break + } + + offset += limit + } + + return +} + +func (me *MariadbService) DescribeMariadbUpgradePriceByFilter(ctx context.Context, param map[string]interface{}) (upgradePrice *mariadb.DescribeUpgradePriceResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeUpgradePriceRequest() + ) + + 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()) + } + }() + + for k, v := range param { + if k == "InstanceId" { + request.InstanceId = v.(*string) + } + if k == "Memory" { + request.Memory = v.(*int64) + } + if k == "Storage" { + request.Storage = v.(*int64) + } + if k == "NodeCount" { + request.NodeCount = v.(*int64) + } + if k == "AmountUnit" { + request.AmountUnit = v.(*string) + } + } + + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseMariadbClient().DescribeUpgradePrice(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 response == nil { + return + } + + upgradePrice = response.Response + + return +} + +func (me *MariadbService) DescribeMariadbLogFilesByFilter(ctx context.Context, param map[string]interface{}) (logFiles *mariadb.DescribeDBLogFilesResponseParams, errRet error) { + var ( + logId = getLogId(ctx) + request = mariadb.NewDescribeDBLogFilesRequest() + ) + + 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()) + } + }() + + for k, v := range param { + if k == "InstanceId" { + request.InstanceId = v.(*string) + } + if k == "Type" { + request.Type = v.(*uint64) + } + } + + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseMariadbClient().DescribeDBLogFiles(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 response == nil { + return + } + + logFiles = response.Response + + return +} + func (me *MariadbService) DescribeMariadbDbInstance(ctx context.Context, instanceId string) (dbInstance *mariadb.DBInstance, errRet error) { var ( logId = getLogId(ctx) diff --git a/website/docs/d/mariadb_dcn_detail.html.markdown b/website/docs/d/mariadb_dcn_detail.html.markdown new file mode 100644 index 0000000000..bbe8664858 --- /dev/null +++ b/website/docs/d/mariadb_dcn_detail.html.markdown @@ -0,0 +1,62 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_dcn_detail" +sidebar_current: "docs-tencentcloud-datasource-mariadb_dcn_detail" +description: |- + Use this data source to query detailed information of mariadb dcn_detail +--- + +# tencentcloud_mariadb_dcn_detail + +Use this data source to query detailed information of mariadb dcn_detail + +## Example Usage + +```hcl +data "tencentcloud_mariadb_dcn_detail" "dcn_detail" { + instance_id = "tdsql-9vqvls95" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String) Instance ID. +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `dcn_details` - DCN synchronization details. + * `cpu` - Number of CPU cores of the instance. + * `create_time` - Creation time of the instance in the format of 2006-01-02 15:04:05. + * `dcn_flag` - DCN flag. Valid values: `1` (primary), `2` (disaster recovery). + * `dcn_status` - DCN status. Valid values: `0` (none), `1` (creating), `2` (syncing), `3` (disconnected). + * `encrypt_status` - Whether KMS is enabled. + * `instance_id` - Instance ID. + * `instance_name` - Instance name. + * `instance_type` - Instance type. Valid values: `1` (dedicated primary instance), `2` (non-dedicated primary instance), `3` (non-dedicated disaster recovery instance), `4` (dedicated disaster recovery instance). + * `memory` - Instance memory capacity in GB. + * `pay_mode` - Billing mode. + * `period_end_time` - Expiration time of the instance in the format of 2006-01-02 15:04:05. + * `region` - Region where the instance resides. + * `replica_config` - Configuration information of DCN replication. This field is null for a primary instance.Note: This field may return null, indicating that no valid values can be obtained. + * `delay_replication_type` - Delayed replication type. Valid values: `DEFAULT` (no delay), `DUE_TIME` (specified replication time)Note: This field may return null, indicating that no valid values can be obtained. + * `due_time` - Specified time for delayed replicationNote: This field may return null, indicating that no valid values can be obtained. + * `replication_delay` - The number of seconds to delay the replicationNote: This field may return null, indicating that no valid values can be obtained. + * `ro_replication_mode` - DCN running status. Valid values: `START` (running), `STOP` (pause)Note: This field may return null, indicating that no valid values can be obtained. + * `replica_status` - DCN replication status. This field is null for the primary instance.Note: This field may return null, indicating that no valid values can be obtained. + * `delay` - The current delay, which takes the delay value of the replica instance. + * `status` - DCN running status. Valid values: `START` (running), `STOP` (pause).Note: This field may return null, indicating that no valid values can be obtained. + * `status_desc` - Instance status description. + * `status` - Instance status. + * `storage` - Instance storage capacity in GB. + * `vip` - Instance IP address. + * `vipv6` - Instance IPv6 address. + * `vport` - Instance port. + * `zone` - Availability zone where the instance resides. + + diff --git a/website/docs/d/mariadb_file_download_url.html.markdown b/website/docs/d/mariadb_file_download_url.html.markdown new file mode 100644 index 0000000000..043f5ba135 --- /dev/null +++ b/website/docs/d/mariadb_file_download_url.html.markdown @@ -0,0 +1,37 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_file_download_url" +sidebar_current: "docs-tencentcloud-datasource-mariadb_file_download_url" +description: |- + Use this data source to query detailed information of mariadb file_download_url +--- + +# tencentcloud_mariadb_file_download_url + +Use this data source to query detailed information of mariadb file_download_url + +## Example Usage + +```hcl +data "tencentcloud_mariadb_file_download_url" "file_download_url" { + instance_id = "tdsql-9vqvls95" + file_path = "/cos_backup/test.txt" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `file_path` - (Required, String) Unsigned file path. +* `instance_id` - (Required, String) Instance ID. +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `pre_signed_url` - Signed download URL. + + diff --git a/website/docs/d/mariadb_flow.html.markdown b/website/docs/d/mariadb_flow.html.markdown new file mode 100644 index 0000000000..2edb7240c8 --- /dev/null +++ b/website/docs/d/mariadb_flow.html.markdown @@ -0,0 +1,35 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_flow" +sidebar_current: "docs-tencentcloud-datasource-mariadb_flow" +description: |- + Use this data source to query detailed information of mariadb flow +--- + +# tencentcloud_mariadb_flow + +Use this data source to query detailed information of mariadb flow + +## Example Usage + +```hcl +data "tencentcloud_mariadb_flow" "flow" { + flow_id = 1307 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `flow_id` - (Required, Int) Flow ID returned by async request API. +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `status` - Flow status. 0: succeeded, 1: failed, 2: running. + + diff --git a/website/docs/d/mariadb_instance_specs.html.markdown b/website/docs/d/mariadb_instance_specs.html.markdown new file mode 100644 index 0000000000..02902ad8b4 --- /dev/null +++ b/website/docs/d/mariadb_instance_specs.html.markdown @@ -0,0 +1,44 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_instance_specs" +sidebar_current: "docs-tencentcloud-datasource-mariadb_instance_specs" +description: |- + Use this data source to query detailed information of mariadb instance_specs +--- + +# tencentcloud_mariadb_instance_specs + +Use this data source to query detailed information of mariadb instance_specs + +## Example Usage + +```hcl +data "tencentcloud_mariadb_instance_specs" "instance_specs" { +} +``` + +## Argument Reference + +The following arguments are supported: + +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `specs` - list of instance specifications. + * `machine` - machine type. + * `spec_infos` - list of machine specifications. + * `cpu` - CPU cores. + * `machine` - machine type. + * `max_storage` - maximum storage size, in GB. + * `memory` - memory, in GB. + * `min_storage` - minimum storage size, in GB. + * `node_count` - node count. + * `pid` - product price id. + * `qps` - maximum QPS. + * `suit_info` - recommended usage scenarios. + + diff --git a/website/docs/d/mariadb_log_files.html.markdown b/website/docs/d/mariadb_log_files.html.markdown new file mode 100644 index 0000000000..d1d280210f --- /dev/null +++ b/website/docs/d/mariadb_log_files.html.markdown @@ -0,0 +1,43 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_log_files" +sidebar_current: "docs-tencentcloud-datasource-mariadb_log_files" +description: |- + Use this data source to query detailed information of mariadb log_files +--- + +# tencentcloud_mariadb_log_files + +Use this data source to query detailed information of mariadb log_files + +## Example Usage + +```hcl +data "tencentcloud_mariadb_log_files" "log_files" { + instance_id = "tdsql-9vqvls95" + type = 1 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String) Instance ID in the format of `tdsql-ow728lmc`. +* `type` - (Required, Int) Requested log type. Valid values: 1 (binlog), 2 (cold backup), 3 (errlog), 4 (slowlog). +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `files` - Information such as `uri`, `length`, and `mtime` (modification time). + * `file_name` - Filename. + * `length` - File length. + * `mtime` - Last modified time of log. + * `uri` - Uniform resource identifier (URI) used during log download. +* `normal_prefix` - For an instance in a common network, this prefix plus URI can be used as the download address. +* `vpc_prefix` - For an instance in a VPC, this prefix plus URI can be used as the download address. + + diff --git a/website/docs/d/mariadb_orders.html.markdown b/website/docs/d/mariadb_orders.html.markdown new file mode 100644 index 0000000000..2d764f8116 --- /dev/null +++ b/website/docs/d/mariadb_orders.html.markdown @@ -0,0 +1,41 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_orders" +sidebar_current: "docs-tencentcloud-datasource-mariadb_orders" +description: |- + Use this data source to query detailed information of mariadb orders +--- + +# tencentcloud_mariadb_orders + +Use this data source to query detailed information of mariadb orders + +## Example Usage + +```hcl +data "tencentcloud_mariadb_orders" "orders" { + deal_name = "20230607164033835942781" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `deal_name` - (Required, String) List of long order numbers to be queried, which are returned for the APIs for creating, renewing, or scaling instances. +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `deals` - Order information list. + * `count` - Number of items. + * `deal_name` - Order number. + * `flow_id` - ID of the associated process, which can be used to query the process execution status. + * `instance_ids` - The ID of the created instance, which is required only for the order that creates an instance.Note: This field may return null, indicating that no valid values can be obtained. + * `owner_uin` - Account. + * `pay_mode` - Payment mode. Valid values: 0 (postpaid), 1 (prepaid). + + diff --git a/website/docs/d/mariadb_price.html.markdown b/website/docs/d/mariadb_price.html.markdown new file mode 100644 index 0000000000..9230c6cf16 --- /dev/null +++ b/website/docs/d/mariadb_price.html.markdown @@ -0,0 +1,49 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_price" +sidebar_current: "docs-tencentcloud-datasource-mariadb_price" +description: |- + Use this data source to query detailed information of mariadb price +--- + +# tencentcloud_mariadb_price + +Use this data source to query detailed information of mariadb price + +## Example Usage + +```hcl +data "tencentcloud_mariadb_price" "price" { + zone = "ap-guangzhou-3" + node_count = 2 + memory = 2 + storage = 20 + buy_count = 1 + period = 1 + paymode = "prepaid" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `buy_count` - (Required, Int) The quantity you want to purchase is queried by default for the price of purchasing 1 instance. +* `memory` - (Required, Int) Memory size in GB, which can be obtained by querying the instance specification through the `DescribeDBInstanceSpecs` API. +* `node_count` - (Required, Int) Number of instance nodes, which can be obtained by querying the instance specification through the `DescribeDBInstanceSpecs` API. +* `storage` - (Required, Int) Storage capacity in GB. The maximum and minimum storage space can be obtained by querying instance specification through the `DescribeDBInstanceSpecs` API. +* `zone` - (Required, String) AZ ID of the purchased instance. +* `amount_unit` - (Optional, String) Price unit. Valid values: `* pent` (cent), `* microPent` (microcent). +* `paymode` - (Optional, String) Billing type. Valid values: `postpaid` (pay-as-you-go), `prepaid` (monthly subscription). +* `period` - (Optional, Int) Purchase period in months. +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `original_price` - Original price * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site). +* `price` - The actual price may be different from the original price due to discounts. * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site). + + diff --git a/website/docs/d/mariadb_project_security_groups.html.markdown b/website/docs/d/mariadb_project_security_groups.html.markdown new file mode 100644 index 0000000000..7f0a569851 --- /dev/null +++ b/website/docs/d/mariadb_project_security_groups.html.markdown @@ -0,0 +1,52 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_project_security_groups" +sidebar_current: "docs-tencentcloud-datasource-mariadb_project_security_groups" +description: |- + Use this data source to query detailed information of mariadb project_security_groups +--- + +# tencentcloud_mariadb_project_security_groups + +Use this data source to query detailed information of mariadb project_security_groups + +## Example Usage + +```hcl +data "tencentcloud_mariadb_project_security_groups" "project_security_groups" { + product = "mariadb" + project_id = 0 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `product` - (Required, String) Database engine name. Valid value: `mariadb`. +* `project_id` - (Optional, Int) Project ID. +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `groups` - Security group details. + * `create_time` - Creation time in the format of yyyy-mm-dd hh:mm:ss. + * `inbound` - Inbound rule. + * `action` - Policy, which can be `ACCEPT` or `DROP`. + * `cidr_ip` - Source IP or source IP range, such as 192.168.0.0/16. + * `ip_protocol` - Network protocol. UDP and TCP are supported. + * `port_range` - Port. + * `outbound` - Outbound rule. + * `action` - Policy, which can be `ACCEPT` or `DROP`. + * `cidr_ip` - Source IP or source IP range, such as 192.168.0.0/16. + * `ip_protocol` - Network protocol. UDP and TCP are supported. + * `port_range` - Port. + * `project_id` - Project ID. + * `security_group_id` - Security group ID. + * `security_group_name` - Security group name. + * `security_group_remark` - Security group remarks. + + diff --git a/website/docs/d/mariadb_renewal_price.html.markdown b/website/docs/d/mariadb_renewal_price.html.markdown new file mode 100644 index 0000000000..a454626457 --- /dev/null +++ b/website/docs/d/mariadb_renewal_price.html.markdown @@ -0,0 +1,39 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_renewal_price" +sidebar_current: "docs-tencentcloud-datasource-mariadb_renewal_price" +description: |- + Use this data source to query detailed information of mariadb renewal_price +--- + +# tencentcloud_mariadb_renewal_price + +Use this data source to query detailed information of mariadb renewal_price + +## Example Usage + +```hcl +data "tencentcloud_mariadb_renewal_price" "renewal_price" { + instance_id = "tdsql-9vqvls95" + period = 2 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String) Instance ID. +* `amount_unit` - (Optional, String) Price unit. Valid values: `* pent` (cent), `* microPent` (microcent). +* `period` - (Optional, Int) Renewal duration, default: 1 month. +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `original_price` - Original price * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site). +* `price` - The actual price may be different from the original price due to discounts. * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site). + + diff --git a/website/docs/d/mariadb_sale_info.html.markdown b/website/docs/d/mariadb_sale_info.html.markdown new file mode 100644 index 0000000000..1a2f2fc74f --- /dev/null +++ b/website/docs/d/mariadb_sale_info.html.markdown @@ -0,0 +1,52 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_sale_info" +sidebar_current: "docs-tencentcloud-datasource-mariadb_sale_info" +description: |- + Use this data source to query detailed information of mariadb sale_info +--- + +# tencentcloud_mariadb_sale_info + +Use this data source to query detailed information of mariadb sale_info + +## Example Usage + +```hcl +data "tencentcloud_mariadb_sale_info" "sale_info" { +} +``` + +## Argument Reference + +The following arguments are supported: + +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `region_list` - list of sale region info. + * `available_choice` - available zone choice. + * `master_zone` - master zone. + * `on_sale` - is zone on sale. + * `zone_id` - zone id. + * `zone_name` - zone name(zh). + * `zone` - zone name(en). + * `slave_zones` - slave zones. + * `on_sale` - is zone on sale. + * `zone_id` - zone id. + * `zone_name` - zone name(zh). + * `zone` - zone name(en). + * `region_id` - region id. + * `region_name` - region name(zh). + * `region` - region name(en). + * `zone_list` - list of az zone. + * `on_sale` - is zone on sale. + * `zone_id` - zone id. + * `zone_name` - zone name(zh). + * `zone` - zone name(en). + + diff --git a/website/docs/d/mariadb_slow_logs.html.markdown b/website/docs/d/mariadb_slow_logs.html.markdown new file mode 100644 index 0000000000..168d83f920 --- /dev/null +++ b/website/docs/d/mariadb_slow_logs.html.markdown @@ -0,0 +1,67 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_slow_logs" +sidebar_current: "docs-tencentcloud-datasource-mariadb_slow_logs" +description: |- + Use this data source to query detailed information of mariadb slow_logs +--- + +# tencentcloud_mariadb_slow_logs + +Use this data source to query detailed information of mariadb slow_logs + +## Example Usage + +```hcl +data "tencentcloud_mariadb_slow_logs" "slow_logs" { + instance_id = "tdsql-9vqvls95" + start_time = "2023-06-01 14:55:20" + order_by = "query_time_sum" + order_by_type = "desc" + slave = 0 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String) Instance ID in the format of `tdsql-ow728lmc`. +* `start_time` - (Required, String) Query start time in the format of 2016-07-23 14:55:20. +* `db` - (Optional, String) Specific name of the database to be queried. +* `end_time` - (Optional, String) Query end time in the format of 2016-08-22 14:55:20. +* `order_by_type` - (Optional, String) Sorting order. Valid values: desc, asc. +* `order_by` - (Optional, String) Sorting metric. Valid values: query_time_sum, query_count. +* `result_output_file` - (Optional, String) Used to save results. +* `slave` - (Optional, Int) Query slow queries from either the primary or the replica. Valid values: 0 (primary), 1 (replica). + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `data` - Slow query log data. + * `check_sum` - Statement checksum for querying details. + * `db` - Database name. + * `example_sql` - Sample SQLNote: This field may return null, indicating that no valid values can be obtained. + * `finger_print` - Abstracted SQL statement. + * `host` - Host address of account. + * `lock_time_avg` - Average lock time. + * `lock_time_max` - Maximum lock time. + * `lock_time_min` - Minimum lock time. + * `lock_time_sum` - Total lock time. + * `query_count` - Number of queries. + * `query_time_avg` - Average query time. + * `query_time_max` - Maximum query time. + * `query_time_min` - Minimum query time. + * `query_time_sum` - Total query time. + * `rows_examined_sum` - Number of scanned rows. + * `rows_sent_sum` - Number of sent rows. + * `ts_max` - Last execution time. + * `ts_min` - First execution time. + * `user` - Account. +* `lock_time_sum` - Total statement lock time. +* `query_count` - Total number of statement queries. +* `query_time_sum` - Total statement query time. + + diff --git a/website/docs/d/mariadb_upgrade_price.html.markdown b/website/docs/d/mariadb_upgrade_price.html.markdown new file mode 100644 index 0000000000..7c9befa18e --- /dev/null +++ b/website/docs/d/mariadb_upgrade_price.html.markdown @@ -0,0 +1,44 @@ +--- +subcategory: "TencentDB for MariaDB(MariaDB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_mariadb_upgrade_price" +sidebar_current: "docs-tencentcloud-datasource-mariadb_upgrade_price" +description: |- + Use this data source to query detailed information of mariadb upgrade_price +--- + +# tencentcloud_mariadb_upgrade_price + +Use this data source to query detailed information of mariadb upgrade_price + +## Example Usage + +```hcl +data "tencentcloud_mariadb_upgrade_price" "upgrade_price" { + instance_id = "tdsql-9vqvls95" + memory = 4 + storage = 40 + node_count = 2 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String) Instance ID. +* `memory` - (Required, Int) Memory size in GB, which can be obtained by querying the instance specification through the `DescribeDBInstanceSpecs` API. +* `storage` - (Required, Int) Storage capacity in GB. The maximum and minimum storage space can be obtained by querying instance specification through the `DescribeDBInstanceSpecs` API. +* `amount_unit` - (Optional, String) Price unit. Valid values: `* pent` (cent), `* microPent` (microcent). +* `node_count` - (Optional, Int) New instance nodes, zero means not change. +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `formula` - Price calculation formula. +* `original_price` - Original price * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site). +* `price` - The actual price may be different from the original price due to discounts. * Unit: Cent (default). If the request parameter contains `AmountUnit`, see `AmountUnit` description. * Currency: CNY (Chinese site), USD (international site). + + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index ddc0383ba6..73c184b8b6 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -3364,9 +3364,45 @@