diff --git a/.changelog/2876.txt b/.changelog/2876.txt new file mode 100644 index 0000000000..492f96d2c5 --- /dev/null +++ b/.changelog/2876.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +tencentcloud_kubernetes_health_check_template +``` diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 4ece7d4892..3fb38f9acd 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1119,7 +1119,7 @@ func Provider() *schema.Provider { "tencentcloud_cdc_dedicated_cluster_instance_types": cdc.DataSourceTencentCloudCdcDedicatedClusterInstanceTypes(), "tencentcloud_cdc_dedicated_cluster_orders": cdc.DataSourceTencentCloudCdcDedicatedClusterOrders(), "tencentcloud_cdwdoris_instances": cdwdoris.DataSourceTencentCloudCdwdorisInstances(), - "tencentcloud_lite_hbase_instances": emr.DataSourceTencentCloudLiteHbaseInstances()}, + "tencentcloud_lite_hbase_instances": emr.DataSourceTencentCloudLiteHbaseInstances(), "tencentcloud_kubernetes_health_check_template": tke.DataSourceTencentCloudKubernetesHealthCheckTemplate()}, ResourcesMap: map[string]*schema.Resource{ "tencentcloud_project": project.ResourceTencentCloudProject(), diff --git a/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template.go b/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template.go new file mode 100644 index 0000000000..0e5094f50c --- /dev/null +++ b/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template.go @@ -0,0 +1,163 @@ +// Code generated by iacg; DO NOT EDIT. +package tke + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + tkev20220501 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20220501" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func DataSourceTencentCloudKubernetesHealthCheckTemplate() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudKubernetesHealthCheckTemplateRead, + Schema: map[string]*schema.Schema{ + "health_check_template": { + Type: schema.TypeList, + Computed: true, + Description: "health check template", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rules": { + Type: schema.TypeList, + Required: true, + Description: "health check template rule", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "health check template rule name", + }, + "description": { + Type: schema.TypeString, + Required: true, + Description: "health check template rule description", + }, + "repair_action": { + Type: schema.TypeString, + Required: true, + Description: "health check template rule repair action", + }, + "repair_effect": { + Type: schema.TypeString, + Required: true, + Description: "health check template rule repair effect", + }, + "should_enable": { + Type: schema.TypeBool, + Required: true, + Description: "health check template rule should enable", + }, + "should_repair": { + Type: schema.TypeBool, + Required: true, + Description: "health check template rule should repair", + }, + "severity": { + Type: schema.TypeString, + Required: true, + Description: "health check template rule severity", + }, + }, + }, + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudKubernetesHealthCheckTemplateRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_kubernetes_health_check_template.read")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(nil) + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + service := TkeService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + + paramMap := make(map[string]interface{}) + var respData *tkev20220501.DescribeHealthCheckTemplateResponseParams + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeKubernetesHealthCheckTemplateByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + respData = result + return nil + }) + if err != nil { + return err + } + + var ids []string + healthCheckTemplateMap := map[string]interface{}{} + + if respData.HealthCheckTemplate != nil { + rulesList := make([]map[string]interface{}, 0, len(respData.HealthCheckTemplate.Rules)) + if respData.HealthCheckTemplate.Rules != nil { + for _, rules := range respData.HealthCheckTemplate.Rules { + rulesMap := map[string]interface{}{} + + var name string + if rules.Name != nil { + rulesMap["name"] = rules.Name + name = *rules.Name + } + + if rules.Description != nil { + rulesMap["description"] = rules.Description + } + + if rules.RepairAction != nil { + rulesMap["repair_action"] = rules.RepairAction + } + + if rules.RepairEffect != nil { + rulesMap["repair_effect"] = rules.RepairEffect + } + + if rules.ShouldEnable != nil { + rulesMap["should_enable"] = rules.ShouldEnable + } + + if rules.ShouldRepair != nil { + rulesMap["should_repair"] = rules.ShouldRepair + } + + if rules.Severity != nil { + rulesMap["severity"] = rules.Severity + } + + ids = append(ids, name) + rulesList = append(rulesList, rulesMap) + } + + healthCheckTemplateMap["rules"] = rulesList + } + _ = d.Set("health_check_template", []interface{}{healthCheckTemplateMap}) + } + + d.SetId(helper.DataResourceIdsHash(ids)) + + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), healthCheckTemplateMap); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template.md b/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template.md new file mode 100644 index 0000000000..fa5e8b308c --- /dev/null +++ b/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template.md @@ -0,0 +1,8 @@ +Use this data source to query detailed information of tke kubernetes_health_check_template + +Example Usage + +```hcl +data "tencentcloud_kubernetes_health_check_template" "kubernetes_health_check_template" { +} +``` diff --git a/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template_extension.go b/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template_extension.go new file mode 100644 index 0000000000..7fdf745226 --- /dev/null +++ b/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template_extension.go @@ -0,0 +1 @@ +package tke diff --git a/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template_test.go b/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template_test.go new file mode 100644 index 0000000000..af05492f60 --- /dev/null +++ b/tencentcloud/services/tke/data_source_tc_kubernetes_health_check_template_test.go @@ -0,0 +1,29 @@ +package tke + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudKubernetesHealthCheckTemplateDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccKubernetesHealthCheckTemplateDataSource, + Check: resource.ComposeTestCheckFunc(resource.AccCheckTencentCloudDataSourceID("data.tencentcloud_kubernetes_health_check_template.kubernetes_health_check_template")), + }}, + }) +} + +const testAccKubernetesHealthCheckTemplateDataSource = ` + +data "tencentcloud_kubernetes_health_check_template" "kubernetes_health_check_template" { +} +` diff --git a/tencentcloud/services/tke/service_tencentcloud_tke.go b/tencentcloud/services/tke/service_tencentcloud_tke.go index 3ec621af82..8f166e87dd 100644 --- a/tencentcloud/services/tke/service_tencentcloud_tke.go +++ b/tencentcloud/services/tke/service_tencentcloud_tke.go @@ -3655,3 +3655,32 @@ func (me *TkeService) DescribeKubernetesLogConfigById(ctx context.Context, clust ret = response.Response return } + +func (me *TkeService) DescribeKubernetesHealthCheckTemplateByFilter(ctx context.Context, param map[string]interface{}) (ret *tke2.DescribeHealthCheckTemplateResponseParams, errRet error) { + var ( + logId = tccommon.GetLogId(ctx) + request = tke2.NewDescribeHealthCheckTemplateRequest() + ) + + 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.UseTkeV20220501Client().DescribeHealthCheckTemplate(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 == nil { + return + } + + ret = response.Response + return +}