|
| 1 | +## ADDED Requirements |
| 2 | + |
| 3 | +### Requirement: Resource shall manage DLC user-policy binding lifecycle |
| 4 | +The Terraform provider SHALL provide a resource `tencentcloud_dlc_attach_user_policyr_attachment` of kind `RESOURCE_KIND_ATTACHMENT` that manages the binding between a DLC user and a set of authorization policies. The resource SHALL support Create (bind), Read (query), and Delete (unbind). The resource SHALL NOT support in-place Update; any change to a top-level argument SHALL trigger recreation. |
| 5 | + |
| 6 | +#### Scenario: Bind policies to a user on create |
| 7 | +- **WHEN** a user applies a configuration defining `tencentcloud_dlc_attach_user_policyr_attachment` with `user_id`, `policy_set`, and `account_type` |
| 8 | +- **THEN** the provider SHALL call the DLC `AttachUserPolicy` API with the given `UserId`, `PolicySet`, and `AccountType` |
| 9 | +- **AND** the provider SHALL set the resource ID to the composite of `user_id` and `account_type` joined by `tccommon.FILED_SP` |
| 10 | +- **AND** the provider SHALL set `policy_set` in state from the API response |
| 11 | + |
| 12 | +#### Scenario: Read reflects currently bound policies |
| 13 | +- **WHEN** the provider reads an existing `tencentcloud_dlc_attach_user_policyr_attachment` resource |
| 14 | +- **THEN** the provider SHALL call the DLC `DescribeUserInfo` API with the `UserId` and `AccountType` derived from the composite ID |
| 15 | +- **AND** the provider SHALL verify the bound policies are still present |
| 16 | +- **AND** if the binding is no longer present, the provider SHALL emit a `[CRUD]` log preserving the id and then set `d.SetId("")` |
| 17 | + |
| 18 | +#### Scenario: Unbind policies on delete |
| 19 | +- **WHEN** a user destroys a `tencentcloud_dlc_attach_user_policyr_attachment` resource |
| 20 | +- **THEN** the provider SHALL call the DLC `DetachUserPolicy` API with the `UserId`, `AccountType`, and `PolicySet` derived from state |
| 21 | +- **AND** the resource SHALL be removed from state |
| 22 | + |
| 23 | +#### Scenario: Any change recreates the resource |
| 24 | +- **WHEN** a user changes any top-level argument of an existing `tencentcloud_dlc_attach_user_policyr_attachment` resource |
| 25 | +- **THEN** the provider SHALL reject the in-place update (the update method returns an error for immutable args) and Terraform SHALL recreate the resource |
| 26 | + |
| 27 | +### Requirement: Resource SHALL use a composite identifier |
| 28 | +Because the DLC `AttachUserPolicy` API returns no single resource identifier, the resource SHALL use a composite ID composed of `user_id` and `account_type` joined by `tccommon.FILED_SP`. The Read, Update, and Delete operations SHALL split the composite ID to recover `user_id` and `account_type` for use as API request parameters. |
| 29 | + |
| 30 | +#### Scenario: Composite ID is split for API calls |
| 31 | +- **WHEN** the provider performs Read, Update, or Delete on `tencentcloud_dlc_attach_user_policyr_attachment` |
| 32 | +- **THEN** the provider SHALL split `d.Id()` by `tccommon.FILED_SP` into `user_id` and `account_type` |
| 33 | +- **AND** the provider SHALL use these values as the `UserId` and `AccountType` request parameters |
| 34 | + |
| 35 | +### Requirement: Resource schema SHALL expose binding parameters |
| 36 | +The resource schema SHALL expose `user_id` (Required, ForceNew), `policy_set` (Required), and `account_type` (Optional, ForceNew). The `policy_set` SHALL be a list of policy objects whose input-eligible fields (`database`, `catalog`, `table`, `operation`, `policy_type`, `function`, `view`, `column`, `data_engine`, `re_auth`, `engine_generation`, `model`, `policy_id`) can be set by the user. |
| 37 | + |
| 38 | +#### Scenario: Required arguments are enforced |
| 39 | +- **WHEN** a user omits `user_id` or `policy_set` in the configuration |
| 40 | +- **THEN** Terraform SHALL report a validation error before any API call is made |
| 41 | + |
| 42 | +#### Scenario: account_type is optional |
| 43 | +- **WHEN** a user does not specify `account_type` |
| 44 | +- **THEN** the provider SHALL not set `AccountType` in the API request, allowing the cloud API to apply its default |
| 45 | + |
| 46 | +### Requirement: Cloud API calls SHALL use retry and proper error handling |
| 47 | +Create, Read, and Delete SHALL wrap their cloud API calls in `resource.Retry` using `tccommon.WriteRetryTimeout` (for Create/Delete) and `tccommon.ReadRetryTimeout` (for Read). Errors from the cloud API SHALL be wrapped with `tccommon.RetryError`. State mutations (setting the ID and fields) SHALL occur outside the retry block, after successful retry completion. |
| 48 | + |
| 49 | +#### Scenario: Transient API failure is retried |
| 50 | +- **WHEN** a DLC API call fails with a retryable error during Create, Read, or Delete |
| 51 | +- **THEN** the provider SHALL retry the call within the configured timeout and wrap the error with `tccommon.RetryError` |
| 52 | + |
| 53 | +#### Scenario: Create validates non-empty response |
| 54 | +- **WHEN** the `AttachUserPolicy` API returns a nil response |
| 55 | +- **THEN** the provider SHALL return a `NonRetryableError` rather than writing an empty id to state |
| 56 | + |
| 57 | +### Requirement: Resource SHALL be registered in the provider |
| 58 | +The provider SHALL register `tencentcloud_dlc_attach_user_policyr_attachment` in `tencentcloud/provider.go` and document it in `tencentcloud/provider.md`. A documentation file `resource_tc_dlc_attach_user_policyr_attachment.md` SHALL exist under `tencentcloud/services/dlc/`. |
| 59 | + |
| 60 | +#### Scenario: Resource is usable in a Terraform configuration |
| 61 | +- **WHEN** a user references `tencentcloud_dlc_attach_user_policyr_attachment` in a `.tf` file |
| 62 | +- **THEN** the provider SHALL recognize the resource type and execute its CRUD handlers |
| 63 | + |
| 64 | +### Requirement: Unit tests SHALL use gomonkey mocks |
| 65 | +The resource test file `resource_tc_dlc_attach_user_policyr_attachment_test.go` SHALL use gomonkey to mock the DLC cloud API client methods and test the business logic of Create/Read/Delete without relying on the Terraform acceptance test suite. The tests SHALL be runnable with `go test -gcflags=all=-l`. |
| 66 | + |
| 67 | +#### Scenario: Create logic is tested with mocked API |
| 68 | +- **WHEN** the unit test invokes the Create handler with a mocked `AttachUserPolicy` that returns a valid response |
| 69 | +- **THEN** the test SHALL assert the composite ID is set and `policy_set` state is populated |
| 70 | + |
| 71 | +#### Scenario: Delete logic is tested with mocked API |
| 72 | +- **WHEN** the unit test invokes the Delete handler with a mocked `DetachUserPolicy` |
| 73 | +- **THEN** the test SHALL assert `DetachUserPolicy` is called with the expected parameters |
0 commit comments