Skip to content

fix(monitor): [122814398] tencentcloud_monitor_tmp_exporter_integration Update field type #3282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3282.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_monitor_tmp_exporter_integration: Update field type
```
52 changes: 39 additions & 13 deletions tencentcloud/services/monitor/service_tencentcloud_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
},
},
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down Expand Up @@ -44,8 +42,6 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" {
}
}
})
cluster_id = ""
kube_type = 3
}
```

Expand Down Expand Up @@ -106,7 +102,5 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" {
EOT
}
})
cluster_id = ""
kube_type = 3
}
```
10 changes: 2 additions & 8 deletions website/docs/r/monitor_tmp_exporter_integration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down Expand Up @@ -55,8 +53,6 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" {
}
}
})
cluster_id = ""
kube_type = 3
}
```

Expand Down Expand Up @@ -117,20 +113,18 @@ resource "tencentcloud_monitor_tmp_exporter_integration" "example" {
EOT
}
})
cluster_id = ""
kube_type = 3
}
```

## Argument Reference

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

Expand Down
Loading