|
| 1 | +## ADDED Requirements |
| 2 | + |
| 3 | +### Requirement: CKafka Instance Resource Schema |
| 4 | +The system SHALL define a Terraform resource `tencentcloud_ckafka_instance` (RESOURCE_KIND_GENERAL) covering the full CRUD lifecycle of a CKafka instance. The schema SHALL include a `delete_protection_enable` field with the following characteristics: |
| 5 | +- `delete_protection_enable` (Optional, Computed, TypeInt): 实例删除保护开关,取值 `1`(开启)/ `0`(关闭)。未显式配置时由云端回填,不触发 plan diff。 |
| 6 | + |
| 7 | +#### Scenario: delete_protection_enable is optional and computed |
| 8 | +- **WHEN** a user does not set `delete_protection_enable` in the Terraform configuration |
| 9 | +- **THEN** the system SHALL populate `delete_protection_enable` from the `DescribeInstanceAttributes` API response (Computed behavior) without triggering a plan diff |
| 10 | + |
| 11 | +#### Scenario: delete_protection_enable accepts user input |
| 12 | +- **WHEN** a user sets `delete_protection_enable = 1` or `delete_protection_enable = 0` in the Terraform configuration |
| 13 | +- **THEN** the schema SHALL accept the integer value and mark it as a candidate for create/update |
| 14 | + |
| 15 | +### Requirement: CKafka Instance Create Operation |
| 16 | +The system SHALL, after successfully creating a CKafka instance, call `ModifyInstanceAttributes` API to set instance attributes. When the user has explicitly configured `delete_protection_enable`, the system SHALL fill `request.DeleteProtectionEnable` with the configured int64 value (`1` or `0`) and include it in the same `ModifyInstanceAttributes` call that sets other post-creation attributes. |
| 17 | + |
| 18 | +#### Scenario: Create with delete_protection_enable set to 1 |
| 19 | +- **WHEN** the user sets `delete_protection_enable = 1` in the Terraform configuration and creates the instance |
| 20 | +- **THEN** the system SHALL call `ModifyInstanceAttributes` with `DeleteProtectionEnable = 1` after the instance is created |
| 21 | + |
| 22 | +#### Scenario: Create with delete_protection_enable set to 0 |
| 23 | +- **WHEN** the user sets `delete_protection_enable = 0` in the Terraform configuration and creates the instance |
| 24 | +- **THEN** the system SHALL call `ModifyInstanceAttributes` with `DeleteProtectionEnable = 0` (using GetOkExists so the explicit 0 value is not skipped) |
| 25 | + |
| 26 | +#### Scenario: Create without delete_protection_enable configured |
| 27 | +- **WHEN** the user does not set `delete_protection_enable` in the Terraform configuration |
| 28 | +- **THEN** the system SHALL NOT fill `DeleteProtectionEnable` in the `ModifyInstanceAttributes` request, preserving the cloud-side default |
| 29 | + |
| 30 | +### Requirement: CKafka Instance Update Operation |
| 31 | +The system SHALL, when `delete_protection_enable` changes in the Terraform configuration, call `ModifyInstanceAttributes` API with `InstanceId` and the updated `DeleteProtectionEnable` value. This field SHALL be mutable in-place (not ForceNew, not in `immutableArgs`). |
| 32 | + |
| 33 | +#### Scenario: Update delete_protection_enable from 0 to 1 |
| 34 | +- **WHEN** `delete_protection_enable` changes from `0` to `1` in the Terraform configuration |
| 35 | +- **THEN** the system SHALL call `ModifyInstanceAttributes` with `DeleteProtectionEnable = 1` |
| 36 | +- **AND** the update SHALL be performed in-place without resource recreation |
| 37 | + |
| 38 | +#### Scenario: Update delete_protection_enable from 1 to 0 |
| 39 | +- **WHEN** `delete_protection_enable` changes from `1` to `0` in the Terraform configuration |
| 40 | +- **THEN** the system SHALL call `ModifyInstanceAttributes` with `DeleteProtectionEnable = 0` |
| 41 | + |
| 42 | +#### Scenario: delete_protection_enable not changed |
| 43 | +- **WHEN** `delete_protection_enable` is not changed during an update |
| 44 | +- **THEN** the system SHALL NOT include `DeleteProtectionEnable` in the `ModifyInstanceAttributes` request for this field |
| 45 | + |
| 46 | +### Requirement: CKafka Instance Read Operation |
| 47 | +The system SHALL read the `delete_protection_enable` value from the `DescribeInstanceAttributes` API response (`InstanceAttributesResponse.DeleteProtectionEnable`). Before calling `d.Set("delete_protection_enable", ...)`, the system SHALL check that the response field is not nil; if nil, the system SHALL skip the set operation. |
| 48 | + |
| 49 | +#### Scenario: Read delete_protection_enable from DescribeInstanceAttributes |
| 50 | +- **WHEN** the Read operation calls `DescribeInstanceAttributes` and the response `DeleteProtectionEnable` is not nil |
| 51 | +- **THEN** the system SHALL set `delete_protection_enable` in Terraform state to the returned value |
| 52 | + |
| 53 | +#### Scenario: Read with nil DeleteProtectionEnable |
| 54 | +- **WHEN** the Read operation calls `DescribeInstanceAttributes` and the response `DeleteProtectionEnable` is nil |
| 55 | +- **THEN** the system SHALL skip `d.Set("delete_protection_enable", ...)` to avoid a nil pointer issue |
| 56 | + |
| 57 | +### Requirement: CKafka Instance Unit Tests |
| 58 | +The system SHALL provide unit tests in `resource_tc_ckafka_instance_test.go` using gomonkey to mock cloud API calls, covering the `delete_protection_enable` handling in Create, Update, and Read operations. |
| 59 | + |
| 60 | +#### Scenario: Unit tests pass |
| 61 | +- **WHEN** `go test` is run with `-gcflags=all=-l` on the test file |
| 62 | +- **THEN** all test cases for `delete_protection_enable` Create (set to 1 and 0), Update (change 0→1 and 1→0), and Read SHALL pass |
| 63 | + |
| 64 | +#### Scenario: Create with delete_protection_enable test |
| 65 | +- **WHEN** a test simulates creating an instance with `delete_protection_enable = 1` |
| 66 | +- **THEN** the mocked `ModifyInstanceAttributes` SHALL be invoked with `DeleteProtectionEnable = 1` |
| 67 | + |
| 68 | +#### Scenario: Update delete_protection_enable test |
| 69 | +- **WHEN** a test simulates updating `delete_protection_enable` from `0` to `1` |
| 70 | +- **THEN** the mocked `ModifyInstanceAttributes` SHALL be invoked with `DeleteProtectionEnable = 1` |
| 71 | +- **AND** the test SHALL assert the API was called |
| 72 | + |
| 73 | +### Requirement: CKafka Instance Resource Documentation |
| 74 | +The system SHALL provide a markdown documentation file `resource_tc_ckafka_instance.md` with a one-line description mentioning CKafka, example usage, and import section. The example usage SHALL demonstrate the `delete_protection_enable` field. |
| 75 | + |
| 76 | +#### Scenario: Documentation exists |
| 77 | +- **WHEN** the resource is created |
| 78 | +- **THEN** a `.md` file SHALL exist with a one-line description mentioning CKafka, example usage including `delete_protection_enable`, and import section showing the instance ID format |
0 commit comments