Skip to content
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

add computed field #1529

Merged
merged 2 commits into from
Jan 29, 2023
Merged
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/1529.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_monitor_tmp_instance: add computed field: `ipv4_address`, `proxy_address`, `remote_write`, `api_root_path`
```
43 changes: 42 additions & 1 deletion tencentcloud/resource_tc_monitor_tmp_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ func resourceTencentCloudMonitorTmpInstance() *schema.Resource {
Optional: true,
Description: "Tag description list.",
},

"ipv4_address": {
Type: schema.TypeString,
Computed: true,
Description: "Instance IPv4 address.",
},

"remote_write": {
Type: schema.TypeString,
Computed: true,
Description: "Prometheus remote write address.",
},

"api_root_path": {
Type: schema.TypeString,
Computed: true,
Description: "Prometheus HTTP API root address.",
},

"proxy_address": {
Type: schema.TypeString,
Computed: true,
Description: "Proxy address.",
},
},
}
}
Expand Down Expand Up @@ -186,7 +210,8 @@ func resourceTencentCloudMonitorTmpInstanceRead(d *schema.ResourceData, meta int

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

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

if tmpInstance.IPv4Address != nil {
_ = d.Set("ipv4_address", tmpInstance.IPv4Address)
}

if tmpInstance.RemoteWrite != nil {
_ = d.Set("remote_write", tmpInstance.RemoteWrite)
}

if tmpInstance.ApiRootPath != nil {
_ = d.Set("api_root_path", tmpInstance.ApiRootPath)
}

if tmpInstance.ProxyAddress != nil {
_ = d.Set("proxy_address", tmpInstance.ProxyAddress)
}

tcClient := meta.(*TencentCloudClient).apiV3Conn
tagService := &TagService{client: tcClient}
tags, err := tagService.DescribeResourceTags(ctx, "monitor", "prom-instance", tcClient.Region, d.Id())
Expand Down
36 changes: 26 additions & 10 deletions tencentcloud/service_tencentcloud_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,20 +321,36 @@ func (me *MonitorService) DescribeMonitorTmpInstance(ctx context.Context, tmpIns
}()
request.InstanceIds = []*string{&tmpInstanceId}

response, err := me.client.UseMonitorClient().DescribePrometheusInstances(request)
if err != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
logId, request.GetAction(), request.ToJsonString(), err.Error())
errRet = err
return
var (
offset int64 = 0
limit int64 = 20
)
instances := make([]*monitor.PrometheusInstancesItem, 0)
for {
request.Offset = &offset
request.Limit = &limit
response, err := me.client.UseMonitorClient().DescribePrometheusInstances(request)
if err != nil {
errRet = err
return
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

if response == nil || len(response.Response.InstanceSet) < 1 {
break
}
instances = append(instances, response.Response.InstanceSet...)
if len(response.Response.InstanceSet) < int(limit) {
break
}

offset += limit
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

if len(response.Response.InstanceSet) < 1 {
if len(instances) < 1 {
return
}
tmpInstance = response.Response.InstanceSet[0]
tmpInstance = instances[0]
return
}

Expand Down
5 changes: 4 additions & 1 deletion website/docs/r/monitor_tmp_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `id` - ID of the resource.

* `api_root_path` - Prometheus HTTP API root address.
* `ipv4_address` - Instance IPv4 address.
* `proxy_address` - Proxy address.
* `remote_write` - Prometheus remote write address.


## Import
Expand Down