From 051f12d59f6a18e5da2b6c01bc2e0cd40f2c3270 Mon Sep 17 00:00:00 2001 From: arunma Date: Fri, 28 Mar 2025 09:57:20 +0800 Subject: [PATCH 1/4] fix(monitor): [122656438] modify read return --- .../services/tmp/resource_tc_monitor_tmp_alert_rule.go | 3 ++- .../services/tmp/resource_tc_monitor_tmp_cvm_agent.go | 3 ++- .../tmp/resource_tc_monitor_tmp_exporter_integration.go | 3 ++- .../services/tmp/resource_tc_monitor_tmp_recording_rule.go | 3 ++- .../services/tmp/resource_tc_monitor_tmp_scrape_job.go | 3 ++- .../services/tmp/resource_tc_monitor_tmp_tke_alert_policy.go | 3 ++- .../tmp/resource_tc_monitor_tmp_tke_cluster_agent.go | 3 ++- .../services/tmp/resource_tc_monitor_tmp_tke_config.go | 4 ++-- .../tmp/resource_tc_monitor_tmp_tke_global_notification.go | 5 +++-- .../services/tmp/resource_tc_monitor_tmp_tke_template.go | 4 ++-- .../tmp/resource_tc_monitor_tmp_tke_template_attachment.go | 3 ++- 11 files changed, 23 insertions(+), 14 deletions(-) diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_rule.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_rule.go index 0411927f22..a173dcedf4 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_rule.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_rule.go @@ -227,7 +227,8 @@ func resourceTencentCloudMonitorTmpAlertRuleRead(d *schema.ResourceData, meta in if tmpAlertRule == nil { d.SetId("") - return fmt.Errorf("resource `tmpAlertRule` %s does not exist", ids[1]) + log.Printf("[WARN]%s resource `tmpAlertRule` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } _ = d.Set("instance_id", ids[0]) diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_cvm_agent.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_cvm_agent.go index efe1bd0585..5f046a647f 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_cvm_agent.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_cvm_agent.go @@ -116,7 +116,8 @@ func resourceTencentCloudMonitorTmpCvmAgentRead(d *schema.ResourceData, meta int if tmpCvmAgent == nil { d.SetId("") - return fmt.Errorf("resource `tmpCvmAgent` %s does not exist", ids[1]) + log.Printf("[WARN]%s resource `tmpCvmAgent` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } if tmpCvmAgent.InstanceId != nil { diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go index 2fda2c7404..6a9e69e069 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go @@ -189,7 +189,8 @@ func resourceTencentCloudMonitorTmpExporterIntegrationRead(d *schema.ResourceDat if tmpExporterIntegration == nil { d.SetId("") - return fmt.Errorf("resource `tmpExporterIntegration` %s does not exist", tmpExporterIntegrationId) + log.Printf("[WARN]%s resource `tmpExporterIntegration` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } if tmpExporterIntegration.Kind != nil { diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_recording_rule.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_recording_rule.go index e7a3998633..f781be37b9 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_recording_rule.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_recording_rule.go @@ -122,7 +122,8 @@ func resourceTencentCloudMonitorTmpRecordingRuleRead(d *schema.ResourceData, met if recordingRule == nil { d.SetId("") - return fmt.Errorf("resource `recordingRule` %s does not exist", ids[1]) + log.Printf("[WARN]%s resource `recordingRule` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } _ = d.Set("instance_id", ids[0]) diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_scrape_job.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_scrape_job.go index 5168e9dd29..d4e7542289 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_scrape_job.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_scrape_job.go @@ -118,7 +118,8 @@ func resourceTencentCloudMonitorTmpScrapeJobRead(d *schema.ResourceData, meta in if tmpScrapeJob == nil { d.SetId("") - return fmt.Errorf("resource `tmpScrapeJob` %s does not exist", tmpScrapeJobId) + log.Printf("[WARN]%s resource `tmpScrapeJob` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } _ = d.Set("instance_id", strings.Split(tmpScrapeJobId, tccommon.FILED_SP)[1]) diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_alert_policy.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_alert_policy.go index ec931f5df2..0c84d8f2a3 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_alert_policy.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_alert_policy.go @@ -458,7 +458,8 @@ func resourceTencentCloudTkeTmpAlertPolicyRead(d *schema.ResourceData, meta inte log.Printf("[DEBUG] tmpAlertPolicy[%v]\n", tmpAlertPolicy) if tmpAlertPolicy == nil { d.SetId("") - return fmt.Errorf("resource `AlertPolicy` %s does not exist", tmpAlertPolicyId) + log.Printf("[WARN]%s resource `AlertPolicy` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } rules := make([]map[string]interface{}, 0, len(tmpAlertPolicy.Rules)) diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_cluster_agent.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_cluster_agent.go index c2f59027e3..6f6fc485c6 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_cluster_agent.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_cluster_agent.go @@ -328,7 +328,8 @@ func resourceTencentCloudMonitorTmpTkeClusterAgentRead(d *schema.ResourceData, m if clusterAgent == nil { d.SetId("") - return fmt.Errorf("resource `global_notification` %s does not exist", instanceId) + log.Printf("[WARN]%s resource `cluster_agent` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } var agents []map[string]interface{} diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_config.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_config.go index 073f03eea2..bc0bb24235 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_config.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_config.go @@ -2,7 +2,6 @@ package tmp import ( "context" - "fmt" "log" "strings" @@ -141,7 +140,8 @@ func resourceTencentCloudTkeTmpConfigRead(d *schema.ResourceData, meta interface if params == nil { d.SetId("") - return fmt.Errorf("resource `prometheus_config` %s does not exist", configId) + log.Printf("[WARN]%s resource `prometheus_config` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } if e := d.Set("config", params.Config); e != nil { diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_global_notification.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_global_notification.go index eb0fac5821..de7c29813b 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_global_notification.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_global_notification.go @@ -2,7 +2,7 @@ package tmp import ( "context" - "fmt" + "log" tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" svcmonitor "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/monitor" @@ -176,7 +176,8 @@ func resourceTencentCloudMonitorTmpTkeGlobalNotificationRead(d *schema.ResourceD if globalNotification == nil { d.SetId("") - return fmt.Errorf("resource `global_notification` %s does not exist", instanceId) + log.Printf("[WARN]%s resource `global_notification` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } if *globalNotification.Enabled { diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_template.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_template.go index 4be266f112..b0ea68341c 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_template.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_template.go @@ -2,7 +2,6 @@ package tmp import ( "context" - "fmt" "log" tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" @@ -332,7 +331,8 @@ func resourceTencentCloudMonitorTmpTkeTemplateRead(d *schema.ResourceData, meta if template == nil { d.SetId("") - return fmt.Errorf("resource `template` %s does not exist", templateId) + log.Printf("[WARN]%s resource `template` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } templates := make([]map[string]interface{}, 0) diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_template_attachment.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_template_attachment.go index d44e4c08a6..ab1d442299 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_template_attachment.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_template_attachment.go @@ -186,7 +186,8 @@ func resourceTencentCloudMonitorTmpTkeTemplateAttachmentRead(d *schema.ResourceD if targets == nil || len(targets) < 1 { d.SetId("") - return fmt.Errorf("resource `targets` %s does not exist", templateId) + log.Printf("[WARN]%s resource `targets` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil } tempTargets := make([]map[string]interface{}, 0) From e213ff22e6e47c4bf2dc4215c4c1b1f8f913468a Mon Sep 17 00:00:00 2001 From: arunma Date: Fri, 28 Mar 2025 10:02:09 +0800 Subject: [PATCH 2/4] feat: add changelog --- .changelog/3249.txt | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .changelog/3249.txt diff --git a/.changelog/3249.txt b/.changelog/3249.txt new file mode 100644 index 0000000000..5764f5f507 --- /dev/null +++ b/.changelog/3249.txt @@ -0,0 +1,43 @@ +```release-note:enhancement +resource/tencentcloud_monitor_tmp_alert_rule: Modify the query to be empty without error. +``` + +```release-note:enhancement +resource/tencentcloud_monitor_tmpCvmAgent: Modify the query to be empty without error. +``` + +```release-note:enhancement +resource/tencentcloud_monitor_tmp_exporter_integration: Modify the query to be empty without error. +``` + +```release-note:enhancement +resource/tencentcloud_tmp_monitor_recording_rule: Modify the query to be empty without error. +``` + +```release-note:enhancement +resource/tencentcloud_monitor_tmpScrapeJob: Modify the query to be empty without error. +``` + +```release-note:enhancement +resource/tencentcloud_tke_tmp_alert_policy: Modify the query to be empty without error. +``` + +```release-note:enhancement +resource/tencentcloud_monitor_tmp_tke_cluster_agent: Modify the query to be empty without error. +``` + +```release-note:enhancement +resource/tencentcloud_tke_tmp_config: Modify the query to be empty without error. +``` + +```release-note:enhancement +resource/tencentcloud_monitor_tmp_tke_global_notification: Modify the query to be empty without error. +``` + +```release-note:enhancement +resource/tencentcloud_monitor_tmp_tke_template: Modify the query to be empty without error. +``` + +```release-note:enhancement +resource/tencentcloud_monitor_tmp_tke_template_attachment: Modify the query to be empty without error. +``` \ No newline at end of file From 2eae2377f34d1791c02075096d737ba5b7ba3a65 Mon Sep 17 00:00:00 2001 From: arunma Date: Fri, 28 Mar 2025 18:23:24 +0800 Subject: [PATCH 3/4] fix: moidfy test --- .../monitor/service_tencentcloud_monitor.go | 2 +- .../resource_tc_monitor_tmp_alert_group_test.go | 4 ++-- .../tmp/resource_tc_monitor_tmp_alert_rule_test.go | 4 ++-- .../resource_tc_monitor_tmp_tke_alert_policy.go | 14 ++++++++------ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tencentcloud/services/monitor/service_tencentcloud_monitor.go b/tencentcloud/services/monitor/service_tencentcloud_monitor.go index 6e222e7338..f7a0bef8b2 100644 --- a/tencentcloud/services/monitor/service_tencentcloud_monitor.go +++ b/tencentcloud/services/monitor/service_tencentcloud_monitor.go @@ -616,7 +616,7 @@ func (me *MonitorService) DescribeMonitorTmpAlertRuleById(ctx context.Context, i }() request.InstanceId = &instanceId - request.RuleId = &tmpAlertRuleId + // request.RuleId = &tmpAlertRuleId ratelimit.Check(request.GetAction()) response, err := me.client.UseMonitorClient().DescribeAlertRules(request) diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_group_test.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_group_test.go index e204d40da6..71b947e684 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_group_test.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_group_test.go @@ -112,7 +112,7 @@ resource "tencentcloud_monitor_tmp_alert_group" "tmp_alert_group" { "notice-om017kc2", ] group_name = "tf-test" - instance_id = tencentcloud_monitor_tmp_instance.basic.id + instance_id = tencentcloud_monitor_tmp_instance.example.id repeat_interval = "5m" custom_receiver { @@ -145,7 +145,7 @@ resource "tencentcloud_monitor_tmp_alert_group" "tmp_alert_group" { "notice-om017kc2", ] group_name = "tf-test-up" - instance_id = tencentcloud_monitor_tmp_instance.basic.id + instance_id = tencentcloud_monitor_tmp_instance.example.id repeat_interval = "1h" custom_receiver { diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_rule_test.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_rule_test.go index 49736e3a04..cdf6ae11d4 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_rule_test.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_alert_rule_test.go @@ -125,7 +125,7 @@ func testAccCheckAlertRuleExists(r string) resource.TestCheckFunc { const testAlertRule_basic = testInstance_basic + ` resource "tencentcloud_monitor_tmp_alert_rule" "basic" { - instance_id = tencentcloud_monitor_tmp_instance.basic.id + instance_id = tencentcloud_monitor_tmp_instance.example.id rule_name = "test-rule_name" receivers = ["notice-tj75hgqj"] expr = "increase(mysql_global_status_slow_queries[1m]) > 0" @@ -143,7 +143,7 @@ resource "tencentcloud_monitor_tmp_alert_rule" "basic" { const testAlertRule_update = testInstance_basic + ` resource "tencentcloud_monitor_tmp_alert_rule" "basic" { - instance_id = tencentcloud_monitor_tmp_instance.basic.id + instance_id = tencentcloud_monitor_tmp_instance.example.id rule_name = "test-rule_name_update" receivers = ["notice-tj75hgqj"] expr = "increase(mysql_global_status_slow_queries[1m]) > 1" diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_alert_policy.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_alert_policy.go index 0c84d8f2a3..26400f3677 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_alert_policy.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_tke_alert_policy.go @@ -491,13 +491,15 @@ func resourceTencentCloudTkeTmpAlertPolicyRead(d *schema.ResourceData, meta inte } 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) + if notify.AlertManager != nil { + alertManager := map[string]interface{}{ + "url": notify.AlertManager.Url, + "cluster_type": notify.AlertManager.ClusterType, + "cluster_id": notify.AlertManager.ClusterId, + } + alertManagers = append(alertManagers, alertManager) + } var notifyWay []string if len(notify.NotifyWay) > 0 { From bbbbd0b2e3e13a14451bc65dbdff32fc05f7a408 Mon Sep 17 00:00:00 2001 From: arunma Date: Fri, 28 Mar 2025 18:28:44 +0800 Subject: [PATCH 4/4] fix: moidfy test --- tencentcloud/acctest/basic.go | 10 +++++----- .../services/monitor/service_tencentcloud_monitor.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tencentcloud/acctest/basic.go b/tencentcloud/acctest/basic.go index 32dd227fcc..486dae7944 100644 --- a/tencentcloud/acctest/basic.go +++ b/tencentcloud/acctest/basic.go @@ -214,14 +214,14 @@ variable "international_subnet_id" { // Tke Exclusive Network Environment const ( TkeExclusiveVpcName = "keep_tke_exclusive_vpc" - DefaultTkeClusterId = "cls-r8gqwjw6" + DefaultTkeClusterId = "cls-2weetaxi" DefaultTkeClusterName = "keep-tke-cluster" DefaultTkeClusterType = "tke" - DefaultPrometheusId = "prom-1lspn8sw" + DefaultPrometheusId = "prom-9ywsz034" DefaultTemplateId = "temp-gqunlvo1" - ClusterPrometheusId = "prom-g261hacc" - TkeClusterIdAgent = "cls-9ae9qo9k" - TkeClusterTypeAgent = "eks" + ClusterPrometheusId = "prom-9ywsz034" + TkeClusterIdAgent = "cls-2weetaxi" + TkeClusterTypeAgent = "tke" DefaultAgentId = "agent-q3zy8gt8" ) diff --git a/tencentcloud/services/monitor/service_tencentcloud_monitor.go b/tencentcloud/services/monitor/service_tencentcloud_monitor.go index f7a0bef8b2..6e222e7338 100644 --- a/tencentcloud/services/monitor/service_tencentcloud_monitor.go +++ b/tencentcloud/services/monitor/service_tencentcloud_monitor.go @@ -616,7 +616,7 @@ func (me *MonitorService) DescribeMonitorTmpAlertRuleById(ctx context.Context, i }() request.InstanceId = &instanceId - // request.RuleId = &tmpAlertRuleId + request.RuleId = &tmpAlertRuleId ratelimit.Check(request.GetAction()) response, err := me.client.UseMonitorClient().DescribeAlertRules(request)