|
| 1 | +## ADDED Requirements |
| 2 | + |
| 3 | +### Requirement: Resource manages TEO L7 acceleration rule lifecycle |
| 4 | + |
| 5 | +The `tencentcloud_teo_l7_acc_rule_v2` resource SHALL manage the full CRUD lifecycle of a TEO L7 acceleration rule using the following APIs: |
| 6 | +- Create: `CreateL7AccRules` with `ZoneId` and `Rules` parameters |
| 7 | +- Read: `DescribeL7AccRules` with `ZoneId` and `Filters` (rule-id filter using `Values`) |
| 8 | +- Update: `ModifyL7AccRule` with `ZoneId` and `Rule` (containing `RuleId`, `Status`, `RuleName`, `Description`, `Branches`) |
| 9 | +- Delete: `DeleteL7AccRules` with `ZoneId` and `RuleIds` |
| 10 | + |
| 11 | +The resource SHALL use a composite ID format `{zone_id}#{rule_id}` with `tccommon.FILED_SP` as separator. |
| 12 | + |
| 13 | +#### Scenario: Create a new L7 acceleration rule |
| 14 | +- **WHEN** user applies a Terraform configuration with `tencentcloud_teo_l7_acc_rule_v2` resource specifying `zone_id`, `status`, `rule_name`, `description`, and `branches` |
| 15 | +- **THEN** the resource SHALL call `CreateL7AccRules` API with the zone ID and a single `RuleEngineItem` containing the specified fields, and store the returned `rule_id` in state with composite ID format |
| 16 | + |
| 17 | +#### Scenario: Read an existing L7 acceleration rule |
| 18 | +- **WHEN** Terraform performs a refresh on the resource |
| 19 | +- **THEN** the resource SHALL call `DescribeL7AccRules` API with `zone_id` and a filter for `rule-id` with the stored `rule_id` as the filter value, and update state with the returned `status`, `rule_name`, `description`, `branches`, and `rule_priority` |
| 20 | + |
| 21 | +#### Scenario: Update an existing L7 acceleration rule |
| 22 | +- **WHEN** user modifies `status`, `rule_name`, `description`, or `branches` in the Terraform configuration |
| 23 | +- **THEN** the resource SHALL call `ModifyL7AccRule` API with `zone_id` and a `RuleEngineItem` containing the `rule_id` and updated fields |
| 24 | + |
| 25 | +#### Scenario: Delete an L7 acceleration rule |
| 26 | +- **WHEN** user destroys the resource |
| 27 | +- **THEN** the resource SHALL call `DeleteL7AccRules` API with `zone_id` and `rule_id` |
| 28 | + |
| 29 | +#### Scenario: Import an existing rule |
| 30 | +- **WHEN** user imports a resource using `terraform import` with ID format `{zone_id}#{rule_id}` |
| 31 | +- **THEN** the resource SHALL parse the composite ID and read the rule details from the API |
| 32 | + |
| 33 | +### Requirement: Resource schema defines correct field types and constraints |
| 34 | + |
| 35 | +The resource schema SHALL define the following fields: |
| 36 | +- `zone_id`: TypeString, Required, ForceNew - Zone ID for the TEO site |
| 37 | +- `status`: TypeString, Optional - Rule status (enable/disable) |
| 38 | +- `rule_name`: TypeString, Optional - Rule name (max 255 characters) |
| 39 | +- `description`: TypeList of TypeString, Optional - Rule annotations |
| 40 | +- `branches`: TypeList of Resource, Optional - Sub-rule branches with conditions and actions |
| 41 | +- `rule_id`: TypeString, Computed - Rule ID returned by the API |
| 42 | +- `rule_priority`: TypeInt, Computed - Rule priority (output only) |
| 43 | + |
| 44 | +#### Scenario: Zone ID is immutable after creation |
| 45 | +- **WHEN** user attempts to change `zone_id` after resource creation |
| 46 | +- **THEN** Terraform SHALL plan to destroy and recreate the resource (ForceNew behavior) |
| 47 | + |
| 48 | +#### Scenario: Optional fields can be omitted |
| 49 | +- **WHEN** user creates a resource without specifying `status`, `rule_name`, `description`, or `branches` |
| 50 | +- **THEN** the resource SHALL be created successfully with API defaults for those fields |
| 51 | + |
| 52 | +### Requirement: Error handling follows provider patterns |
| 53 | + |
| 54 | +The resource SHALL implement proper error handling: |
| 55 | +- All API calls MUST be wrapped with retry logic using `tccommon.RetryError()` |
| 56 | +- Create MUST verify the response is not nil and `RuleIds` is not empty before storing the ID |
| 57 | +- Read MUST check for nil response and empty rules list, logging the resource ID before clearing state |
| 58 | + |
| 59 | +#### Scenario: Create API returns empty response |
| 60 | +- **WHEN** the `CreateL7AccRules` API returns a nil response or empty `RuleIds` |
| 61 | +- **THEN** the resource SHALL return a `NonRetryableError` with a descriptive message |
| 62 | + |
| 63 | +#### Scenario: Read API returns no matching rule |
| 64 | +- **WHEN** the `DescribeL7AccRules` API returns an empty rules list |
| 65 | +- **THEN** the resource SHALL log the resource ID for debugging and set the ID to empty string to remove from state |
0 commit comments