Skip to content

Commit c3fc791

Browse files
committed
feat(teo): add security_policy parameter to tencentcloud_teo_security_policy_config resource
1 parent e3683c9 commit c3fc791

13 files changed

Lines changed: 1388 additions & 325 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ require (
9393
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.533
9494
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.3.46
9595
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578
96-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.3.90
96+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.3.108
9797
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.3.86
9898
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.1.0
9999
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.857

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.3.46 h1:hnBTV4y
10731073
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.3.46/go.mod h1:brB63yRDKDgCzEBFU5G3OBV+wQ+lpnOnedxwdnLgjjk=
10741074
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578 h1:vBpQhUroO+FAslUmsDWGi8nvczsqZBWVgQwlnyT0Aj8=
10751075
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578/go.mod h1:UlojGQh/9wb7/uXPNi7PvMral1CNAskVDNgqJEV83l0=
1076-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.3.90 h1:UAefUxiVLj639m5jplPyTyOkF5vT8W0d8TrWZ7cepj4=
1077-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.3.90/go.mod h1:YV/JlZueAHyf9eyLmowdbeX90MR5jJmy0Dn6gZwPT2M=
1076+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.3.108 h1:cAw2o4gMuAUZnjdo+WDZmUTHgH6FdysXeUDI1YcBjgI=
1077+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.3.108/go.mod h1:/+JtDwgVSkaDGMU42zTWtidw/p56hl2N46zkWJLAr9U=
10781078
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/thpc v1.0.998 h1:f4/n0dVKQTD06xJ84B5asHViNJHrZmGojdAWEPIsITM=
10791079
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/thpc v1.0.998/go.mod h1:fyi/HUwCwVe2NCCCjz8k/C5GwPu3QazCZO+OBJ3MhLk=
10801080
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.3.86 h1:vTpLGPpzAbZHOv0F6hmy8C9IBwJIUfhTrXH0vi7eiGA=
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-06-04
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## Context
2+
3+
The `tencentcloud_teo_security_policy_config` resource manages TEO (TencentCloud EdgeOne) security policy configurations. It uses:
4+
- `ModifySecurityPolicy` API for create/update operations
5+
- `DescribeSecurityPolicy` API for read operations
6+
7+
The resource already exists at `tencentcloud/services/teo/resource_tc_teo_security_policy_config.go` with the following top-level schema fields:
8+
- `zone_id` (Required, ForceNew) - Zone ID
9+
- `entity` (Optional, ForceNew) - Security policy type (ZoneDefaultPolicy/Template/Host)
10+
- `host` (Optional, ForceNew) - Domain name for Host entity type
11+
- `template_id` (Optional, ForceNew) - Template ID for Template entity type
12+
- `security_policy` (Optional, TypeList, MaxItems: 1) - Security policy configuration using expression grammar
13+
- `security_config` (Optional, Computed, TypeList, MaxItems: 1) - Classic web protection settings
14+
15+
The `SecurityPolicy` parameter in the `ModifySecurityPolicy` API maps to the `security_policy` schema field and contains sub-structures for:
16+
- `CustomRules` - Custom rule configuration
17+
- `ManagedRules` - Managed rules configuration
18+
- `HttpDDoSProtection` - HTTP DDoS protection configuration
19+
- `RateLimitingRules` - Rate limiting rules configuration
20+
- `ExceptionRules` - Exception rules configuration
21+
- `BotManagement` - Bot management configuration
22+
- `BotManagementLite` - Basic bot management configuration
23+
- `DefaultDenySecurityActionParameters` - Default deny action parameters
24+
25+
The `DescribeSecurityPolicy` API returns `response.Response.SecurityPolicy` which is read back into the `security_policy` terraform attribute.
26+
27+
## Goals / Non-Goals
28+
29+
**Goals:**
30+
- Ensure the `security_policy` parameter is properly supported in the `ModifySecurityPolicy` API call (create/update)
31+
- Ensure the `DescribeSecurityPolicy` API properly reads back the `SecurityPolicy` response into the `security_policy` attribute
32+
- Ensure proper input parameters (`ZoneId`, `Entity`, `Host`, `TemplateId`) are passed to `DescribeSecurityPolicy`
33+
- Maintain backward compatibility with existing terraform configurations
34+
35+
**Non-Goals:**
36+
- Modifying the `security_config` (classic) parameter handling
37+
- Adding new sub-fields within the `SecurityPolicy` structure beyond what the vendor SDK supports
38+
- Changing the resource ID format or import behavior
39+
40+
## Decisions
41+
42+
1. **Parameter mapping**: The `request.SecurityPolicy` field in `ModifySecurityPolicy` maps to the terraform schema field `security_policy`. This is a complex nested structure (TypeList with MaxItems: 1) containing all security policy sub-configurations.
43+
44+
2. **Read operation**: The `DescribeSecurityPolicy` API requires `ZoneId`, `Entity`, `Host`, and `TemplateId` as input parameters (extracted from the resource ID) and returns `SecurityPolicy` in the response which is flattened into the `security_policy` attribute.
45+
46+
3. **Resource lifecycle**: Since there is no `CreateSecurityPolicy` or `DeleteSecurityPolicy` API, the resource uses `ModifySecurityPolicy` for both create and update operations. Delete is a no-op (the security policy always exists for a zone).
47+
48+
4. **Retry handling**: API calls use `tccommon.ReadRetryTimeout` with `resource.RetryContext` for retry logic, wrapping errors with `tccommon.RetryError()`.
49+
50+
## Risks / Trade-offs
51+
52+
- [Risk] The `SecurityPolicy` structure is complex with deeply nested fields → Mitigation: Follow existing patterns in the resource code for flattening/expanding nested structures.
53+
- [Risk] Backward compatibility with existing state files → Mitigation: Only add Optional fields, never modify existing Required fields or change field types.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Why
2+
3+
The existing `tencentcloud_teo_security_policy_config` resource needs to support the `SecurityPolicy` parameter in the `ModifySecurityPolicy` API and properly read it back via the `DescribeSecurityPolicy` API. This enables users to configure security policies (custom rules, managed rules, HTTP DDoS protection, rate limiting rules, exception rules, bot management, bot management lite, and default deny security action parameters) using the expression-based `SecurityPolicy` structure for TEO (TencentCloud EdgeOne) security policy management.
4+
5+
## What Changes
6+
7+
- Add the `security_policy` parameter to the `tencentcloud_teo_security_policy_config` resource that maps to `request.SecurityPolicy` in the `ModifySecurityPolicy` API for create/update operations.
8+
- Ensure the `DescribeSecurityPolicy` API is called with proper input parameters (`ZoneId`, `Entity`, `Host`, `TemplateId`) and the `response.Response.SecurityPolicy` output is read back into the `security_policy` terraform attribute.
9+
10+
## Capabilities
11+
12+
### New Capabilities
13+
- `teo-security-policy-param`: Add the `SecurityPolicy` parameter support to the `tencentcloud_teo_security_policy_config` resource, enabling configuration of security policies via the `ModifySecurityPolicy` API and reading them back via `DescribeSecurityPolicy` API.
14+
15+
### Modified Capabilities
16+
<!-- No existing capabilities are being modified -->
17+
18+
## Impact
19+
20+
- **Code**: `tencentcloud/services/teo/resource_tc_teo_security_policy_config.go` - Add/verify `security_policy` schema field and CRUD logic
21+
- **Code**: `tencentcloud/services/teo/resource_tc_teo_security_policy_config_test.go` - Add unit tests
22+
- **Code**: `tencentcloud/services/teo/resource_tc_teo_security_policy_config.md` - Update documentation with example usage
23+
- **API**: Uses `ModifySecurityPolicy` and `DescribeSecurityPolicy` from `github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901`
24+
- **Dependencies**: No new dependencies required (vendor SDK already includes the TEO v20220901 package)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## ADDED Requirements
2+
3+
### Requirement: SecurityPolicy parameter support in ModifySecurityPolicy API
4+
5+
The `tencentcloud_teo_security_policy_config` resource SHALL support the `security_policy` parameter that maps to `request.SecurityPolicy` in the `ModifySecurityPolicy` API. When the user specifies the `security_policy` block in their terraform configuration, the resource MUST construct the `SecurityPolicy` struct and pass it to the `ModifySecurityPolicy` API request during create and update operations.
6+
7+
#### Scenario: User configures security_policy with custom rules
8+
- **WHEN** user specifies a `security_policy` block with `custom_rules` configuration in their terraform resource
9+
- **THEN** the resource MUST construct the `SecurityPolicy.CustomRules` struct and include it in the `ModifySecurityPolicy` API request
10+
11+
#### Scenario: User configures security_policy with managed rules
12+
- **WHEN** user specifies a `security_policy` block with `managed_rules` configuration
13+
- **THEN** the resource MUST construct the `SecurityPolicy.ManagedRules` struct and include it in the `ModifySecurityPolicy` API request
14+
15+
#### Scenario: User does not specify security_policy
16+
- **WHEN** user does not include the `security_policy` block in their terraform configuration
17+
- **THEN** the resource MUST NOT set `request.SecurityPolicy` on the `ModifySecurityPolicy` API request
18+
19+
### Requirement: DescribeSecurityPolicy reads SecurityPolicy response
20+
21+
The resource SHALL call the `DescribeSecurityPolicy` API with proper input parameters (`ZoneId`, `Entity`, `Host`, `TemplateId`) during read operations and MUST flatten the `response.Response.SecurityPolicy` output into the `security_policy` terraform attribute.
22+
23+
#### Scenario: Read operation retrieves security policy
24+
- **WHEN** terraform performs a read/refresh operation on the `tencentcloud_teo_security_policy_config` resource
25+
- **THEN** the resource MUST call `DescribeSecurityPolicy` with `ZoneId`, `Entity`, `Host`, and `TemplateId` extracted from the resource ID, and set the returned `SecurityPolicy` data into the `security_policy` attribute
26+
27+
#### Scenario: DescribeSecurityPolicy returns nil SecurityPolicy
28+
- **WHEN** the `DescribeSecurityPolicy` API returns a nil `SecurityPolicy` in the response
29+
- **THEN** the resource MUST NOT attempt to set the `security_policy` attribute and SHALL treat the resource as deleted (remove from state)
30+
31+
### Requirement: Input parameters for DescribeSecurityPolicy
32+
33+
The resource SHALL pass the following input parameters to the `DescribeSecurityPolicy` API:
34+
- `ZoneId` from the `zone_id` schema field
35+
- `Entity` from the `entity` schema field
36+
- `Host` from the `host` schema field (when entity is "Host")
37+
- `TemplateId` from the `template_id` schema field (when entity is "Template")
38+
39+
#### Scenario: Zone default policy query
40+
- **WHEN** the resource ID contains entity "ZoneDefaultPolicy"
41+
- **THEN** the resource MUST call `DescribeSecurityPolicy` with `ZoneId` and `Entity` set to "ZoneDefaultPolicy"
42+
43+
#### Scenario: Host-level policy query
44+
- **WHEN** the resource ID contains entity "Host" with a host value
45+
- **THEN** the resource MUST call `DescribeSecurityPolicy` with `ZoneId`, `Entity` set to "Host", and `Host` set to the domain name
46+
47+
#### Scenario: Template-level policy query
48+
- **WHEN** the resource ID contains entity "Template" with a template_id value
49+
- **THEN** the resource MUST call `DescribeSecurityPolicy` with `ZoneId`, `Entity` set to "Template", and `TemplateId` set to the template ID
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## 1. Resource Implementation
2+
3+
- [x] 1.1 Verify and ensure the `security_policy` schema field in `tencentcloud/services/teo/resource_tc_teo_security_policy_config.go` properly maps all sub-fields of the `SecurityPolicy` struct from the vendor SDK (`github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901`)
4+
- [x] 1.2 Verify the Update function correctly constructs `request.SecurityPolicy` from the `security_policy` schema field and passes it to `ModifySecurityPolicy` API
5+
- [x] 1.3 Verify the Read function correctly calls `DescribeSecurityPolicy` with `ZoneId`, `Entity`, `Host`, `TemplateId` input parameters and flattens `response.Response.SecurityPolicy` into the `security_policy` attribute
6+
7+
## 2. Unit Tests
8+
9+
- [x] 2.1 Add unit tests in `tencentcloud/services/teo/resource_tc_teo_security_policy_config_test.go` using gomonkey to mock the cloud API calls, verifying the `security_policy` parameter is correctly handled in create/update/read operations
10+
11+
## 3. Documentation
12+
13+
- [x] 3.1 Update `tencentcloud/services/teo/resource_tc_teo_security_policy_config.md` with example usage demonstrating the `security_policy` parameter configuration
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## ADDED Requirements
2+
3+
### Requirement: SecurityPolicy parameter support in ModifySecurityPolicy API
4+
5+
The `tencentcloud_teo_security_policy_config` resource SHALL support the `security_policy` parameter that maps to `request.SecurityPolicy` in the `ModifySecurityPolicy` API. When the user specifies the `security_policy` block in their terraform configuration, the resource MUST construct the `SecurityPolicy` struct and pass it to the `ModifySecurityPolicy` API request during create and update operations.
6+
7+
#### Scenario: User configures security_policy with custom rules
8+
- **WHEN** user specifies a `security_policy` block with `custom_rules` configuration in their terraform resource
9+
- **THEN** the resource MUST construct the `SecurityPolicy.CustomRules` struct and include it in the `ModifySecurityPolicy` API request
10+
11+
#### Scenario: User configures security_policy with managed rules
12+
- **WHEN** user specifies a `security_policy` block with `managed_rules` configuration
13+
- **THEN** the resource MUST construct the `SecurityPolicy.ManagedRules` struct and include it in the `ModifySecurityPolicy` API request
14+
15+
#### Scenario: User does not specify security_policy
16+
- **WHEN** user does not include the `security_policy` block in their terraform configuration
17+
- **THEN** the resource MUST NOT set `request.SecurityPolicy` on the `ModifySecurityPolicy` API request
18+
19+
### Requirement: DescribeSecurityPolicy reads SecurityPolicy response
20+
21+
The resource SHALL call the `DescribeSecurityPolicy` API with proper input parameters (`ZoneId`, `Entity`, `Host`, `TemplateId`) during read operations and MUST flatten the `response.Response.SecurityPolicy` output into the `security_policy` terraform attribute.
22+
23+
#### Scenario: Read operation retrieves security policy
24+
- **WHEN** terraform performs a read/refresh operation on the `tencentcloud_teo_security_policy_config` resource
25+
- **THEN** the resource MUST call `DescribeSecurityPolicy` with `ZoneId`, `Entity`, `Host`, and `TemplateId` extracted from the resource ID, and set the returned `SecurityPolicy` data into the `security_policy` attribute
26+
27+
#### Scenario: DescribeSecurityPolicy returns nil SecurityPolicy
28+
- **WHEN** the `DescribeSecurityPolicy` API returns a nil `SecurityPolicy` in the response
29+
- **THEN** the resource MUST NOT attempt to set the `security_policy` attribute and SHALL treat the resource as deleted (remove from state)
30+
31+
### Requirement: Input parameters for DescribeSecurityPolicy
32+
33+
The resource SHALL pass the following input parameters to the `DescribeSecurityPolicy` API:
34+
- `ZoneId` from the `zone_id` schema field
35+
- `Entity` from the `entity` schema field
36+
- `Host` from the `host` schema field (when entity is "Host")
37+
- `TemplateId` from the `template_id` schema field (when entity is "Template")
38+
39+
#### Scenario: Zone default policy query
40+
- **WHEN** the resource ID contains entity "ZoneDefaultPolicy"
41+
- **THEN** the resource MUST call `DescribeSecurityPolicy` with `ZoneId` and `Entity` set to "ZoneDefaultPolicy"
42+
43+
#### Scenario: Host-level policy query
44+
- **WHEN** the resource ID contains entity "Host" with a host value
45+
- **THEN** the resource MUST call `DescribeSecurityPolicy` with `ZoneId`, `Entity` set to "Host", and `Host` set to the domain name
46+
47+
#### Scenario: Template-level policy query
48+
- **WHEN** the resource ID contains entity "Template" with a template_id value
49+
- **THEN** the resource MUST call `DescribeSecurityPolicy` with `ZoneId`, `Entity` set to "Template", and `TemplateId` set to the template ID

0 commit comments

Comments
 (0)