Skip to content

Commit a031ae5

Browse files
authored
Merge pull request #1529 from tencentcloudstack/feat/add_tmp_computed_field
add computed field
2 parents 863101d + 6506c98 commit a031ae5

File tree

4 files changed

+75
-12
lines changed

4 files changed

+75
-12
lines changed

.changelog/1529.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_monitor_tmp_instance: add computed field: `ipv4_address`, `proxy_address`, `remote_write`, `api_root_path`
3+
```

tencentcloud/resource_tc_monitor_tmp_instance.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ func resourceTencentCloudMonitorTmpInstance() *schema.Resource {
8181
Optional: true,
8282
Description: "Tag description list.",
8383
},
84+
85+
"ipv4_address": {
86+
Type: schema.TypeString,
87+
Computed: true,
88+
Description: "Instance IPv4 address.",
89+
},
90+
91+
"remote_write": {
92+
Type: schema.TypeString,
93+
Computed: true,
94+
Description: "Prometheus remote write address.",
95+
},
96+
97+
"api_root_path": {
98+
Type: schema.TypeString,
99+
Computed: true,
100+
Description: "Prometheus HTTP API root address.",
101+
},
102+
103+
"proxy_address": {
104+
Type: schema.TypeString,
105+
Computed: true,
106+
Description: "Proxy address.",
107+
},
84108
},
85109
}
86110
}
@@ -186,7 +210,8 @@ func resourceTencentCloudMonitorTmpInstanceRead(d *schema.ResourceData, meta int
186210

187211
if tmpInstance == nil {
188212
d.SetId("")
189-
return fmt.Errorf("resource `tmpInstance` %s does not exist", tmpInstanceId)
213+
log.Printf("[WARN]%s resource `tmpInstance` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
214+
return nil
190215
}
191216

192217
if tmpInstance.InstanceName != nil {
@@ -209,6 +234,22 @@ func resourceTencentCloudMonitorTmpInstanceRead(d *schema.ResourceData, meta int
209234
_ = d.Set("zone", tmpInstance.Zone)
210235
}
211236

237+
if tmpInstance.IPv4Address != nil {
238+
_ = d.Set("ipv4_address", tmpInstance.IPv4Address)
239+
}
240+
241+
if tmpInstance.RemoteWrite != nil {
242+
_ = d.Set("remote_write", tmpInstance.RemoteWrite)
243+
}
244+
245+
if tmpInstance.ApiRootPath != nil {
246+
_ = d.Set("api_root_path", tmpInstance.ApiRootPath)
247+
}
248+
249+
if tmpInstance.ProxyAddress != nil {
250+
_ = d.Set("proxy_address", tmpInstance.ProxyAddress)
251+
}
252+
212253
tcClient := meta.(*TencentCloudClient).apiV3Conn
213254
tagService := &TagService{client: tcClient}
214255
tags, err := tagService.DescribeResourceTags(ctx, "monitor", "prom-instance", tcClient.Region, d.Id())

tencentcloud/service_tencentcloud_monitor.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,20 +321,36 @@ func (me *MonitorService) DescribeMonitorTmpInstance(ctx context.Context, tmpIns
321321
}()
322322
request.InstanceIds = []*string{&tmpInstanceId}
323323

324-
response, err := me.client.UseMonitorClient().DescribePrometheusInstances(request)
325-
if err != nil {
326-
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
327-
logId, request.GetAction(), request.ToJsonString(), err.Error())
328-
errRet = err
329-
return
324+
var (
325+
offset int64 = 0
326+
limit int64 = 20
327+
)
328+
instances := make([]*monitor.PrometheusInstancesItem, 0)
329+
for {
330+
request.Offset = &offset
331+
request.Limit = &limit
332+
response, err := me.client.UseMonitorClient().DescribePrometheusInstances(request)
333+
if err != nil {
334+
errRet = err
335+
return
336+
}
337+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
338+
339+
if response == nil || len(response.Response.InstanceSet) < 1 {
340+
break
341+
}
342+
instances = append(instances, response.Response.InstanceSet...)
343+
if len(response.Response.InstanceSet) < int(limit) {
344+
break
345+
}
346+
347+
offset += limit
330348
}
331-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
332-
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
333349

334-
if len(response.Response.InstanceSet) < 1 {
350+
if len(instances) < 1 {
335351
return
336352
}
337-
tmpInstance = response.Response.InstanceSet[0]
353+
tmpInstance = instances[0]
338354
return
339355
}
340356

website/docs/r/monitor_tmp_instance.html.markdown

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ The following arguments are supported:
4242
In addition to all arguments above, the following attributes are exported:
4343

4444
* `id` - ID of the resource.
45-
45+
* `api_root_path` - Prometheus HTTP API root address.
46+
* `ipv4_address` - Instance IPv4 address.
47+
* `proxy_address` - Proxy address.
48+
* `remote_write` - Prometheus remote write address.
4649

4750

4851
## Import

0 commit comments

Comments
 (0)