diff --git a/.changelog/3282.txt b/.changelog/3282.txt new file mode 100644 index 0000000000..bbb3496c66 --- /dev/null +++ b/.changelog/3282.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_monitor_tmp_exporter_integration: Update field type +``` \ No newline at end of file diff --git a/tencentcloud/services/monitor/service_tencentcloud_monitor.go b/tencentcloud/services/monitor/service_tencentcloud_monitor.go index 6e222e7338..22d58410cc 100644 --- a/tencentcloud/services/monitor/service_tencentcloud_monitor.go +++ b/tencentcloud/services/monitor/service_tencentcloud_monitor.go @@ -544,14 +544,26 @@ func (me *MonitorService) DescribeMonitorTmpExporterIntegration(ctx context.Cont }() ids := strings.Split(tmpExporterIntegrationId, tccommon.FILED_SP) - if ids[0] != "" { - request.Name = &ids[0] + if len(ids) == 5 { + if ids[0] != "" { + request.Name = &ids[0] + } + + request.InstanceId = &ids[1] + kubeType, _ := strconv.Atoi(ids[2]) + request.KubeType = helper.IntInt64(kubeType) + request.ClusterId = &ids[3] + request.Kind = &ids[4] + } else if len(ids) == 3 { + if ids[0] != "" { + request.Name = &ids[0] + } + + request.InstanceId = &ids[1] + request.Kind = &ids[2] + } else { + return nil, fmt.Errorf("id is broken, id is %s", tmpExporterIntegrationId) } - request.InstanceId = &ids[1] - 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 { @@ -576,12 +588,26 @@ func (me *MonitorService) DeleteMonitorTmpExporterIntegrationById(ctx context.Co request := monitor.NewDeleteExporterIntegrationRequest() ids := strings.Split(tmpExporterIntegrationId, tccommon.FILED_SP) - request.Name = &ids[0] - request.InstanceId = &ids[1] - kubeType, _ := strconv.Atoi(ids[2]) - request.KubeType = helper.IntInt64(kubeType) - request.ClusterId = &ids[3] - request.Kind = &ids[4] + if len(ids) == 5 { + if ids[0] != "" { + request.Name = &ids[0] + } + + request.InstanceId = &ids[1] + kubeType, _ := strconv.Atoi(ids[2]) + request.KubeType = helper.IntInt64(kubeType) + request.ClusterId = &ids[3] + request.Kind = &ids[4] + } else if len(ids) == 3 { + if ids[0] != "" { + request.Name = &ids[0] + } + + request.InstanceId = &ids[1] + request.Kind = &ids[2] + } else { + return fmt.Errorf("id is broken, id is %s", tmpExporterIntegrationId) + } defer func() { if errRet != 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 6a9e69e069..229da9d692 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go @@ -44,13 +44,13 @@ func ResourceTencentCloudMonitorTmpExporterIntegration() *schema.Resource { "kube_type": { Type: schema.TypeInt, - Required: true, + Optional: true, Description: "Integration config.", }, "cluster_id": { Type: schema.TypeString, - Required: true, + Optional: true, Description: "Cluster ID.", }, }, @@ -89,7 +89,7 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD request.Content = helper.String(v.(string)) } - if v, ok := d.GetOk("kube_type"); ok { + if v, ok := d.GetOkExists("kube_type"); ok { kubeType = v.(int) request.KubeType = helper.IntInt64(kubeType) } @@ -99,6 +99,10 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD request.ClusterId = helper.String(clusterId) } + if kubeType == 0 && clusterId == "" { + return fmt.Errorf("`kube_type` and `cluster_id` can only be set simultaneously or not set at all") + } + initStatus := monitor.NewDescribePrometheusInstanceInitStatusRequest() initStatus.InstanceId = request.InstanceId err := resource.Retry(8*tccommon.ReadRetryTimeout, func() *resource.RetryError { @@ -165,7 +169,11 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD tmpExporterIntegrationId := *response.Response.Names[0] - d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, strconv.Itoa(kubeType), clusterId, kind}, tccommon.FILED_SP)) + if kubeType != 0 && clusterId != "" { + d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, strconv.Itoa(kubeType), clusterId, kind}, tccommon.FILED_SP)) + } else { + d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, kind}, tccommon.FILED_SP)) + } return resourceTencentCloudMonitorTmpExporterIntegrationRead(d, meta) } @@ -210,6 +218,13 @@ func resourceTencentCloudMonitorTmpExporterIntegrationUpdate(d *schema.ResourceD logId := tccommon.GetLogId(tccommon.ContextNil) + immutableArgs := []string{"instance_id", "kind", "kube_type", "cluster_id"} + for _, v := range immutableArgs { + if d.HasChange(v) { + return fmt.Errorf("argument `%s` cannot be changed.", v) + } + } + request := monitor.NewUpdateExporterIntegrationRequest() if v, ok := d.GetOk("instance_id"); ok { @@ -224,7 +239,7 @@ func resourceTencentCloudMonitorTmpExporterIntegrationUpdate(d *schema.ResourceD request.Content = helper.String(v.(string)) } - if v, ok := d.GetOk("kube_type"); ok { + if v, ok := d.GetOkExists("kube_type"); ok { request.KubeType = helper.IntInt64(v.(int)) } diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.md b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.md index 086bb73490..b3c5aaec5a 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.md +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.md @@ -11,8 +11,6 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" { instance_id = "prom-gzg3f1em" kind = "qcloud-exporter" content = "{\"name\":\"test\",\"kind\":\"qcloud-exporter\",\"spec\":{\"scrapeSpec\":{\"interval\":\"1m\",\"timeout\":\"1m\",\"relabelConfigs\":\"#metricRelabelings:\\n#- action: labeldrop\\n# regex: tmp_test_label\\n\"},\"instanceSpec\":{\"region\":\"Guangzhou\",\"role\":\"CM_QCSLinkedRoleInTMP\",\"useRole\":true,\"authProvider\":{\"method\":1,\"presetRole\":\"CM_QCSLinkedRoleInTMP\"},\"rateLimit\":1000,\"delaySeconds\":0,\"rangeSeconds\":0,\"reload_interval_minutes\":10,\"uin\":\"100023201586\",\"tag_key_operation\":\"ToUnderLineAndLower\"},\"exporterSpec\":{\"cvm\":false,\"cbs\":true,\"imageRegistry\":\"ccr.ccs.tencentyun.com\",\"cpu\":\"0.25\",\"memory\":\"0.5Gi\"}},\"status\":{}}" - cluster_id = "cls-csxm4phu" - kube_type = 3 } ``` @@ -44,8 +42,6 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" { } } }) - cluster_id = "" - kube_type = 3 } ``` @@ -106,7 +102,5 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" { EOT } }) - cluster_id = "" - kube_type = 3 } ``` \ No newline at end of file diff --git a/website/docs/r/monitor_tmp_exporter_integration.html.markdown b/website/docs/r/monitor_tmp_exporter_integration.html.markdown index 2c5bd57a4a..1510c54188 100644 --- a/website/docs/r/monitor_tmp_exporter_integration.html.markdown +++ b/website/docs/r/monitor_tmp_exporter_integration.html.markdown @@ -22,8 +22,6 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" { instance_id = "prom-gzg3f1em" kind = "qcloud-exporter" content = "{\"name\":\"test\",\"kind\":\"qcloud-exporter\",\"spec\":{\"scrapeSpec\":{\"interval\":\"1m\",\"timeout\":\"1m\",\"relabelConfigs\":\"#metricRelabelings:\\n#- action: labeldrop\\n# regex: tmp_test_label\\n\"},\"instanceSpec\":{\"region\":\"Guangzhou\",\"role\":\"CM_QCSLinkedRoleInTMP\",\"useRole\":true,\"authProvider\":{\"method\":1,\"presetRole\":\"CM_QCSLinkedRoleInTMP\"},\"rateLimit\":1000,\"delaySeconds\":0,\"rangeSeconds\":0,\"reload_interval_minutes\":10,\"uin\":\"100023201586\",\"tag_key_operation\":\"ToUnderLineAndLower\"},\"exporterSpec\":{\"cvm\":false,\"cbs\":true,\"imageRegistry\":\"ccr.ccs.tencentyun.com\",\"cpu\":\"0.25\",\"memory\":\"0.5Gi\"}},\"status\":{}}" - cluster_id = "cls-csxm4phu" - kube_type = 3 } ``` @@ -55,8 +53,6 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" { } } }) - cluster_id = "" - kube_type = 3 } ``` @@ -117,8 +113,6 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" { EOT } }) - cluster_id = "" - kube_type = 3 } ``` @@ -126,11 +120,11 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" { The following arguments are supported: -* `cluster_id` - (Required, String) Cluster ID. * `content` - (Required, String) Integration config. * `instance_id` - (Required, String) Instance id. * `kind` - (Required, String) Type. -* `kube_type` - (Required, Int) Integration config. +* `cluster_id` - (Optional, String) Cluster ID. +* `kube_type` - (Optional, Int) Integration config. ## Attributes Reference