Skip to content

Commit f0a4b40

Browse files
committed
feat(cls): add timezone parameter to cls_cos_shipper resource
1 parent df1dcc5 commit f0a4b40

17 files changed

Lines changed: 4318 additions & 701 deletions

File tree

.changelog/4159.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_cls_cos_shipper: add timezone parameter support
3+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ require (
4545
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.3.16
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.3.52
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
48-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.3.58
49-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.102
48+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.3.103
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.103
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/config v1.3.80
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.3.69
5252
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.3.30

go.sum

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.3.52 h1:t3/KRe8e
875875
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.3.52/go.mod h1:llHcTUrqshNqR3ZHhrooFogFcoXh6Er8SnkHfGpdK04=
876876
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033 h1:dIr+MVsZeUBiKZELfJh5HRJdI+BI6lCp5pv/2oXekuk=
877877
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033/go.mod h1:7oFlNimGSTHFy6JV7W/IZKuJWr+NUjCnGLTvb9MWNrY=
878-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.3.58 h1:pTW5RzN6Lx887sHK+KVNX7mG9YfRS3XA3gPGAEId+Fk=
879-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.3.58/go.mod h1:SHM5qxbY3qzCz2pSoXwE13xV2qRNXGkBskNiSgn5KfU=
878+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.3.103 h1:6uJoaCafWAOMd9mp6u5WfyZIwYyLqvEmx7DNmmLCyYU=
879+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.3.103/go.mod h1:+9DZIuORfHQJ3Oz0I8IYOSwoYiRL7dwyeKmEGuYwl5o=
880880
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.414/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
881881
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.486/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
882882
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.533/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
@@ -957,8 +957,11 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.89/go.mod h
957957
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.90/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
958958
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.94/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
959959
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.95/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
960-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.102 h1:3n7BpLOPnE9Rv3Y9Jxgl/XaQX3GzktO+dEaAbtVbjSk=
960+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.98/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
961+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.101/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
961962
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.102/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
963+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.103 h1:W1dpZ/Q6+DjUpiAUSmIHuFn7rAvetlSqzQCtf0tKEEA=
964+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.103/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
962965
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/config v1.3.80 h1:chnsNBeJn3MieFLki4hpbzoml5NiTvLVzOTqYRVxQho=
963966
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/config v1.3.80/go.mod h1:B/ezGtlvDhZlleNM+2QdvZccrUi+J+fN6vMnDDsZnuM=
964967
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.1.51 h1:pGwrfCBBCt1u+EDHwfNj9NLQpvk5MVKVMcsE7SvwqM4=
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
schema: spec-driven
2+
created: 2026-05-28
3+
status: applied
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## Context
2+
3+
The `tencentcloud_cls_cos_shipper` resource manages CLS (Cloud Log Service) log shipping rules to COS (Cloud Object Storage). The resource currently supports parameters like `topic_id`, `bucket`, `prefix`, `shipper_name`, `interval`, `max_size`, `filter_rules`, `partition`, `compress`, `content`, `filename_mode`, `start_time`, `end_time`, and `storage_type`.
4+
5+
The cloud API already supports a `TimeZone` parameter in `CreateShipperRequest`, `ModifyShipperRequest`, and returns it in `ShipperInfo` (via `DescribeShippers`). However, the Terraform resource does not yet expose this parameter.
6+
7+
The resource file is at `tencentcloud/services/cls/resource_tc_cls_cos_shipper.go` and follows the standard CRUD pattern with retry logic.
8+
9+
## Goals / Non-Goals
10+
11+
**Goals:**
12+
- Add `time_zone` as an Optional string parameter to the `tencentcloud_cls_cos_shipper` resource schema
13+
- Wire the parameter into Create, Read, and Update methods
14+
- Maintain backward compatibility (existing configurations without `time_zone` continue to work)
15+
16+
**Non-Goals:**
17+
- Adding other missing parameters (e.g., `DSLFilter`, `RoleArn`, `ExternalId`)
18+
- Changing existing parameter behavior
19+
- Modifying the service layer (`service_tencentcloud_cls.go`)
20+
21+
## Decisions
22+
23+
1. **Schema field type**: Use `schema.TypeString` with `Optional: true` and `Computed: true`. The field is optional on create/update, and the API may return a default value on read.
24+
25+
2. **No validation function**: The API accepts a wide range of GMT/UTC timezone formats. Rather than maintaining a large validation list in Terraform, we rely on the API to validate the input and return appropriate errors.
26+
27+
3. **Update support**: The `time_zone` field is updatable via `ModifyShipper` API, so it will be handled in the Update method with `d.HasChange("time_zone")` pattern, consistent with other string fields like `storage_type`.
28+
29+
4. **Read support**: Read from `ShipperInfo.TimeZone` in the Read method with nil check before setting, consistent with existing patterns like `storage_type`.
30+
31+
## Risks / Trade-offs
32+
33+
- [Risk] API timezone format validation may change → Mitigation: Rely on API-side validation; no client-side validation needed.
34+
- [Trade-off] No client-side validation means users get API errors instead of Terraform plan-time errors → Acceptable since the timezone list is extensive and may be updated server-side.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Why
2+
3+
The `tencentcloud_cls_cos_shipper` resource currently does not support the `TimeZone` parameter, which is used to generate time variables in the file path when shipping logs to COS. Users need this parameter to control the timezone used in COS file path generation, ensuring logs are organized according to their preferred timezone.
4+
5+
## What Changes
6+
7+
- Add a new optional `time_zone` parameter to the `tencentcloud_cls_cos_shipper` resource
8+
- The parameter maps to `TimeZone` in the CLS cloud API (CreateShipper, ModifyShipper, DescribeShippers)
9+
- The parameter accepts GMT/UTC timezone format strings (e.g., "GMT+08:00", "UTC+08:00")
10+
- The parameter is used in Create, Update, and Read operations
11+
12+
## Capabilities
13+
14+
### New Capabilities
15+
- `cls-cos-shipper-timezone`: Add `time_zone` parameter support to the CLS COS shipper resource for controlling timezone in COS file path generation
16+
17+
### Modified Capabilities
18+
19+
## Impact
20+
21+
- `tencentcloud/services/cls/resource_tc_cls_cos_shipper.go`: Add `time_zone` schema field and wire it into Create, Read, Update methods
22+
- `tencentcloud/services/cls/resource_tc_cls_cos_shipper_test.go`: Add unit test cases for the new parameter
23+
- `tencentcloud/services/cls/resource_tc_cls_cos_shipper.md`: Update example usage documentation
24+
- Cloud API SDK: Uses existing `TimeZone` field in `CreateShipperRequest`, `ModifyShipperRequest`, and `ShipperInfo` structs from `github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016`
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## ADDED Requirements
2+
3+
### Requirement: Support time_zone parameter in CLS COS shipper resource
4+
5+
The `tencentcloud_cls_cos_shipper` resource SHALL support an optional `time_zone` parameter that maps to the `TimeZone` field in the CLS cloud API. This parameter is used to generate time variables in the file path when shipping logs to COS.
6+
7+
The parameter SHALL be:
8+
- Type: string
9+
- Optional: true
10+
- Computed: true
11+
- Description: "The timezone used to generate time variables in the COS file path. Supports GMT/UTC timezone formats (e.g., GMT+08:00, UTC+08:00)."
12+
13+
#### Scenario: Create shipper with time_zone specified
14+
15+
- **WHEN** user creates a `tencentcloud_cls_cos_shipper` resource with `time_zone = "GMT+08:00"`
16+
- **THEN** the `CreateShipper` API request SHALL include `TimeZone` set to `"GMT+08:00"`
17+
- **AND** the resource state SHALL store the `time_zone` value after successful creation
18+
19+
#### Scenario: Create shipper without time_zone specified
20+
21+
- **WHEN** user creates a `tencentcloud_cls_cos_shipper` resource without specifying `time_zone`
22+
- **THEN** the `CreateShipper` API request SHALL NOT include `TimeZone` parameter
23+
- **AND** the resource state SHALL read back whatever value the API returns for `TimeZone` in the Read method
24+
25+
#### Scenario: Read shipper with time_zone
26+
27+
- **WHEN** the resource Read method is called
28+
- **AND** the `ShipperInfo.TimeZone` field in the `DescribeShippers` response is not nil
29+
- **THEN** the resource state SHALL set `time_zone` to the value of `ShipperInfo.TimeZone`
30+
31+
#### Scenario: Read shipper without time_zone
32+
33+
- **WHEN** the resource Read method is called
34+
- **AND** the `ShipperInfo.TimeZone` field in the `DescribeShippers` response is nil
35+
- **THEN** the resource state SHALL NOT set `time_zone` (skip the `d.Set` call)
36+
37+
#### Scenario: Update shipper time_zone
38+
39+
- **WHEN** user updates the `time_zone` field of an existing `tencentcloud_cls_cos_shipper` resource
40+
- **THEN** the `ModifyShipper` API request SHALL include `TimeZone` set to the new value
41+
- **AND** the resource state SHALL reflect the updated value after successful modification
42+
43+
#### Scenario: Import existing shipper with time_zone
44+
45+
- **WHEN** user imports an existing CLS COS shipper resource
46+
- **THEN** the Read method SHALL correctly populate the `time_zone` field from the API response
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## 1. Schema Definition
2+
3+
- [x] 1.1 Add `time_zone` field to the resource schema in `tencentcloud/services/cls/resource_tc_cls_cos_shipper.go` as an Optional, Computed string field with appropriate description
4+
5+
## 2. CRUD Implementation
6+
7+
- [x] 2.1 Add `time_zone` handling in the Create method (`resourceTencentCloudClsCosShipperCreate`): read from ResourceData and set `request.TimeZone`
8+
- [x] 2.2 Add `time_zone` handling in the Read method (`resourceTencentCloudClsCosShipperRead`): read from `ShipperInfo.TimeZone` with nil check and set to state
9+
- [x] 2.3 Add `time_zone` handling in the Update method (`resourceTencentCloudClsCosShipperUpdate`): handle `d.HasChange("time_zone")` and set `request.TimeZone`
10+
11+
## 3. Unit Tests
12+
13+
- [x] 3.1 Add unit test cases in `tencentcloud/services/cls/resource_tc_cls_cos_shipper_test.go` using gomonkey to mock cloud API calls, verifying the `time_zone` parameter is correctly handled in Create, Read, and Update operations
14+
15+
## 4. Documentation
16+
17+
- [x] 4.1 Update `tencentcloud/services/cls/resource_tc_cls_cos_shipper.md` to include `time_zone` parameter in the example usage
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## ADDED Requirements
2+
3+
### Requirement: Support time_zone parameter in CLS COS shipper resource
4+
5+
The `tencentcloud_cls_cos_shipper` resource SHALL support an optional `time_zone` parameter that maps to the `TimeZone` field in the CLS cloud API. This parameter is used to generate time variables in the file path when shipping logs to COS.
6+
7+
The parameter SHALL be:
8+
- Type: string
9+
- Optional: true
10+
- Computed: true
11+
- Description: "The timezone used to generate time variables in the COS file path. Supports GMT/UTC timezone formats (e.g., GMT+08:00, UTC+08:00)."
12+
13+
#### Scenario: Create shipper with time_zone specified
14+
15+
- **WHEN** user creates a `tencentcloud_cls_cos_shipper` resource with `time_zone = "GMT+08:00"`
16+
- **THEN** the `CreateShipper` API request SHALL include `TimeZone` set to `"GMT+08:00"`
17+
- **AND** the resource state SHALL store the `time_zone` value after successful creation
18+
19+
#### Scenario: Create shipper without time_zone specified
20+
21+
- **WHEN** user creates a `tencentcloud_cls_cos_shipper` resource without specifying `time_zone`
22+
- **THEN** the `CreateShipper` API request SHALL NOT include `TimeZone` parameter
23+
- **AND** the resource state SHALL read back whatever value the API returns for `TimeZone` in the Read method
24+
25+
#### Scenario: Read shipper with time_zone
26+
27+
- **WHEN** the resource Read method is called
28+
- **AND** the `ShipperInfo.TimeZone` field in the `DescribeShippers` response is not nil
29+
- **THEN** the resource state SHALL set `time_zone` to the value of `ShipperInfo.TimeZone`
30+
31+
#### Scenario: Read shipper without time_zone
32+
33+
- **WHEN** the resource Read method is called
34+
- **AND** the `ShipperInfo.TimeZone` field in the `DescribeShippers` response is nil
35+
- **THEN** the resource state SHALL NOT set `time_zone` (skip the `d.Set` call)
36+
37+
#### Scenario: Update shipper time_zone
38+
39+
- **WHEN** user updates the `time_zone` field of an existing `tencentcloud_cls_cos_shipper` resource
40+
- **THEN** the `ModifyShipper` API request SHALL include `TimeZone` set to the new value
41+
- **AND** the resource state SHALL reflect the updated value after successful modification
42+
43+
#### Scenario: Import existing shipper with time_zone
44+
45+
- **WHEN** user imports an existing CLS COS shipper resource
46+
- **THEN** the Read method SHALL correctly populate the `time_zone` field from the API response

tencentcloud/services/cls/resource_tc_cls_cos_shipper.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ func ResourceTencentCloudClsCosShipper() *schema.Resource {
228228
Optional: true,
229229
Description: "COS bucket storage type. support: STANDARD_IA, ARCHIVE, DEEP_ARCHIVE, STANDARD, MAZ_STANDARD, MAZ_STANDARD_IA, INTELLIGENT_TIERING.",
230230
},
231+
"time_zone": {
232+
Type: schema.TypeString,
233+
Optional: true,
234+
Computed: true,
235+
Description: "Timezone used to generate the time variable in the COS file path when shipping logs. Supports GMT and UTC timezone formats, e.g., `GMT+08:00`, `UTC+08:00`.",
236+
},
231237
},
232238
}
233239
}
@@ -388,6 +394,10 @@ func resourceTencentCloudClsCosShipperCreate(d *schema.ResourceData, meta interf
388394
request.StorageType = helper.String(v.(string))
389395
}
390396

397+
if v, ok := d.GetOk("time_zone"); ok {
398+
request.TimeZone = helper.String(v.(string))
399+
}
400+
391401
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
392402
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().CreateShipper(request)
393403
if e != nil {
@@ -534,6 +544,10 @@ func resourceTencentCloudClsCosShipperRead(d *schema.ResourceData, meta interfac
534544
_ = d.Set("storage_type", shipper.StorageType)
535545
}
536546

547+
if shipper.TimeZone != nil {
548+
_ = d.Set("time_zone", shipper.TimeZone)
549+
}
550+
537551
return nil
538552
}
539553

@@ -708,6 +722,12 @@ func resourceTencentCloudClsCosShipperUpdate(d *schema.ResourceData, meta interf
708722
}
709723
}
710724

725+
if d.HasChange("time_zone") {
726+
if v, ok := d.GetOk("time_zone"); ok {
727+
request.TimeZone = helper.String(v.(string))
728+
}
729+
}
730+
711731
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
712732
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().ModifyShipper(request)
713733
if e != nil {

0 commit comments

Comments
 (0)