From d7a0f444f4e5fc9fc0924226deefdf209e21cd39 Mon Sep 17 00:00:00 2001 From: arunma Date: Tue, 23 Aug 2022 23:33:20 +0800 Subject: [PATCH 01/13] style: go fmt --- tencentcloud/resource_tc_kubernetes_addon_attachment.go | 3 ++- .../resource_tc_monitor_tmp_tke_global_notification.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tencentcloud/resource_tc_kubernetes_addon_attachment.go b/tencentcloud/resource_tc_kubernetes_addon_attachment.go index fed63925a2..44e4623245 100644 --- a/tencentcloud/resource_tc_kubernetes_addon_attachment.go +++ b/tencentcloud/resource_tc_kubernetes_addon_attachment.go @@ -80,10 +80,11 @@ package tencentcloud import ( "context" "fmt" - tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525" "log" "strings" + tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" ) diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go b/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go index 5b59f03430..7e17c5ef13 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_global_notification.go @@ -34,6 +34,7 @@ package tencentcloud import ( "context" "fmt" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" From 5fb1edc0ca227bdb41cde9967dc0d6c144c12873 Mon Sep 17 00:00:00 2001 From: arunma Date: Tue, 23 Aug 2022 23:35:42 +0800 Subject: [PATCH 02/13] feat: add template ut --- .../resource_tc_monitor_tmp_tke_template.go | 8 ++ ...source_tc_monitor_tmp_tke_template_test.go | 111 ++++++++++++++++++ tencentcloud/service_tencentcloud_tke.go | 2 +- 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 tencentcloud/resource_tc_monitor_tmp_tke_template_test.go diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_template.go b/tencentcloud/resource_tc_monitor_tmp_tke_template.go index 1597e9de42..07c741d925 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_template.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_template.go @@ -345,6 +345,14 @@ func resourceTencentCloudMonitorTmpTkeTemplateRead(d *schema.ResourceData, meta return fmt.Errorf("resource `template` %s does not exist", templateId) } + templates := make([]map[string]interface{}, 0) + templates = append(templates, map[string]interface{}{ + "name": template.Name, + "level": template.Level, + "describe": template.Describe, + "is_default": template.IsDefault, + }) + _ = d.Set("template", templates) return nil } diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go b/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go new file mode 100644 index 0000000000..89ba78578d --- /dev/null +++ b/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go @@ -0,0 +1,111 @@ +package tencentcloud + +import ( + "context" + "fmt" + "testing" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccTencentCloudMonitorTemplate_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_COMMON) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckTemplateDestroy, + Steps: []resource.TestStep{ + { + Config: testTemplate_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckTemplateExists("tencentcloud_monitor_tmp_tke_template.basic"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_template.basic", "template.0.name", "test-template"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_template.basic", "template.0.level", "instance"), + ), + }, + { + Config: testTemplate_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckTemplateExists("tencentcloud_monitor_tmp_tke_template.basic"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_template.basic", "template.0.name", "test-template_update"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_template.basic", "template.0.level", "instance"), + ), + }, + { + ResourceName: "tencentcloud_monitor_tmp_tke_template.basic", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckTemplateDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := TkeService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_monitor_tmp_tke_template" { + continue + } + if rs.Primary.ID == "" { + return fmt.Errorf("resource id is not set") + } + time.Sleep(10000) + template1, err := service.DescribeTmpTkeTemplateById(ctx, rs.Primary.ID) + if err != nil { + return err + } + + if template1 != nil { + return fmt.Errorf("template %s still exists, : %v", rs.Primary.ID, *template1.TemplateId) + } + } + + return nil +} + +func testAccCheckTemplateExists(r string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + rs, ok := s.RootModule().Resources[r] + if !ok { + return fmt.Errorf("resource %s is not found", r) + } + if rs.Primary.ID == "" { + return fmt.Errorf("resource id is not set") + } + + service := TkeService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + template, err := service.DescribeTmpTkeTemplateById(ctx, rs.Primary.ID) + if err != nil { + return err + } + + if template == nil { + return fmt.Errorf("template %s is not found", rs.Primary.ID) + } + + return nil + } +} + +const testTemplate_basic = ` +resource "tencentcloud_monitor_tmp_tke_template" "basic" { + template { + name = "test-template" + level = "instance" + } +}` + +const testTemplate_update = ` +resource "tencentcloud_monitor_tmp_tke_template" "basic" { + template { + name = "test-template_update" + level = "instance" + } +}` diff --git a/tencentcloud/service_tencentcloud_tke.go b/tencentcloud/service_tencentcloud_tke.go index 19cfdcdbd4..e2919ac16f 100644 --- a/tencentcloud/service_tencentcloud_tke.go +++ b/tencentcloud/service_tencentcloud_tke.go @@ -1745,7 +1745,7 @@ func (me *TkeService) DescribeTmpTkeTemplateById(ctx context.Context, templateId request.Filters = append( request.Filters, &tke.Filter{ - Name: helper.String("templateId"), + Name: helper.String("ID"), Values: []*string{&templateId}, }, ) From a667aec56c2d170b25cce96f54b301c1bf4e70e5 Mon Sep 17 00:00:00 2001 From: arunma Date: Wed, 24 Aug 2022 00:02:41 +0800 Subject: [PATCH 03/13] fix: update template ut --- .../resource_tc_monitor_tmp_tke_template_test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go b/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go index 89ba78578d..0393f49879 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go @@ -3,11 +3,9 @@ package tencentcloud import ( "context" "fmt" - "testing" - "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "testing" ) func TestAccTencentCloudMonitorTemplate_basic(t *testing.T) { @@ -53,14 +51,14 @@ func testAccCheckTemplateDestroy(s *terraform.State) error { if rs.Primary.ID == "" { return fmt.Errorf("resource id is not set") } - time.Sleep(10000) - template1, err := service.DescribeTmpTkeTemplateById(ctx, rs.Primary.ID) + + template, err := service.DescribeTmpTkeTemplateById(ctx, rs.Primary.ID) if err != nil { return err } - if template1 != nil { - return fmt.Errorf("template %s still exists, : %v", rs.Primary.ID, *template1.TemplateId) + if template != nil { + return fmt.Errorf("template %s still exists", rs.Primary.ID) } } From 95f4920b024bfbadb94ec38f042f7a248486a554 Mon Sep 17 00:00:00 2001 From: arunma Date: Wed, 24 Aug 2022 00:40:09 +0800 Subject: [PATCH 04/13] feat: add alert rule ut --- .../resource_tc_monitor_tmp_alert_rule.go | 12 +- ...resource_tc_monitor_tmp_alert_rule_test.go | 131 ++++++++++++++++++ 2 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go diff --git a/tencentcloud/resource_tc_monitor_tmp_alert_rule.go b/tencentcloud/resource_tc_monitor_tmp_alert_rule.go index f64af8b9f9..cd35050918 100644 --- a/tencentcloud/resource_tc_monitor_tmp_alert_rule.go +++ b/tencentcloud/resource_tc_monitor_tmp_alert_rule.go @@ -245,15 +245,21 @@ func resourceTencentCloudMonitorTmpAlertRuleRead(d *schema.ResourceData, meta in return fmt.Errorf("resource `tmpAlertRule` %s does not exist", ids[1]) } + _ = d.Set("instance_id", ids[0]) if tmpAlertRule.RuleName != nil { _ = d.Set("rule_name", tmpAlertRule.RuleName) } if tmpAlertRule.Expr != nil { _ = d.Set("expr", tmpAlertRule.Expr) } - //if tmpAlertRule.Receivers != nil { - // _ = d.Set("receivers", tmpAlertRule.Receivers) - //} + if tmpAlertRule.Receivers != nil { + list := tmpAlertRule.Receivers + result := make([]string, 0, len(list)) + for _, v := range list { + result = append(result, *v) + } + _ = d.Set("receivers", result) + } if tmpAlertRule.RuleState != nil { _ = d.Set("rule_state", tmpAlertRule.RuleState) } diff --git a/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go b/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go new file mode 100644 index 0000000000..cfb96d462d --- /dev/null +++ b/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go @@ -0,0 +1,131 @@ +package tencentcloud + +import ( + "context" + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "strings" + "testing" +) + +func TestAccTencentCloudMonitorAlertRule_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_COMMON) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAlertRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAlertRule_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckAlertRuleExists("tencentcloud_monitor_tmp_alert_rule.basic"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "instance_id", "prom-86azj3lg"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "rule_name", "test-rule_name"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "receivers.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "expr", "increase(mysql_global_status_slow_queries[1m]) > 0"), + ), + }, + //{ + // Config: testAlertRule_update, + // Check: resource.ComposeTestCheckFunc( + // testAccCheckAlertRuleExists("tencentcloud_monitor_tmp_alert_rule.basic"), + // resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "instance_id", "prom-86azj3lg"), + // resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "rule_name", "test-rule_name_update"), + // resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "receivers.#", "1"), + // resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "expr", "increase(mysql_global_status_slow_queries[1m]) > 1"), + // ), + //}, + { + ResourceName: "tencentcloud_monitor_tmp_alert_rule.basic", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckAlertRuleDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := MonitorService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_monitor_tmp_tke_alert_rule" { + continue + } + if rs.Primary.ID == "" { + return fmt.Errorf("resource id is not set") + } + ids := strings.Split(rs.Primary.ID, FILED_SP) + if len(ids) != 2 { + return fmt.Errorf("id is broken, id is %s", rs.Primary.ID) + } + + instance, err := service.DescribeMonitorTmpAlertRuleById(ctx, ids[0], ids[1]) + if err != nil { + return err + } + + if instance != nil { + return fmt.Errorf("instance %s still exists", rs.Primary.ID) + } + } + + return nil +} + +func testAccCheckAlertRuleExists(r string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + rs, ok := s.RootModule().Resources[r] + if !ok { + return fmt.Errorf("resource %s is not found", r) + } + if rs.Primary.ID == "" { + return fmt.Errorf("resource id is not set") + } + ids := strings.Split(rs.Primary.ID, FILED_SP) + if len(ids) != 2 { + return fmt.Errorf("id is broken, id is %s", rs.Primary.ID) + } + + service := MonitorService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + instance, err := service.DescribeMonitorTmpAlertRuleById(ctx, ids[0], ids[1]) + if err != nil { + return err + } + + if instance == nil { + return fmt.Errorf("instance %s is not found", rs.Primary.ID) + } + + return nil + } +} + +const testAlertRuleVar = ` +variable "prometheus_id" { + default = "` + defaultPrometheusId + `" +} +` +const testAlertRule_basic = testAlertRuleVar + ` +resource "tencentcloud_monitor_tmp_alert_rule" "basic" { + instance_id = var.prometheus_id + rule_name = "test-rule_name" + receivers = ["Consumer-6vkna7pevq"] + expr = "increase(mysql_global_status_slow_queries[1m]) > 0" + duration = "4m" + rule_state = 2 +}` + +const testAlertRule_update = testAlertRuleVar + ` +resource "tencentcloud_monitor_tmp_alert_rule" "basic" { + instance_id = var.prometheus_id + rule_name = "test-rule_name_update" + receivers = ["Consumer-6vkna7pevq"] + expr = "increase(mysql_global_status_slow_queries[1m]) > 1" + duration = "4m" + rule_state = 2 +}` From 0ee38bac218b002f2fa702726f70e3751e8fe9a3 Mon Sep 17 00:00:00 2001 From: arunma Date: Wed, 24 Aug 2022 01:05:02 +0800 Subject: [PATCH 05/13] fix: update alert rule ut --- ...resource_tc_monitor_tmp_alert_rule_test.go | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go b/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go index cfb96d462d..fa45cc7027 100644 --- a/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go +++ b/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go @@ -24,18 +24,20 @@ func TestAccTencentCloudMonitorAlertRule_basic(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "rule_name", "test-rule_name"), resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "receivers.#", "1"), resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "expr", "increase(mysql_global_status_slow_queries[1m]) > 0"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "duration", "4m"), + ), + }, + { + Config: testAlertRule_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckAlertRuleExists("tencentcloud_monitor_tmp_alert_rule.basic"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "instance_id", "prom-86azj3lg"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "rule_name", "test-rule_name_update"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "receivers.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "expr", "increase(mysql_global_status_slow_queries[1m]) > 1"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "duration", "2m"), ), }, - //{ - // Config: testAlertRule_update, - // Check: resource.ComposeTestCheckFunc( - // testAccCheckAlertRuleExists("tencentcloud_monitor_tmp_alert_rule.basic"), - // resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "instance_id", "prom-86azj3lg"), - // resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "rule_name", "test-rule_name_update"), - // resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "receivers.#", "1"), - // resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "expr", "increase(mysql_global_status_slow_queries[1m]) > 1"), - // ), - //}, { ResourceName: "tencentcloud_monitor_tmp_alert_rule.basic", ImportState: true, @@ -126,6 +128,6 @@ resource "tencentcloud_monitor_tmp_alert_rule" "basic" { rule_name = "test-rule_name_update" receivers = ["Consumer-6vkna7pevq"] expr = "increase(mysql_global_status_slow_queries[1m]) > 1" - duration = "4m" + duration = "2m" rule_state = 2 }` From 69ba9d4fdf15b763ff4e1ea133ace4ffa5801930 Mon Sep 17 00:00:00 2001 From: arunma Date: Wed, 24 Aug 2022 02:00:33 +0800 Subject: [PATCH 06/13] feat: add exporter integration ut --- ...rce_tc_monitor_tmp_exporter_integration.go | 18 ++- ...c_monitor_tmp_exporter_integration_test.go | 119 ++++++++++++++++++ tencentcloud/service_tencentcloud_monitor.go | 2 + 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 tencentcloud/resource_tc_monitor_tmp_exporter_integration_test.go diff --git a/tencentcloud/resource_tc_monitor_tmp_exporter_integration.go b/tencentcloud/resource_tc_monitor_tmp_exporter_integration.go index aee9c4c18f..a32744faae 100644 --- a/tencentcloud/resource_tc_monitor_tmp_exporter_integration.go +++ b/tencentcloud/resource_tc_monitor_tmp_exporter_integration.go @@ -78,6 +78,7 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD instanceId string kubeType int clusterId string + kind string ) var ( @@ -91,6 +92,7 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD } if v, ok := d.GetOk("kind"); ok { + kind = v.(string) request.Kind = helper.String(v.(string)) } @@ -127,7 +129,7 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD tmpExporterIntegrationId := *response.Response.Names[0] - d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, strconv.Itoa(kubeType), clusterId}, FILED_SP)) + d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, strconv.Itoa(kubeType), clusterId, kind}, FILED_SP)) return resourceTencentCloudMonitorTmpExporterIntegrationRead(d, meta) } @@ -225,5 +227,19 @@ func resourceTencentCloudMonitorTmpExporterIntegrationDelete(d *schema.ResourceD return err } + err := resource.Retry(2*readRetryTimeout, func() *resource.RetryError { + tmpExporterIntegration, errRet := service.DescribeMonitorTmpExporterIntegration(ctx, tmpExporterIntegrationId) + if errRet != nil { + return retryError(errRet, InternalError) + } + if tmpExporterIntegration == nil { + return nil + } + return resource.RetryableError(fmt.Errorf("exporter integration status is %v, retry...", *tmpExporterIntegration.Status)) + }) + if err != nil { + return err + } + return nil } diff --git a/tencentcloud/resource_tc_monitor_tmp_exporter_integration_test.go b/tencentcloud/resource_tc_monitor_tmp_exporter_integration_test.go new file mode 100644 index 0000000000..ac87e9f59b --- /dev/null +++ b/tencentcloud/resource_tc_monitor_tmp_exporter_integration_test.go @@ -0,0 +1,119 @@ +package tencentcloud + +import ( + "context" + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "testing" +) + +func TestAccTencentCloudMonitorExporterIntegration_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_COMMON) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckExporterIntegrationDestroy, + Steps: []resource.TestStep{ + { + Config: testExporterIntegration_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckExporterIntegrationExists("tencentcloud_monitor_tmp_exporter_integration.basic"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_exporter_integration.basic", "kind", "cvm-http-sd-exporter"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_exporter_integration.basic", "kube_type", "1"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_exporter_integration.basic", "cluster_id", "cls-ely08ic4"), + ), + }, + { + Config: testExporterIntegration_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckExporterIntegrationExists("tencentcloud_monitor_tmp_exporter_integration.basic"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_exporter_integration.basic", "kind", "cvm-http-sd-exporter"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_exporter_integration.basic", "kube_type", "1"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_exporter_integration.basic", "cluster_id", "cls-87o4klby"), + ), + }, + }, + }) +} + +func testAccCheckExporterIntegrationDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := MonitorService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_monitor_tmp_exporter_integration" { + continue + } + if rs.Primary.ID == "" { + return fmt.Errorf("resource id is not set") + } + + instance, err := service.DescribeMonitorTmpExporterIntegration(ctx, rs.Primary.ID) + if err != nil { + return err + } + + if instance != nil { + return fmt.Errorf("ExporterIntegration %s still exists", rs.Primary.ID) + } + } + + return nil +} + +func testAccCheckExporterIntegrationExists(r string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + rs, ok := s.RootModule().Resources[r] + if !ok { + return fmt.Errorf("resource %s is not found", r) + } + if rs.Primary.ID == "" { + return fmt.Errorf("resource id is not set") + } + + service := MonitorService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + tmpExporterIntegration, err := service.DescribeMonitorTmpExporterIntegration(ctx, rs.Primary.ID) + if err != nil { + return err + } + + if tmpExporterIntegration == nil { + return fmt.Errorf("ExporterIntegration %s is not found", rs.Primary.ID) + } + + return nil + } +} + +const testExporterIntegrationVar = ` +variable "prometheus_id" { + default = "` + defaultPrometheusId + `" +} +variable "default_cluster" { + default = "` + defaultTkeClusterId + `" +} +variable "cluster_id" { + default = "` + tkeClusterIdAgent + `" +} +` +const testExporterIntegration_basic = testExporterIntegrationVar + ` +resource "tencentcloud_monitor_tmp_exporter_integration" "basic" { + instance_id = var.prometheus_id + kind = "cvm-http-sd-exporter" + content = "{\"kind\":\"cvm-http-sd-exporter\",\"spec\":{\"job\":\"job_name: example-job-name\\nmetrics_path: /metrics\\ncvm_sd_configs:\\n- region: ap-guangzhou\\n ports:\\n - 9100\\n filters: \\n - name: tag:示例标签键\\n values: \\n - 示例标签值\\nrelabel_configs: \\n- source_labels: [__meta_cvm_instance_state]\\n regex: RUNNING\\n action: keep\\n- regex: __meta_cvm_tag_(.*)\\n replacement: $1\\n action: labelmap\\n- source_labels: [__meta_cvm_region]\\n target_label: region\\n action: replace\"}}" + kube_type = 1 + cluster_id = var.default_cluster +}` + +const testExporterIntegration_update = testExporterIntegrationVar + ` +resource "tencentcloud_monitor_tmp_exporter_integration" "basic" { + instance_id = var.prometheus_id + kind = "cvm-http-sd-exporter" + content = "{\"kind\":\"cvm-http-sd-exporter\",\"spec\":{\"job\":\"job_name: example-job-name\\nmetrics_path: /metrics\\ncvm_sd_configs:\\n- region: ap-guangzhou\\n ports:\\n - 9100\\n filters: \\n - name: tag:示例标签键\\n values: \\n - 示例标签值\\nrelabel_configs: \\n- source_labels: [__meta_cvm_instance_state]\\n regex: RUNNING\\n action: keep\\n- regex: __meta_cvm_tag_(.*)\\n replacement: $1\\n action: labelmap\\n- source_labels: [__meta_cvm_region]\\n target_label: region\\n action: replace\"}}" + kube_type = 1 + cluster_id = var.cluster_id +}` diff --git a/tencentcloud/service_tencentcloud_monitor.go b/tencentcloud/service_tencentcloud_monitor.go index b96e71af81..4bbec3e9cc 100644 --- a/tencentcloud/service_tencentcloud_monitor.go +++ b/tencentcloud/service_tencentcloud_monitor.go @@ -523,6 +523,7 @@ func (me *MonitorService) DescribeMonitorTmpExporterIntegration(ctx context.Cont kubeType, _ := strconv.Atoi(ids[2]) request.KubeType = helper.IntInt64(kubeType) request.ClusterId = &ids[3] + request.Kind = &ids[4] response, err := me.client.UseMonitorClient().DescribeExporterIntegrations(request) if err != nil { @@ -551,6 +552,7 @@ func (me *MonitorService) DeleteMonitorTmpExporterIntegrationById(ctx context.Co kubeType, _ := strconv.Atoi(ids[2]) request.KubeType = helper.IntInt64(kubeType) request.ClusterId = &ids[3] + request.Kind = &ids[4] defer func() { if errRet != nil { From 5125d4c0791aceb305a486cfb3d0a3bffd782176 Mon Sep 17 00:00:00 2001 From: arunma Date: Wed, 24 Aug 2022 02:03:09 +0800 Subject: [PATCH 07/13] style: make fmt --- tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go | 5 +++-- .../resource_tc_monitor_tmp_exporter_integration_test.go | 3 ++- tencentcloud/resource_tc_monitor_tmp_tke_template_test.go | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go b/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go index fa45cc7027..9cd5301527 100644 --- a/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go +++ b/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go @@ -3,10 +3,11 @@ package tencentcloud import ( "context" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" "strings" "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccTencentCloudMonitorAlertRule_basic(t *testing.T) { diff --git a/tencentcloud/resource_tc_monitor_tmp_exporter_integration_test.go b/tencentcloud/resource_tc_monitor_tmp_exporter_integration_test.go index ac87e9f59b..e97a9f60c2 100644 --- a/tencentcloud/resource_tc_monitor_tmp_exporter_integration_test.go +++ b/tencentcloud/resource_tc_monitor_tmp_exporter_integration_test.go @@ -3,9 +3,10 @@ package tencentcloud import ( "context" "fmt" + "testing" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "testing" ) func TestAccTencentCloudMonitorExporterIntegration_basic(t *testing.T) { diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go b/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go index 0393f49879..505e173bfd 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_template_test.go @@ -3,9 +3,10 @@ package tencentcloud import ( "context" "fmt" + "testing" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "testing" ) func TestAccTencentCloudMonitorTemplate_basic(t *testing.T) { From d0a6224601aca8c461248066547d80d851f627b8 Mon Sep 17 00:00:00 2001 From: arunma Date: Wed, 24 Aug 2022 02:50:50 +0800 Subject: [PATCH 08/13] feat: add instance ut --- .../resource_tc_monitor_tmp_instance_test.go | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 tencentcloud/resource_tc_monitor_tmp_instance_test.go diff --git a/tencentcloud/resource_tc_monitor_tmp_instance_test.go b/tencentcloud/resource_tc_monitor_tmp_instance_test.go new file mode 100644 index 0000000000..c70f6f86fa --- /dev/null +++ b/tencentcloud/resource_tc_monitor_tmp_instance_test.go @@ -0,0 +1,132 @@ +package tencentcloud + +import ( + "context" + "fmt" + "strconv" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccTencentCloudMonitorInstance_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_COMMON) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMonInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testInstance_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists("tencentcloud_monitor_tmp_instance.basic"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_instance.basic", "instance_name", "demo-test"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_instance.basic", "data_retention_time", "30"), + ), + }, + { + Config: testInstance_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists("tencentcloud_monitor_tmp_instance.update"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_instance.update", "instance_name", "demo-test-update"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_instance.update", "data_retention_time", "30"), + ), + }, + //{ + // ResourceName: "tencentcloud_monitor_tmp_instance.basic", + // ImportState: true, + // ImportStateVerify: true, + //}, + }, + }) +} + +func testAccCheckMonInstanceDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := MonitorService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_monitor_tmp_instance" { + continue + } + if rs.Primary.ID == "" { + return fmt.Errorf("resource id is not set") + } + + instance, err := service.DescribeMonitorTmpInstance(ctx, rs.Primary.ID) + if err != nil { + return err + } + + if instance != nil { + status := strconv.FormatInt(*instance.InstanceStatus, 10) + if strings.Contains("5,6,8,9", status) { + return nil + } + return fmt.Errorf("instance %s still exists: %v", rs.Primary.ID, *instance.InstanceStatus) + } + } + + return nil +} + +func testAccCheckInstanceExists(r string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + rs, ok := s.RootModule().Resources[r] + if !ok { + return fmt.Errorf("resource %s is not found", r) + } + if rs.Primary.ID == "" { + return fmt.Errorf("resource id is not set") + } + + service := MonitorService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + instance, err := service.DescribeMonitorTmpInstance(ctx, rs.Primary.ID) + if err != nil { + return err + } + + if instance == nil || *instance.InstanceStatus != 2 { + return fmt.Errorf("instance %s is not found", rs.Primary.ID) + } + + return nil + } +} + +const testInstanceVar = defaultAzVariable + ` +variable "vpc_id" { + default = "` + defaultEMRVpcId + `" +} +variable "subnet_id" { + default = "` + defaultEMRSubnetId + `" +} +` +const testInstance_basic = testInstanceVar + ` +resource "tencentcloud_monitor_tmp_instance" "basic" { + instance_name = "demo-test" + vpc_id = var.vpc_id + subnet_id = var.subnet_id + data_retention_time = 30 + zone = var.default_az + tags = { + "createdBy" = "terraform" + } +}` + +const testInstance_update = testInstanceVar + ` +resource "tencentcloud_monitor_tmp_instance" "update" { + instance_name = "demo-test-update" + vpc_id = var.vpc_id + subnet_id = var.subnet_id + data_retention_time = 30 + zone = var.default_az + tags = { + "createdBy" = "terraform" + } +}` From f33ac03da854f529dda139c33cefa2a9fc86130e Mon Sep 17 00:00:00 2001 From: arunma Date: Wed, 24 Aug 2022 03:17:08 +0800 Subject: [PATCH 09/13] feat: add scrape job ut --- tencentcloud/basic_test.go | 1 + .../resource_tc_monitor_tmp_scrape_job.go | 1 + ...resource_tc_monitor_tmp_scrape_job_test.go | 124 ++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 tencentcloud/resource_tc_monitor_tmp_scrape_job_test.go diff --git a/tencentcloud/basic_test.go b/tencentcloud/basic_test.go index 71a483481a..db44efdf13 100644 --- a/tencentcloud/basic_test.go +++ b/tencentcloud/basic_test.go @@ -178,6 +178,7 @@ const ( defaultTemplateId = "temp-gqunlvo1" tkeClusterIdAgent = "cls-87o4klby" tkeClusterTypeAgent = "eks" + defaultAgentId = "agent-q3zy8gt8" ) /* diff --git a/tencentcloud/resource_tc_monitor_tmp_scrape_job.go b/tencentcloud/resource_tc_monitor_tmp_scrape_job.go index 675fe164fc..36bced5260 100644 --- a/tencentcloud/resource_tc_monitor_tmp_scrape_job.go +++ b/tencentcloud/resource_tc_monitor_tmp_scrape_job.go @@ -142,6 +142,7 @@ func resourceTencentCloudMonitorTmpScrapeJobRead(d *schema.ResourceData, meta in return fmt.Errorf("resource `tmpScrapeJob` %s does not exist", tmpScrapeJobId) } + _ = d.Set("instance_id", strings.Split(tmpScrapeJobId, FILED_SP)[1]) if tmpScrapeJob.AgentId != nil { _ = d.Set("agent_id", tmpScrapeJob.AgentId) } diff --git a/tencentcloud/resource_tc_monitor_tmp_scrape_job_test.go b/tencentcloud/resource_tc_monitor_tmp_scrape_job_test.go new file mode 100644 index 0000000000..a5c7e86432 --- /dev/null +++ b/tencentcloud/resource_tc_monitor_tmp_scrape_job_test.go @@ -0,0 +1,124 @@ +package tencentcloud + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccTencentCloudMonitorScrapeJob_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_COMMON) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckScrapeJobDestroy, + Steps: []resource.TestStep{ + { + Config: testScrapeJob_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckScrapeJobExists("tencentcloud_monitor_tmp_scrape_job.basic"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_scrape_job.basic", "config", "job_name: demo-config-test\nhonor_timestamps: true\nmetrics_path: /metrics\nscheme: https\n"), + ), + }, + { + Config: testScrapeJob_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckScrapeJobExists("tencentcloud_monitor_tmp_scrape_job.update"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_scrape_job.update", "config", "job_name: demo-config-test-update\nhonor_timestamps: true\nmetrics_path: /metrics\nscheme: https\n"), + ), + }, + { + ResourceName: "tencentcloud_monitor_tmp_scrape_job.update", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckScrapeJobDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := MonitorService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_monitor_tmp_scrape_job" { + continue + } + if rs.Primary.ID == "" { + return fmt.Errorf("resource id is not set") + } + + tmpScrapeJob, err := service.DescribeMonitorTmpScrapeJob(ctx, rs.Primary.ID) + if err != nil { + return err + } + + if tmpScrapeJob != nil { + return fmt.Errorf("scrape job %s still exists", rs.Primary.ID) + } + } + + return nil +} + +func testAccCheckScrapeJobExists(r string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + rs, ok := s.RootModule().Resources[r] + if !ok { + return fmt.Errorf("resource %s is not found", r) + } + if rs.Primary.ID == "" { + return fmt.Errorf("resource id is not set") + } + + service := MonitorService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + tmpScrapeJob, err := service.DescribeMonitorTmpScrapeJob(ctx, rs.Primary.ID) + if err != nil { + return err + } + + if tmpScrapeJob == nil { + return fmt.Errorf("scrape job %s is not found", rs.Primary.ID) + } + + return nil + } +} + +const testScrapeJobVar = ` +variable "prometheus_id" { + default = "` + defaultPrometheusId + `" +} +variable "agent_id" { + default = "` + defaultAgentId + `" +} +` +const testScrapeJob_basic = testScrapeJobVar + ` +resource "tencentcloud_monitor_tmp_scrape_job" "basic" { + instance_id = var.prometheus_id + agent_id = var.agent_id + config = <<-EOT +job_name: demo-config-test +honor_timestamps: true +metrics_path: /metrics +scheme: https +EOT +}` + +const testScrapeJob_update = testScrapeJobVar + ` +resource "tencentcloud_monitor_tmp_scrape_job" "update" { + instance_id = var.prometheus_id + agent_id = var.agent_id + config = <<-EOT +job_name: demo-config-test-update +honor_timestamps: true +metrics_path: /metrics +scheme: https +EOT +}` From 52acb2078c97c67d618e133c2900a7e9ac549c7d Mon Sep 17 00:00:00 2001 From: arunma Date: Wed, 24 Aug 2022 14:38:37 +0800 Subject: [PATCH 10/13] feat: add recording rule ut --- tencentcloud/common.go | 15 ++ .../resource_tc_monitor_tmp_recording_rule.go | 17 ++- ...urce_tc_monitor_tmp_recording_rule_test.go | 136 ++++++++++++++++++ .../monitor_tmp_recording_rule.html.markdown | 8 +- 4 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 tencentcloud/resource_tc_monitor_tmp_recording_rule_test.go diff --git a/tencentcloud/common.go b/tencentcloud/common.go index b5f3c3a0cc..dad39bf4c7 100644 --- a/tencentcloud/common.go +++ b/tencentcloud/common.go @@ -2,6 +2,7 @@ package tencentcloud import ( "context" + "encoding/base64" "encoding/json" "fmt" "io/ioutil" @@ -349,3 +350,17 @@ func YamlParser(config string) (map[interface{}]interface{}, error) { } return m, nil } + +func YamlToBase64(config string) string { + m := []byte(config) + encodedStr := base64.StdEncoding.EncodeToString(m) + return encodedStr +} + +func Base64ToYaml(config string) (string, error) { + yamlConfig, err := base64.StdEncoding.DecodeString(config) + if err != nil { + return "", err + } + return string(yamlConfig), nil +} diff --git a/tencentcloud/resource_tc_monitor_tmp_recording_rule.go b/tencentcloud/resource_tc_monitor_tmp_recording_rule.go index 98f7595ada..c2111e14c7 100644 --- a/tencentcloud/resource_tc_monitor_tmp_recording_rule.go +++ b/tencentcloud/resource_tc_monitor_tmp_recording_rule.go @@ -6,7 +6,13 @@ Example Usage ```hcl resource "tencentcloud_monitor_tmp_recording_rule" "recordingRule" { name = "dasdasdsadasd" - group = "LS0tDQpuYW1lOiBleGFtcGxlDQpydWxlczoNCiAgLSByZWNvcmQ6IGpvYjpodHRwX2lucHJvZ3Jlc3NfcmVxdWVzdHM6c3VtDQogICAgZXhwcjogc3VtIGJ5IChqb2IpIChodHRwX2lucHJvZ3Jlc3NfcmVxdWVzdHMp" + group = < Date: Wed, 24 Aug 2022 14:41:26 +0800 Subject: [PATCH 11/13] fix: update ut --- tencentcloud/resource_tc_monitor_tmp_recording_rule_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tencentcloud/resource_tc_monitor_tmp_recording_rule_test.go b/tencentcloud/resource_tc_monitor_tmp_recording_rule_test.go index 8183644521..c3b2a860f7 100644 --- a/tencentcloud/resource_tc_monitor_tmp_recording_rule_test.go +++ b/tencentcloud/resource_tc_monitor_tmp_recording_rule_test.go @@ -110,7 +110,7 @@ variable "prometheus_id" { const testRecordingRule_basic = testRecordingRuleVar + ` resource "tencentcloud_monitor_tmp_recording_rule" "basic" { name = "recording_rule-test" - instance_id = "prom-86azj3lg" + instance_id = var.prometheus_id rule_state = 2 group = < Date: Wed, 24 Aug 2022 19:03:19 +0800 Subject: [PATCH 12/13] feat: add alert policy ut --- ...esource_tc_monitor_tmp_tke_alert_policy.go | 277 +++++++++++++++++- ...ce_tc_monitor_tmp_tke_alert_policy_test.go | 183 ++++++++++++ tencentcloud/service_tencentcloud_tke.go | 13 +- 3 files changed, 463 insertions(+), 10 deletions(-) create mode 100644 tencentcloud/resource_tc_monitor_tmp_tke_alert_policy_test.go diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go b/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go index 7cfa7003e7..5077089528 100644 --- a/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go +++ b/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy.go @@ -42,6 +42,7 @@ import ( "context" "fmt" "log" + "strings" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -329,6 +330,19 @@ func resourceTencentCloudTkeTmpAlertPolicyCreate(d *schema.ResourceData, meta in if v, ok := RulesMap["describe"]; ok { prometheusAlertRule.Describe = helper.String(v.(string)) } + if v, ok := RulesMap["labels"]; ok { + for _, item := range v.([]interface{}) { + labelsMap := item.(map[string]interface{}) + label := tke.Label{} + if v, ok := labelsMap["name"]; ok { + label.Name = helper.String(v.(string)) + } + if v, ok := labelsMap["value"]; ok { + label.Value = helper.String(v.(string)) + } + prometheusAlertRule.Labels = append(prometheusAlertRule.Labels, &label) + } + } if v, ok := RulesMap["annotations"]; ok { for _, item := range v.([]interface{}) { AnnotationsMap := item.(map[string]interface{}) @@ -428,7 +442,7 @@ func resourceTencentCloudTkeTmpAlertPolicyCreate(d *schema.ResourceData, meta in if v, ok := dMap["cluster_id"]; ok { prometheusAlertPolicyItem.ClusterId = helper.String(v.(string)) } - + request.AlertRule = &prometheusAlertPolicyItem } err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { @@ -449,15 +463,128 @@ func resourceTencentCloudTkeTmpAlertPolicyCreate(d *schema.ResourceData, meta in } tmpAlertPolicyId := *response.Response.Id + instanceId := *request.InstanceId - d.SetId(tmpAlertPolicyId) + d.SetId(strings.Join([]string{instanceId, tmpAlertPolicyId}, FILED_SP)) return resourceTencentCloudTkeTmpAlertPolicyRead(d, meta) } func resourceTencentCloudTkeTmpAlertPolicyRead(d *schema.ResourceData, meta interface{}) error { - defer logElapsed("resource.tencentcloud_tke_tmpAlertPolicy.read")() + defer logElapsed("resource.tencentcloud_tke_tmp_alert_policy.read")() defer inconsistentCheck(d, meta)() + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + ids := strings.Split(d.Id(), FILED_SP) + if len(ids) != 2 { + return fmt.Errorf("id is broken, id is %s", d.Id()) + } + + instanceId := ids[0] + tmpAlertPolicyId := ids[1] + + service := TkeService{client: meta.(*TencentCloudClient).apiV3Conn} + tmpAlertPolicy, err := service.DescribeTkeTmpAlertPolicy(ctx, instanceId, tmpAlertPolicyId) + if err != nil { + return err + } + log.Printf("[DEBUG] tmpAlertPolicy[%v]\n", *tmpAlertPolicy) + if tmpAlertPolicy == nil { + d.SetId("") + return fmt.Errorf("resource `AlertPolicy` %s does not exist", tmpAlertPolicyId) + } + + rules := make([]map[string]interface{}, 0, len(tmpAlertPolicy.Rules)) + for _, v := range tmpAlertPolicy.Rules { + labelList := make([]map[string]interface{}, 0, len(v.Labels)) + annotations := make([]map[string]interface{}, 0, len(v.Annotations)) + for _, label := range v.Labels { + labelList = append(labelList, map[string]interface{}{ + "name": label.Name, + "value": label.Value, + }) + } + for _, annotation := range v.Annotations { + annotations = append(annotations, map[string]interface{}{ + "name": annotation.Name, + "value": annotation.Value, + }) + } + rules = append(rules, map[string]interface{}{ + "name": v.Name, + "rule": v.Rule, + "labels": labelList, + "template": v.Template, + "for": v.For, + "describe": v.Describe, + "annotations": annotations, + "rule_state": v.RuleState, + }) + } + + notify := tmpAlertPolicy.Notification + alertManager := map[string]interface{}{ + "url": notify.AlertManager.Url, + "cluster_type": notify.AlertManager.ClusterType, + "cluster_id": notify.AlertManager.ClusterId, + } + var alertManagers []map[string]interface{} + alertManagers = append(alertManagers, alertManager) + + var notifyWay []string + if len(notify.NotifyWay) > 0 { + for _, v := range notify.NotifyWay { + notifyWay = append(notifyWay, *v) + } + } + + var receiverGroups []string + if len(notify.ReceiverGroups) > 0 { + for _, v := range notify.ReceiverGroups { + receiverGroups = append(receiverGroups, *v) + } + } + + var phoneNotifyOrder []uint64 + if len(notify.PhoneNotifyOrder) > 0 { + for _, v := range notify.PhoneNotifyOrder { + phoneNotifyOrder = append(phoneNotifyOrder, *v) + } + } + + notification := map[string]interface{}{ + "enabled": notify.Enabled, + "type": notify.Type, + "web_hook": notify.WebHook, + "alert_manager": alertManagers, + //"repeat_interval": notify.RepeatInterval, + //"time_range_start": notify.TimeRangeStart, + //"time_range_end": notify.TimeRangeEnd, + "notify_way": notifyWay, + "receiver_groups": receiverGroups, + "phone_notify_order": phoneNotifyOrder, + "phone_circle_times": notify.PhoneCircleTimes, + "phone_inner_interval": notify.PhoneInnerInterval, + "phone_circle_interval": notify.PhoneCircleInterval, + "phone_arrive_notice": notify.PhoneArriveNotice, + } + var notifications []map[string]interface{} + notifications = append(notifications, notification) + + var alertRules []map[string]interface{} + alertRule := make(map[string]interface{}) + alertRule["name"] = tmpAlertPolicy.Name + alertRule["rules"] = rules + alertRule["template_id"] = tmpAlertPolicy.TemplateId + alertRule["notification"] = notifications + alertRule["updated_at"] = tmpAlertPolicy.UpdatedAt + alertRule["cluster_id"] = tmpAlertPolicy.ClusterId + alertRules = append(alertRules, alertRule) + + _ = d.Set("alert_rule", alertRules) + _ = d.Set("instance_id", instanceId) + return nil } @@ -469,7 +596,14 @@ func resourceTencentCloudTkeTmpAlertPolicyUpdate(d *schema.ResourceData, meta in request := tke.NewModifyPrometheusAlertPolicyRequest() - request.InstanceId = helper.String(d.Id()) + ids := strings.Split(d.Id(), FILED_SP) + if len(ids) != 2 { + return fmt.Errorf("id is broken, id is %s", d.Id()) + } + + instanceId := ids[0] + + request.InstanceId = &instanceId if d.HasChange("instance_id") { return fmt.Errorf("`instance_id` do not support change now.") @@ -478,6 +612,131 @@ func resourceTencentCloudTkeTmpAlertPolicyUpdate(d *schema.ResourceData, meta in if d.HasChange("alert_rule") { return fmt.Errorf("`alert_rule` do not support change now.") } + if dMap, ok := helper.InterfacesHeadMap(d, "alert_rule"); ok { + prometheusAlertPolicyItem := tke.PrometheusAlertPolicyItem{} + if v, ok := dMap["name"]; ok { + prometheusAlertPolicyItem.Name = helper.String(v.(string)) + } + if v, ok := dMap["rules"]; ok { + for _, item := range v.([]interface{}) { + RulesMap := item.(map[string]interface{}) + prometheusAlertRule := tke.PrometheusAlertRule{} + if v, ok := RulesMap["name"]; ok { + prometheusAlertRule.Name = helper.String(v.(string)) + } + if v, ok := RulesMap["rule"]; ok { + prometheusAlertRule.Rule = helper.String(v.(string)) + } + if v, ok := RulesMap["template"]; ok { + prometheusAlertRule.Template = helper.String(v.(string)) + } + if v, ok := RulesMap["for"]; ok { + prometheusAlertRule.For = helper.String(v.(string)) + } + if v, ok := RulesMap["describe"]; ok { + prometheusAlertRule.Describe = helper.String(v.(string)) + } + if v, ok := RulesMap["annotations"]; ok { + for _, item := range v.([]interface{}) { + AnnotationsMap := item.(map[string]interface{}) + label := tke.Label{} + if v, ok := AnnotationsMap["name"]; ok { + label.Name = helper.String(v.(string)) + } + if v, ok := AnnotationsMap["value"]; ok { + label.Value = helper.String(v.(string)) + } + prometheusAlertRule.Annotations = append(prometheusAlertRule.Annotations, &label) + } + } + if v, ok := RulesMap["rule_state"]; ok { + prometheusAlertRule.RuleState = helper.IntInt64(v.(int)) + } + prometheusAlertPolicyItem.Rules = append(prometheusAlertPolicyItem.Rules, &prometheusAlertRule) + } + } + if v, ok := dMap["id"]; ok { + prometheusAlertPolicyItem.Id = helper.String(v.(string)) + } + if v, ok := dMap["template_id"]; ok { + prometheusAlertPolicyItem.TemplateId = helper.String(v.(string)) + } + if NotificationMap, ok := helper.InterfaceToMap(dMap, "notification"); ok { + prometheusNotificationItem := tke.PrometheusNotificationItem{} + if v, ok := NotificationMap["enabled"]; ok { + prometheusNotificationItem.Enabled = helper.Bool(v.(bool)) + } + if v, ok := NotificationMap["type"]; ok { + prometheusNotificationItem.Type = helper.String(v.(string)) + } + if v, ok := NotificationMap["web_hook"]; ok { + prometheusNotificationItem.WebHook = helper.String(v.(string)) + } + if AlertManagerMap, ok := helper.InterfaceToMap(NotificationMap, "alert_manager"); ok { + prometheusAlertManagerConfig := tke.PrometheusAlertManagerConfig{} + if v, ok := AlertManagerMap["url"]; ok { + prometheusAlertManagerConfig.Url = helper.String(v.(string)) + } + if v, ok := AlertManagerMap["cluster_type"]; ok { + prometheusAlertManagerConfig.ClusterType = helper.String(v.(string)) + } + if v, ok := AlertManagerMap["cluster_id"]; ok { + prometheusAlertManagerConfig.ClusterId = helper.String(v.(string)) + } + prometheusNotificationItem.AlertManager = &prometheusAlertManagerConfig + } + if v, ok := NotificationMap["repeat_interval"]; ok { + prometheusNotificationItem.RepeatInterval = helper.String(v.(string)) + } + if v, ok := NotificationMap["time_range_start"]; ok { + prometheusNotificationItem.TimeRangeStart = helper.String(v.(string)) + } + if v, ok := NotificationMap["time_range_end"]; ok { + prometheusNotificationItem.TimeRangeEnd = helper.String(v.(string)) + } + if v, ok := NotificationMap["notify_way"]; ok { + notifyWaySet := v.(*schema.Set).List() + for i := range notifyWaySet { + notifyWay := notifyWaySet[i].(string) + prometheusNotificationItem.NotifyWay = append(prometheusNotificationItem.NotifyWay, ¬ifyWay) + } + } + if v, ok := NotificationMap["receiver_groups"]; ok { + receiverGroupsSet := v.(*schema.Set).List() + for i := range receiverGroupsSet { + receiverGroups := receiverGroupsSet[i].(string) + prometheusNotificationItem.ReceiverGroups = append(prometheusNotificationItem.ReceiverGroups, &receiverGroups) + } + } + if v, ok := NotificationMap["phone_notify_order"]; ok { + phoneNotifyOrderSet := v.(*schema.Set).List() + for i := range phoneNotifyOrderSet { + phoneNotifyOrder := phoneNotifyOrderSet[i].(int) + prometheusNotificationItem.PhoneNotifyOrder = append(prometheusNotificationItem.PhoneNotifyOrder, helper.IntUint64(phoneNotifyOrder)) + } + } + if v, ok := NotificationMap["phone_circle_times"]; ok { + prometheusNotificationItem.PhoneCircleTimes = helper.IntInt64(v.(int)) + } + if v, ok := NotificationMap["phone_inner_interval"]; ok { + prometheusNotificationItem.PhoneInnerInterval = helper.IntInt64(v.(int)) + } + if v, ok := NotificationMap["phone_circle_interval"]; ok { + prometheusNotificationItem.PhoneCircleInterval = helper.IntInt64(v.(int)) + } + if v, ok := NotificationMap["phone_arrive_notice"]; ok { + prometheusNotificationItem.PhoneArriveNotice = helper.Bool(v.(bool)) + } + prometheusAlertPolicyItem.Notification = &prometheusNotificationItem + } + if v, ok := dMap["updated_at"]; ok { + prometheusAlertPolicyItem.UpdatedAt = helper.String(v.(string)) + } + if v, ok := dMap["cluster_id"]; ok { + prometheusAlertPolicyItem.ClusterId = helper.String(v.(string)) + } + request.AlertRule = &prometheusAlertPolicyItem + } err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { result, e := meta.(*TencentCloudClient).apiV3Conn.UseTkeClient().ModifyPrometheusAlertPolicy(request) @@ -505,9 +764,15 @@ func resourceTencentCloudTkeTmpAlertPolicyDelete(d *schema.ResourceData, meta in ctx := context.WithValue(context.TODO(), logIdKey, logId) service := TkeService{client: meta.(*TencentCloudClient).apiV3Conn} - tmpAlertPolicyId := d.Id() + ids := strings.Split(d.Id(), FILED_SP) + if len(ids) != 2 { + return fmt.Errorf("id is broken, id is %s", d.Id()) + } + + instanceId := ids[0] + tmpAlertPolicyId := ids[1] - if err := service.DeleteTkeTmpAlertPolicyById(ctx, tmpAlertPolicyId); err != nil { + if err := service.DeleteTkeTmpAlertPolicyById(ctx, instanceId, tmpAlertPolicyId); err != nil { return err } diff --git a/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy_test.go b/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy_test.go new file mode 100644 index 0000000000..06706ae7b3 --- /dev/null +++ b/tencentcloud/resource_tc_monitor_tmp_tke_alert_policy_test.go @@ -0,0 +1,183 @@ +package tencentcloud + +import ( + "context" + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +//func init() { +// // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_monitor_tmp_tke_alert_policy +// resource.AddTestSweepers("tencentcloud_monitor_tmp_tke_alert_policy", &resource.Sweeper{ +// Name: "tencentcloud_monitor_tmp_tke_alert_policy", +// F: testSweepTmpTkeAlertPolicy, +// }) +//} +// +//func testSweepTmpTkeAlertPolicy(region string) error { +// logId := getLogId(contextNil) +// ctx := context.WithValue(context.TODO(), logIdKey, logId) +// cli, _ := sharedClientForRegion(region) +// client := cli.(*TencentCloudClient).apiV3Conn +// service := TkeService{client} +// +// instanceId := defaultPrometheusId +// +// for { +// tmpAlertPolicy, err := service.DescribeTkeTmpAlertPolicy(ctx, instanceId, "") +// if err != nil { +// return err +// } +// +// if tmpAlertPolicy == nil { +// return nil +// } +// +// err = service.DeleteTkeTmpAlertPolicyById(ctx, instanceId, *tmpAlertPolicy.Id) +// if err != nil { +// return err +// } +// } +//} + +func TestAccTencentCloudMonitorTmpTkeAlertPolicy_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_COMMON) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckTmpTkeAlertPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: testTmpTkeAlertPolicy_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckTmpTkeAlertPolicyExists("tencentcloud_monitor_tmp_tke_alert_policy.basic"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.cluster_id", ""), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.id", ""), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.name", "alert_rule-test"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.0.enabled", "true"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.0.phone_arrive_notice", "false"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.0.phone_circle_interval", "0"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.0.phone_circle_times", "0"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.0.phone_inner_interval", "0"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.0.repeat_interval", ""), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.0.time_range_end", ""), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.0.time_range_start", ""), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.0.type", "amp"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.notification.0.web_hook", ""), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.rules.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.rules.0.describe", ""), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.rules.0.for", "5m"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.rules.0.labels.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.rules.0.labels.0.name", "severity"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.rules.0.labels.0.value", "warning"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.rules.0.name", "rules-test"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.rules.0.rule", "(count(kube_node_status_allocatable_cpu_cores) by (cluster) -1) / count(kube_node_status_allocatable_cpu_cores) by (cluster)"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.rules.0.rule_state", "0"), + resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_tke_alert_policy.basic", "alert_rule.0.rules.0.template", "集群{{ $labels.cluster }}内Pod申请的CPU过载,当前CPU申请占比{{ $value | humanizePercentage }}"), + ), + }, + { + ResourceName: "tencentcloud_monitor_tmp_tke_alert_policy.basic", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckTmpTkeAlertPolicyDestroy(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := TkeService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + for _, rs := range s.RootModule().Resources { + if rs.Type != "tencentcloud_monitor_tmp_tke_alert_policy" { + continue + } + + items := strings.Split(rs.Primary.ID, FILED_SP) + if len(items) != 2 { + return fmt.Errorf("invalid ID %s", rs.Primary.ID) + } + + instanceId := items[0] + tmpAlertPolicyId := items[1] + + tmpAlertPolicy, err := service.DescribeTkeTmpAlertPolicy(ctx, instanceId, tmpAlertPolicyId) + if tmpAlertPolicy != nil { + return fmt.Errorf("alert policy still exists") + } + if err != nil { + return err + } + } + return nil +} + +func testAccCheckTmpTkeAlertPolicyExists(r string) resource.TestCheckFunc { + return func(s *terraform.State) error { + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + + rs, ok := s.RootModule().Resources[r] + if !ok { + return fmt.Errorf("resource %s is not found", r) + } + if rs.Primary.ID == "" { + return fmt.Errorf("instance id is not set") + } + items := strings.Split(rs.Primary.ID, FILED_SP) + if len(items) != 2 { + return fmt.Errorf("invalid ID %s", rs.Primary.ID) + } + + instanceId := items[0] + tmpAlertPolicyId := items[1] + + service := TkeService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} + tmpAlertPolicy, err := service.DescribeTkeTmpAlertPolicy(ctx, instanceId, tmpAlertPolicyId) + if tmpAlertPolicy == nil { + return fmt.Errorf("alert policy %s is not found", rs.Primary.ID) + } + if err != nil { + return err + } + + return nil + } +} + +const testTmpTkeAlertPolicyVar = ` +variable "prometheus_id" { + default = "` + defaultPrometheusId + `" +} +` +const testTmpTkeAlertPolicy_basic = testTmpTkeAlertPolicyVar + ` +resource "tencentcloud_monitor_tmp_tke_alert_policy" "basic" { + instance_id = var.prometheus_id + alert_rule { + name = "alert_rule-test" + rules { + name = "rules-test" + rule = "(count(kube_node_status_allocatable_cpu_cores) by (cluster) -1) / count(kube_node_status_allocatable_cpu_cores) by (cluster)" + template = "集群{{ $labels.cluster }}内Pod申请的CPU过载,当前CPU申请占比{{ $value | humanizePercentage }}" + for = "5m" + labels { + name = "severity" + value = "warning" + } + } + notification { + type = "amp" + enabled = true + alert_manager { + url = "xxx" + } + } + } +}` diff --git a/tencentcloud/service_tencentcloud_tke.go b/tencentcloud/service_tencentcloud_tke.go index e2919ac16f..b91c9b1907 100644 --- a/tencentcloud/service_tencentcloud_tke.go +++ b/tencentcloud/service_tencentcloud_tke.go @@ -1812,7 +1812,7 @@ func (me *TkeService) DeleteTmpTkeTemplate(ctx context.Context, tempId string) ( return } -func (me *TkeService) DescribeTkeTmpAlertPolicy(ctx context.Context, tmpAlertPolicyId string) (tmpAlertPolicy *tke.PrometheusAlertPolicyItem, errRet error) { +func (me *TkeService) DescribeTkeTmpAlertPolicy(ctx context.Context, instanceId, tmpAlertPolicyId string) (tmpAlertPolicy *tke.PrometheusAlertPolicyItem, errRet error) { var ( logId = getLogId(ctx) request = tke.NewDescribePrometheusAlertPolicyRequest() @@ -1824,7 +1824,11 @@ func (me *TkeService) DescribeTkeTmpAlertPolicy(ctx context.Context, tmpAlertPol logId, "query object", request.ToJsonString(), errRet.Error()) } }() - request.InstanceId = &tmpAlertPolicyId + request.InstanceId = &instanceId + request.Filters = append(request.Filters, &tke.Filter{ + Name: helper.String("ID"), + Values: []*string{&tmpAlertPolicyId}, + }) response, err := me.client.UseTkeClient().DescribePrometheusAlertPolicy(request) if err != nil { @@ -1843,11 +1847,12 @@ func (me *TkeService) DescribeTkeTmpAlertPolicy(ctx context.Context, tmpAlertPol return } -func (me *TkeService) DeleteTkeTmpAlertPolicyById(ctx context.Context, tmpAlertPolicyId string) (errRet error) { +func (me *TkeService) DeleteTkeTmpAlertPolicyById(ctx context.Context, instanceId, tmpAlertPolicyId string) (errRet error) { logId := getLogId(ctx) request := tke.NewDeletePrometheusAlertPolicyRequest() - request.InstanceId = &tmpAlertPolicyId + request.InstanceId = &instanceId + request.AlertIds = []*string{&tmpAlertPolicyId} defer func() { if errRet != nil { From 51e9f35be6f25b0a1656070b5b94967d00002bdc Mon Sep 17 00:00:00 2001 From: arunma Date: Wed, 24 Aug 2022 19:12:32 +0800 Subject: [PATCH 13/13] fix: update ut --- tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go b/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go index 9cd5301527..34447db30c 100644 --- a/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go +++ b/tencentcloud/resource_tc_monitor_tmp_alert_rule_test.go @@ -21,7 +21,6 @@ func TestAccTencentCloudMonitorAlertRule_basic(t *testing.T) { Config: testAlertRule_basic, Check: resource.ComposeTestCheckFunc( testAccCheckAlertRuleExists("tencentcloud_monitor_tmp_alert_rule.basic"), - resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "instance_id", "prom-86azj3lg"), resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "rule_name", "test-rule_name"), resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "receivers.#", "1"), resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "expr", "increase(mysql_global_status_slow_queries[1m]) > 0"), @@ -32,7 +31,6 @@ func TestAccTencentCloudMonitorAlertRule_basic(t *testing.T) { Config: testAlertRule_update, Check: resource.ComposeTestCheckFunc( testAccCheckAlertRuleExists("tencentcloud_monitor_tmp_alert_rule.basic"), - resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "instance_id", "prom-86azj3lg"), resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "rule_name", "test-rule_name_update"), resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "receivers.#", "1"), resource.TestCheckResourceAttr("tencentcloud_monitor_tmp_alert_rule.basic", "expr", "increase(mysql_global_status_slow_queries[1m]) > 1"),