Skip to content

Commit fcd6427

Browse files
committed
add
1 parent 9d28c5c commit fcd6427

File tree

2 files changed

+50
-16
lines changed

2 files changed

+50
-16
lines changed

tencentcloud/services/monitor/service_tencentcloud_monitor.go

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -544,14 +544,26 @@ func (me *MonitorService) DescribeMonitorTmpExporterIntegration(ctx context.Cont
544544
}()
545545

546546
ids := strings.Split(tmpExporterIntegrationId, tccommon.FILED_SP)
547-
if ids[0] != "" {
548-
request.Name = &ids[0]
547+
if len(ids) == 5 {
548+
if ids[0] != "" {
549+
request.Name = &ids[0]
550+
}
551+
552+
request.InstanceId = &ids[1]
553+
kubeType, _ := strconv.Atoi(ids[2])
554+
request.KubeType = helper.IntInt64(kubeType)
555+
request.ClusterId = &ids[3]
556+
request.Kind = &ids[4]
557+
} else if len(ids) == 3 {
558+
if ids[0] != "" {
559+
request.Name = &ids[0]
560+
}
561+
562+
request.InstanceId = &ids[1]
563+
request.Kind = &ids[2]
564+
} else {
565+
return nil, fmt.Errorf("id is broken, id is %s", tmpExporterIntegrationId)
549566
}
550-
request.InstanceId = &ids[1]
551-
kubeType, _ := strconv.Atoi(ids[2])
552-
request.KubeType = helper.IntInt64(kubeType)
553-
request.ClusterId = &ids[3]
554-
request.Kind = &ids[4]
555567

556568
response, err := me.client.UseMonitorClient().DescribeExporterIntegrations(request)
557569
if err != nil {
@@ -576,12 +588,26 @@ func (me *MonitorService) DeleteMonitorTmpExporterIntegrationById(ctx context.Co
576588
request := monitor.NewDeleteExporterIntegrationRequest()
577589
ids := strings.Split(tmpExporterIntegrationId, tccommon.FILED_SP)
578590

579-
request.Name = &ids[0]
580-
request.InstanceId = &ids[1]
581-
kubeType, _ := strconv.Atoi(ids[2])
582-
request.KubeType = helper.IntInt64(kubeType)
583-
request.ClusterId = &ids[3]
584-
request.Kind = &ids[4]
591+
if len(ids) == 5 {
592+
if ids[0] != "" {
593+
request.Name = &ids[0]
594+
}
595+
596+
request.InstanceId = &ids[1]
597+
kubeType, _ := strconv.Atoi(ids[2])
598+
request.KubeType = helper.IntInt64(kubeType)
599+
request.ClusterId = &ids[3]
600+
request.Kind = &ids[4]
601+
} else if len(ids) == 3 {
602+
if ids[0] != "" {
603+
request.Name = &ids[0]
604+
}
605+
606+
request.InstanceId = &ids[1]
607+
request.Kind = &ids[2]
608+
} else {
609+
return fmt.Errorf("id is broken, id is %s", tmpExporterIntegrationId)
610+
}
585611

586612
defer func() {
587613
if errRet != nil {

tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD
8989
request.Content = helper.String(v.(string))
9090
}
9191

92-
if v, ok := d.GetOk("kube_type"); ok {
92+
if v, ok := d.GetOkExists("kube_type"); ok {
9393
kubeType = v.(int)
9494
request.KubeType = helper.IntInt64(kubeType)
9595
}
@@ -99,6 +99,10 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD
9999
request.ClusterId = helper.String(clusterId)
100100
}
101101

102+
if kubeType == 0 && clusterId == "" {
103+
return fmt.Errorf("`kube_type` and `cluster_id` can only be set simultaneously or not set at all")
104+
}
105+
102106
initStatus := monitor.NewDescribePrometheusInstanceInitStatusRequest()
103107
initStatus.InstanceId = request.InstanceId
104108
err := resource.Retry(8*tccommon.ReadRetryTimeout, func() *resource.RetryError {
@@ -165,7 +169,11 @@ func resourceTencentCloudMonitorTmpExporterIntegrationCreate(d *schema.ResourceD
165169

166170
tmpExporterIntegrationId := *response.Response.Names[0]
167171

168-
d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, strconv.Itoa(kubeType), clusterId, kind}, tccommon.FILED_SP))
172+
if kubeType != 0 && clusterId != "" {
173+
d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, strconv.Itoa(kubeType), clusterId, kind}, tccommon.FILED_SP))
174+
} else {
175+
d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, kind}, tccommon.FILED_SP))
176+
}
169177

170178
return resourceTencentCloudMonitorTmpExporterIntegrationRead(d, meta)
171179
}
@@ -231,7 +239,7 @@ func resourceTencentCloudMonitorTmpExporterIntegrationUpdate(d *schema.ResourceD
231239
request.Content = helper.String(v.(string))
232240
}
233241

234-
if v, ok := d.GetOk("kube_type"); ok {
242+
if v, ok := d.GetOkExists("kube_type"); ok {
235243
request.KubeType = helper.IntInt64(v.(int))
236244
}
237245

0 commit comments

Comments
 (0)