Skip to content

Commit 61c9c12

Browse files
iac-agentCodeBuddyTerraform Providergitmkn
authored
fix(teo): [134409549]Optimize the handling of empty return results in the read function of tencentcloud_teo_l7_acc_rule_v2. (#4147)
* docs(teo): update tencentcloud_teo_l7_acc_rule_v2 resource documentation * fix(teo): revert field descriptions and fix read function nil check - Restore original field descriptions in resource_tc_teo_l7_acc_rule_extension.go - Fix Read function to check for empty Rules array: if respData == nil || len(respData.Rules) == 0 - Restore website documentation to match original descriptions - Move openspec change from archive back to active state with updated tasks * docs(teo): archive openspec change for teo_l7_acc_rule_v2 * fix(teo): normalize openspec proposal and update changelog for l7_acc_rule_v2 Read fix - Update .changelog/4147.txt to reflect the actual bug fix (Read function handling empty Rules array) - Move openspec change from archive back to active state - Normalize openspec proposal to accurately describe the branch change * docs(teo): update teo l7 acc rule v2 openspec archive * fix: modify md * fix: modify md --------- Co-authored-by: CodeBuddy <codebuddy@tencentcloud.com> Co-authored-by: Terraform Provider <terraform@tencentcloud.com> Co-authored-by: arunma <arunma@tencent.com>
1 parent 5c22d78 commit 61c9c12

8 files changed

Lines changed: 70 additions & 1 deletion

File tree

.changelog/4147.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/tencentcloud_teo_l7_acc_rule_v2: fix Read function to handle empty Rules array from API response
3+
```
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-04-28
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Context
2+
3+
The `tencentcloud_teo_l7_acc_rule_v2` resource manages individual TEO L7 acceleration rules. The Read function previously only checked `if respData == nil` to determine if the resource was deleted. However, the DescribeL7AccRules API can return a valid response with an empty `Rules` array when the rule no longer exists, which was not handled.
4+
5+
## Goals / Non-Goals
6+
7+
**Goals:**
8+
- Fix Read function to handle empty Rules array from API response
9+
- Ensure resource is properly marked as deleted when API returns empty Rules
10+
11+
**Non-Goals:**
12+
- Changing any other resource behavior
13+
14+
## Decisions
15+
16+
1. **Fix Read function nil check**: Change `if respData == nil {` to `if respData == nil || len(respData.Rules) == 0 {` to properly handle the case where the API returns a response with an empty Rules array (resource deleted).
17+
18+
## Risks / Trade-offs
19+
20+
- No risks. This is a purely defensive fix that handles an edge case in the API response.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Why
2+
3+
The `tencentcloud_teo_l7_acc_rule_v2` resource's Read function only checked if `respData == nil` before marking the resource as deleted. However, the API can also return a valid response with an empty `Rules` array when the rule has been deleted. This caused the Read function to proceed with an empty array and potentially panic or produce incorrect state.
4+
5+
## What Changes
6+
7+
- Fix Read function: change `if respData == nil` to `if respData == nil || len(respData.Rules) == 0` to handle empty Rules array
8+
9+
## Capabilities
10+
11+
### Modified Capabilities
12+
- `l7-acc-rule-v2-read-fix`: Fix the Read function to properly detect deleted resources when the API returns an empty Rules array instead of nil.
13+
14+
## Impact
15+
16+
- `tencentcloud/services/teo/resource_tc_teo_l7_acc_rule_v2.go`: Fix Read function nil check to also handle empty Rules array
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## MODIFIED Requirements
2+
3+
### Requirement: Read function handles empty Rules array
4+
5+
The `tencentcloud_teo_l7_acc_rule_v2` resource's Read function SHALL handle both nil response and empty Rules array as indicators that the resource has been deleted.
6+
7+
#### Scenario: API returns empty Rules array
8+
- **WHEN** the DescribeL7AccRules API returns a response with an empty `Rules` array
9+
- **THEN** the Read function SHALL mark the resource as deleted by calling `d.SetId("")`
10+
11+
#### Scenario: API returns nil response
12+
- **WHEN** the DescribeL7AccRules API returns a nil response
13+
- **THEN** the Read function SHALL mark the resource as deleted by calling `d.SetId("")`
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1. 修复 Read 函数
2+
3+
- [x] 1.1 将 Read 函数中 `if respData == nil {` 修改为 `if respData == nil || len(respData.Rules) == 0 {`

openspec/specs/rule-ids-output/spec.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ The `actions.name` field description SHALL list all valid action names matching
3535
#### Scenario: name description matches SDK
3636
- **WHEN** a user reads the `actions.name` field description
3737
- **THEN** it SHALL include all supported actions from `RuleEngineAction.Name` in the SDK, including `SetContentIdentifier`, `Vary`, `ContentCompression`, and `OriginAuthentication`
38+
39+
### Requirement: Read function handles empty Rules array
40+
41+
The `tencentcloud_teo_l7_acc_rule_v2` resource's Read function SHALL handle both nil response and empty Rules array as indicators that the resource has been deleted.
42+
43+
#### Scenario: API returns empty Rules array
44+
- **WHEN** the DescribeL7AccRules API returns a response with an empty `Rules` array
45+
- **THEN** the Read function SHALL mark the resource as deleted by calling `d.SetId("")`
46+
47+
#### Scenario: API returns nil response
48+
- **WHEN** the DescribeL7AccRules API returns a nil response
49+
- **THEN** the Read function SHALL mark the resource as deleted by calling `d.SetId("")`

tencentcloud/services/teo/resource_tc_teo_l7_acc_rule_v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func ResourceTencentCloudTeoL7AccRuleV2Read(d *schema.ResourceData, meta interfa
148148
return err
149149
}
150150

151-
if respData == nil {
151+
if respData == nil || len(respData.Rules) == 0 {
152152
d.SetId("")
153153
log.Printf("[WARN]%s resource `teo_l7_acc_rule` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
154154
return nil

0 commit comments

Comments
 (0)