Skip to content

Commit 228133f

Browse files
iac-agentVanHWZ
andauthored
feat(tmp): [133996720]add new parameters to monitor tmp instance resource (#4144)
* feat(tmp): add new parameters to monitor tmp instance resource --------- Co-authored-by: vincenthuangwz <van136682262@gmail.com>
1 parent 9d0ebc4 commit 228133f

22 files changed

Lines changed: 1696 additions & 553 deletions

File tree

.changelog/4144.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: support `long_term_storage_retention_time` parameter for configuring archive storage retention duration
3+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ require (
7070
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live v1.3.95
7171
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb v1.0.672
7272
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.3.65
73-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.3.49
73+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.3.101
7474
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mps v1.3.45
7575
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.3.89
7676
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.3.63

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb v1.0.672 h1:sR3
10191019
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb v1.0.672/go.mod h1:o3rBKhtfIJfw4BG22M0CQVLQAc0WqIsbyRI/EW52Ka0=
10201020
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.3.65 h1:ZMG98KxfY0HefEU0U2/kDm2g9IUSqXAtjKzrM+X3jZE=
10211021
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.3.65/go.mod h1:AOJNqusaTIhb3EXZfqFDj7YOQGdReMGakBqEdx9tblI=
1022-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.3.49 h1:j+xW0faHHUVpf28Ogv7ClWHniprdKoa7j6FEW4WMVbs=
1023-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.3.49/go.mod h1:ihQpv91ZdiYflH3B7FTnu13yv06xnVyzbT66lP6dPCg=
1022+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.3.101 h1:r8PjkCuXrztjLyBROWTww0RJUq+a+l5ybPLl6GGlov8=
1023+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.3.101/go.mod h1:+cX4PEEehIIbyHy9plpXOTShlFWtc9OC1AWcmOrOMT8=
10241024
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mps v1.3.45 h1:35PD/GXaOl3QhL1fI5a3Q+jcenzR1PqfuGxltOeO48w=
10251025
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mps v1.3.45/go.mod h1:OrNv7U7R19HZySH5o+/ag3EyAH1tDIwb5z23K5fY5vw=
10261026
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mqtt v1.3.7 h1:ms2KfUZ9OYiKx75dqPaOuBTj6QoCJC90FN10d1gr720=
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
schema: spec-driven
2+
created: 2026-05-25
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Context
2+
3+
The `tencentcloud_monitor_tmp_instance` resource manages Prometheus instances via TencentCloud Monitor APIs. The cloud APIs support an `InstanceAttributes` parameter (type: `[]*PrometheusRuleKV`) that carries special instance properties. One supported attribute is `LongTermStorageRetentionTime` (archive storage retention in days, value range 60-730).
4+
5+
- `CreatePrometheusMultiTenantInstancePostPayMode` supports `InstanceAttributes` to set `LongTermStorageRetentionTime` at creation time.
6+
- `ModifyPrometheusInstanceAttributes` supports `InstanceAttributes` to update `LongTermStorageRetentionTime` after creation.
7+
- `DescribePrometheusInstances` returns `InstanceAttributes` in the `PrometheusInstancesItem` struct.
8+
9+
Current resource file: `tencentcloud/services/tmp/resource_tc_monitor_tmp_instance.go`
10+
Service layer: `tencentcloud/services/monitor/service_tencentcloud_monitor.go`
11+
12+
## Goals / Non-Goals
13+
14+
**Goals:**
15+
- Add `long_term_storage_retention_time` as an Optional integer parameter (range 60-730) to the resource schema.
16+
- Pass `InstanceAttributes` with key `LongTermStorageRetentionTime` to the Create API when provided.
17+
- Pass `InstanceAttributes` with key `LongTermStorageRetentionTime` to the Modify API when the value changes.
18+
- Read back `LongTermStorageRetentionTime` from the Describe API response's `InstanceAttributes` array.
19+
- Update unit tests to verify Create/Read/Update with `long_term_storage_retention_time`.
20+
21+
**Non-Goals:**
22+
- Supporting other `InstanceAttributes` keys (e.g., `CreatedFrom`, `FreeTrialExpireAt`) — out of scope.
23+
- Adding validation logic for value range in schema (rely on API-side validation).
24+
25+
## Decisions
26+
27+
1. **Parameter mutability**: The parameter is mutable after creation via `ModifyPrometheusInstanceAttributes` API, so updates are supported.
28+
29+
2. **Schema definition**: The parameter will be `Optional` + `Computed` (int type). Optional because users may or may not want to configure archive storage. Computed because the value can be read back from the API (may be set server-side).
30+
31+
3. **Read implementation**: Iterate over `InstanceAttributes` array from `PrometheusInstancesItem`, find the entry with key `LongTermStorageRetentionTime`, parse the string value as integer, and set in state.
32+
33+
4. **Wire format**: The API uses `PrometheusRuleKV` struct (`Key` string, `Value` string), so the integer value is converted to/from string for API communication.
34+
35+
## Risks / Trade-offs
36+
37+
- [Risk] The `InstanceAttributes` array in the API response may contain other keys besides `LongTermStorageRetentionTime` → Mitigation: Only read the specific key we care about, ignore others.
38+
- [Risk] Backward compatibility concern if existing state files don't have this field → Mitigation: The field is Optional+Computed, so existing configurations without it will simply read the value from the API on next refresh without breaking.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Why
2+
3+
The `tencentcloud_monitor_tmp_instance` resource currently does not support configuring the long-term storage retention time (`LongTermStorageRetentionTime`) via `InstanceAttributes`. The cloud APIs `CreatePrometheusMultiTenantInstancePostPayMode` and `ModifyPrometheusInstanceAttributes` both support the `InstanceAttributes` parameter with key `LongTermStorageRetentionTime` (value: 60-730 days), and the `DescribePrometheusInstances` response returns the `InstanceAttributes` array including this key. Adding this parameter allows users to configure archive storage duration for Prometheus instances via Terraform.
4+
5+
## What Changes
6+
7+
- Add a new optional parameter `long_term_storage_retention_time` (type: int, range: 60-730) to the `tencentcloud_monitor_tmp_instance` resource schema.
8+
- Wire the parameter to the `CreatePrometheusMultiTenantInstancePostPayMode` API's `InstanceAttributes` field (key: `LongTermStorageRetentionTime`) during resource creation.
9+
- Wire the parameter to the `ModifyPrometheusInstanceAttributes` API's `InstanceAttributes` field during resource update.
10+
- Read back the `LongTermStorageRetentionTime` from the `DescribePrometheusInstances` API response's `InstanceAttributes` array in the Read function.
11+
12+
## Capabilities
13+
14+
### New Capabilities
15+
- `monitor-tmp-instance-long-term-storage-retention-time`: Add `long_term_storage_retention_time` parameter to `tencentcloud_monitor_tmp_instance` resource for configuring archive storage retention duration (60-730 days).
16+
17+
### Modified Capabilities
18+
19+
## Impact
20+
21+
- Resource file: `tencentcloud/services/tmp/resource_tc_monitor_tmp_instance.go` — schema addition, Create/Read/Update logic changes.
22+
- Test file: `tencentcloud/services/tmp/resource_tc_monitor_tmp_instance_test.go` — updated unit test cases.
23+
- Documentation: `tencentcloud/services/tmp/resource_tc_monitor_tmp_instance.md` — updated parameter documentation.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# monitor-tmp-instance-long-term-storage-retention-time Specification
2+
3+
## Purpose
4+
Support configuring the archive storage retention duration (LongTermStorageRetentionTime) for Prometheus instances via the `tencentcloud_monitor_tmp_instance` resource's `InstanceAttributes` parameter.
5+
6+
## Requirements
7+
### Requirement: Resource supports long_term_storage_retention_time parameter
8+
The `tencentcloud_monitor_tmp_instance` resource SHALL support an optional `long_term_storage_retention_time` parameter (int type, range 60-730) that allows users to configure the archive storage retention duration for the Prometheus instance.
9+
10+
#### Scenario: Create instance with long_term_storage_retention_time specified
11+
- **WHEN** user specifies `long_term_storage_retention_time` in the resource configuration
12+
- **THEN** the system SHALL pass the `InstanceAttributes` field with key `LongTermStorageRetentionTime` and the specified value to the `CreatePrometheusMultiTenantInstancePostPayMode` API request
13+
14+
#### Scenario: Create instance without long_term_storage_retention_time
15+
- **WHEN** user does not specify `long_term_storage_retention_time` in the resource configuration
16+
- **THEN** the system SHALL NOT pass the `InstanceAttributes` field to the Create API request, and the resource SHALL be created successfully without archive storage configuration
17+
18+
#### Scenario: Read long_term_storage_retention_time from API
19+
- **WHEN** the resource Read function is invoked
20+
- **THEN** the system SHALL read the `InstanceAttributes` array from the `DescribePrometheusInstances` API response, find the entry with key `LongTermStorageRetentionTime`, parse its value as integer, and set it in state
21+
22+
#### Scenario: Modify long_term_storage_retention_time after creation
23+
- **WHEN** user changes the `long_term_storage_retention_time` value in an existing resource configuration
24+
- **THEN** the system SHALL pass the `InstanceAttributes` field with key `LongTermStorageRetentionTime` and the new value to the `ModifyPrometheusInstanceAttributes` API request
25+
26+
#### Scenario: Import existing instance with long_term_storage_retention_time
27+
- **WHEN** user imports an existing Prometheus instance that has `LongTermStorageRetentionTime` set in `InstanceAttributes`
28+
- **THEN** the system SHALL correctly read and populate the `long_term_storage_retention_time` attribute in state
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## 1. Schema and CRUD Implementation
2+
3+
- [x] 1.1 Add `long_term_storage_retention_time` parameter (Optional, Computed, int) to the resource schema in `tencentcloud/services/tmp/resource_tc_monitor_tmp_instance.go`
4+
- [x] 1.2 Wire `long_term_storage_retention_time` to `request.InstanceAttributes` with key `LongTermStorageRetentionTime` in the Create function
5+
- [x] 1.3 Wire `long_term_storage_retention_time` to `request.InstanceAttributes` with key `LongTermStorageRetentionTime` in the Update function (when changed)
6+
- [x] 1.4 Read `LongTermStorageRetentionTime` from `PrometheusInstancesItem.InstanceAttributes` in the Read function, parsing the string value to int
7+
8+
## 2. Unit Tests
9+
10+
- [x] 2.1 Update unit test cases in `tencentcloud/services/tmp/resource_tc_monitor_tmp_instance_test.go` to verify Create with `long_term_storage_retention_time`, Read populating the field from `InstanceAttributes`, Read with nil `InstanceAttributes`, and Update modifying the value
11+
12+
## 3. Documentation
13+
14+
- [x] 3.1 Update `tencentcloud/services/tmp/resource_tc_monitor_tmp_instance.md` to include `long_term_storage_retention_time` in the parameter documentation
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# monitor-tmp-instance-long-term-storage-retention-time Specification
2+
3+
## Purpose
4+
Support configuring the archive storage retention duration (LongTermStorageRetentionTime) for Prometheus instances via the `tencentcloud_monitor_tmp_instance` resource's `InstanceAttributes` parameter.
5+
6+
## Requirements
7+
### Requirement: Resource supports long_term_storage_retention_time parameter
8+
The `tencentcloud_monitor_tmp_instance` resource SHALL support an optional `long_term_storage_retention_time` parameter (int type, range 60-730) that allows users to configure the archive storage retention duration for the Prometheus instance.
9+
10+
#### Scenario: Create instance with long_term_storage_retention_time specified
11+
- **WHEN** user specifies `long_term_storage_retention_time` in the resource configuration
12+
- **THEN** the system SHALL pass the `InstanceAttributes` field with key `LongTermStorageRetentionTime` and the specified value to the `CreatePrometheusMultiTenantInstancePostPayMode` API request
13+
14+
#### Scenario: Create instance without long_term_storage_retention_time
15+
- **WHEN** user does not specify `long_term_storage_retention_time` in the resource configuration
16+
- **THEN** the system SHALL NOT pass the `InstanceAttributes` field to the Create API request, and the resource SHALL be created successfully without archive storage configuration
17+
18+
#### Scenario: Read long_term_storage_retention_time from API
19+
- **WHEN** the resource Read function is invoked
20+
- **THEN** the system SHALL read the `InstanceAttributes` array from the `DescribePrometheusInstances` API response, find the entry with key `LongTermStorageRetentionTime`, parse its value as integer, and set it in state
21+
22+
#### Scenario: Modify long_term_storage_retention_time after creation
23+
- **WHEN** user changes the `long_term_storage_retention_time` value in an existing resource configuration
24+
- **THEN** the system SHALL pass the `InstanceAttributes` field with key `LongTermStorageRetentionTime` and the new value to the `ModifyPrometheusInstanceAttributes` API request
25+
26+
#### Scenario: Import existing instance with long_term_storage_retention_time
27+
- **WHEN** user imports an existing Prometheus instance that has `LongTermStorageRetentionTime` set in `InstanceAttributes`
28+
- **THEN** the system SHALL correctly read and populate the `long_term_storage_retention_time` attribute in state

tencentcloud/services/tmp/resource_tc_monitor_tmp_instance.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ func ResourceTencentCloudMonitorTmpInstance() *schema.Resource {
8585
Computed: true,
8686
Description: "Proxy address.",
8787
},
88+
89+
"long_term_storage_retention_time": {
90+
Type: schema.TypeInt,
91+
Optional: true,
92+
Computed: true,
93+
Description: "Long-term storage retention time(in days). Value range: 60-730.",
94+
},
8895
},
8996
}
9097
}
@@ -119,6 +126,15 @@ func resourceTencentCloudMonitorTmpInstanceCreate(d *schema.ResourceData, meta i
119126
request.Zone = helper.String(v.(string))
120127
}
121128

129+
if v, ok := d.GetOkExists("long_term_storage_retention_time"); ok {
130+
request.InstanceAttributes = []*monitor.PrometheusRuleKV{
131+
{
132+
Key: helper.String("LongTermStorageRetentionTime"),
133+
Value: helper.String(fmt.Sprintf("%d", v.(int))),
134+
},
135+
}
136+
}
137+
122138
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
123139
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMonitorClient().CreatePrometheusMultiTenantInstancePostPayMode(request)
124140
if e != nil {
@@ -241,6 +257,17 @@ func resourceTencentCloudMonitorTmpInstanceRead(d *schema.ResourceData, meta int
241257
_ = d.Set("proxy_address", tmpInstance.ProxyAddress)
242258
}
243259

260+
if tmpInstance.InstanceAttributes != nil {
261+
for _, attr := range tmpInstance.InstanceAttributes {
262+
if attr.Key != nil && *attr.Key == "LongTermStorageRetentionTime" && attr.Value != nil {
263+
var longTermStorageRetentionTime int
264+
fmt.Sscanf(*attr.Value, "%d", &longTermStorageRetentionTime)
265+
_ = d.Set("long_term_storage_retention_time", longTermStorageRetentionTime)
266+
break
267+
}
268+
}
269+
}
270+
244271
tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
245272
tagService := svctag.NewTagService(tcClient)
246273
tags, err := tagService.DescribeResourceTags(ctx, "monitor", "prom-instance", tcClient.Region, d.Id())
@@ -285,6 +312,17 @@ func resourceTencentCloudMonitorTmpInstanceUpdate(d *schema.ResourceData, meta i
285312
}
286313
}
287314

315+
if d.HasChange("long_term_storage_retention_time") {
316+
if v, ok := d.GetOkExists("long_term_storage_retention_time"); ok {
317+
request.InstanceAttributes = []*monitor.PrometheusRuleKV{
318+
{
319+
Key: helper.String("LongTermStorageRetentionTime"),
320+
Value: helper.String(fmt.Sprintf("%d", v.(int))),
321+
},
322+
}
323+
}
324+
}
325+
288326
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
289327
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMonitorClient().ModifyPrometheusInstanceAttributes(request)
290328
if e != nil {

0 commit comments

Comments
 (0)