|
| 1 | +## ADDED Requirements |
| 2 | + |
| 3 | +### Requirement: Create audit log file |
| 4 | +The system SHALL provide a Terraform resource `tencentcloud_postgres_audit_log_file` that creates a PostgreSQL audit log file by calling the `CreateAuditLogFile` API with the specified instance ID, time range, product name, and optional filter conditions. |
| 5 | + |
| 6 | +#### Scenario: Successful creation with all parameters |
| 7 | +- **WHEN** user applies a Terraform configuration with `tencentcloud_postgres_audit_log_file` specifying `instance_id`, `start_time`, `end_time`, `product`, and `filter` block |
| 8 | +- **THEN** the system SHALL call `CreateAuditLogFile` API with all provided parameters, poll `DescribeAuditLogFiles` until the file status becomes `success`, and set the resource ID as `instance_id#file_name` |
| 9 | + |
| 10 | +#### Scenario: Successful creation without filter |
| 11 | +- **WHEN** user applies a Terraform configuration with `tencentcloud_postgres_audit_log_file` specifying only `instance_id`, `start_time`, `end_time`, and `product` (no filter) |
| 12 | +- **THEN** the system SHALL call `CreateAuditLogFile` API without the Filter parameter and poll until completion |
| 13 | + |
| 14 | +#### Scenario: Creation fails asynchronously |
| 15 | +- **WHEN** the audit log file creation results in a `failed` status during polling |
| 16 | +- **THEN** the system SHALL return an error containing the ErrMsg from the API response |
| 17 | + |
| 18 | +### Requirement: Read audit log file |
| 19 | +The system SHALL support reading the audit log file metadata by calling `DescribeAuditLogFiles` with the `InstanceId`, `Product`, and `FileName` parameters extracted from the resource ID. |
| 20 | + |
| 21 | +#### Scenario: File exists and is readable |
| 22 | +- **WHEN** Terraform performs a refresh on an existing `tencentcloud_postgres_audit_log_file` resource |
| 23 | +- **THEN** the system SHALL call `DescribeAuditLogFiles` with the FileName filter and populate computed attributes (`file_name`, `status`, `file_size`, `create_time`, `download_url`, `err_msg`, `progress`, `finish_time`) from the response Items |
| 24 | + |
| 25 | +#### Scenario: File no longer exists |
| 26 | +- **WHEN** Terraform performs a refresh and `DescribeAuditLogFiles` returns no matching items |
| 27 | +- **THEN** the system SHALL remove the resource from state (call `d.SetId("")`) |
| 28 | + |
| 29 | +### Requirement: Delete audit log file |
| 30 | +The system SHALL support deleting the audit log file by calling `DeleteAuditLogFile` with `InstanceId`, `Product`, and `FileName` extracted from the resource ID. |
| 31 | + |
| 32 | +#### Scenario: Successful deletion |
| 33 | +- **WHEN** user destroys a `tencentcloud_postgres_audit_log_file` resource |
| 34 | +- **THEN** the system SHALL call `DeleteAuditLogFile` API with the correct parameters and remove the resource from state |
| 35 | + |
| 36 | +### Requirement: Resource schema definition |
| 37 | +The system SHALL define the resource schema with the following fields: |
| 38 | + |
| 39 | +#### Scenario: Required input fields |
| 40 | +- **WHEN** the resource schema is defined |
| 41 | +- **THEN** the following fields SHALL be Required and ForceNew: `instance_id` (String), `start_time` (String), `end_time` (String), `product` (String) |
| 42 | + |
| 43 | +#### Scenario: Optional input fields |
| 44 | +- **WHEN** the resource schema is defined |
| 45 | +- **THEN** the `filter` field SHALL be Optional and ForceNew, containing a nested block with fields: `affect_rows` (Int, Optional), `db_name` (List of String, Optional), `exec_time` (Int, Optional), `host` (List of String, Optional), `sql` (String, Optional), `user` (List of String, Optional), `sql_type` (List of String, Optional) |
| 46 | + |
| 47 | +#### Scenario: Computed output fields |
| 48 | +- **WHEN** the resource schema is defined |
| 49 | +- **THEN** the following fields SHALL be Computed: `file_name` (String), `status` (String), `file_size` (Int), `create_time` (String), `download_url` (String), `err_msg` (String), `progress` (Int), `finish_time` (String) |
| 50 | + |
| 51 | +### Requirement: Import support |
| 52 | +The system SHALL support importing existing audit log files using the composite ID format `instance_id#file_name`. |
| 53 | + |
| 54 | +#### Scenario: Import by composite ID |
| 55 | +- **WHEN** user runs `terraform import tencentcloud_postgres_audit_log_file.example instance_id#file_name` |
| 56 | +- **THEN** the system SHALL parse the composite ID, call `DescribeAuditLogFiles` to read the file metadata, and populate the state |
| 57 | + |
| 58 | +### Requirement: Retry and error handling |
| 59 | +The system SHALL wrap all API calls with retry logic using `tccommon.ReadRetryTimeout` and `tccommon.RetryError()`. |
| 60 | + |
| 61 | +#### Scenario: Transient API failure during creation |
| 62 | +- **WHEN** `CreateAuditLogFile` API returns a transient error |
| 63 | +- **THEN** the system SHALL retry the call within the configured timeout |
| 64 | + |
| 65 | +#### Scenario: Transient API failure during read |
| 66 | +- **WHEN** `DescribeAuditLogFiles` API returns a transient error |
| 67 | +- **THEN** the system SHALL retry the call within the configured timeout |
| 68 | + |
| 69 | +#### Scenario: Transient API failure during deletion |
| 70 | +- **WHEN** `DeleteAuditLogFile` API returns a transient error |
| 71 | +- **THEN** the system SHALL retry the call within the configured timeout |
0 commit comments