Skip to content

Commit 2a9fc36

Browse files
committed
feat(ga2): add tencentcloud_ga2_global_accelerator resource
1 parent 228133f commit 2a9fc36

14 files changed

Lines changed: 1098 additions & 1 deletion

File tree

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.89/go.mod h
958958
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.90/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
959959
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.94/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
960960
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.95/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
961+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.101/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
961962
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.102 h1:3n7BpLOPnE9Rv3Y9Jxgl/XaQX3GzktO+dEaAbtVbjSk=
962963
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.102/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
963964
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/config v1.3.80 h1:chnsNBeJn3MieFLki4hpbzoml5NiTvLVzOTqYRVxQho=
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-05-27
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
## Context
2+
3+
当前 Terraform Provider 已有 GA2 服务的基础设施:
4+
- `tencentcloud/services/ga2/service_tencentcloud_ga2.go` 提供了 `Ga2Service``WaitForGa2TaskFinish` 等公共方法
5+
- `tencentcloud/services/ga2/resource_tc_ga2_endpoint_group.go` 是同产品下已有的资源实现,可作为模式参考
6+
- vendor 中已包含 `github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ga2/v20250115` SDK
7+
8+
所有 GA2 写操作(Create/Modify/Delete)均为异步接口,返回 TaskId,需通过 `DescribeTaskResult` 轮询任务状态直到 SUCCESS。已有的 `WaitForGa2TaskFinish` 方法可直接复用。
9+
10+
## Goals / Non-Goals
11+
12+
**Goals:**
13+
- 实现 `tencentcloud_ga2_global_accelerator` 资源的完整 CRUD
14+
- 复用已有的 `Ga2Service``WaitForGa2TaskFinish` 异步等待机制
15+
- 支持 Import 功能(通过 global_accelerator_id 导入)
16+
- 在 service 层新增 `DescribeGa2GlobalAcceleratorById` 方法供 Read 使用
17+
- 使用 gomonkey mock 方式编写单元测试
18+
19+
**Non-Goals:**
20+
- 不实现 tags 的独立更新(ModifyGlobalAccelerator 不支持 tags 参数)
21+
- 不实现 instance_charge_type 的变更(仅创建时指定)
22+
- 不实现数据源(本次仅新增 RESOURCE_KIND_GENERAL 资源)
23+
24+
## Decisions
25+
26+
### 1. 资源 ID 使用 GlobalAcceleratorId
27+
28+
**决策**: 使用 `CreateGlobalAccelerator` 返回的 `GlobalAcceleratorId` 作为 Terraform 资源 ID(单一 ID,无需复合 ID)。
29+
30+
**理由**: 该 ID 是全球加速实例的唯一标识,Modify 和 Delete 接口均只需此 ID。
31+
32+
### 2. 异步操作使用已有的 WaitForGa2TaskFinish
33+
34+
**决策**: Create/Modify/Delete 操作完成后,调用 `Ga2Service.WaitForGa2TaskFinish` 等待任务完成。
35+
36+
**理由**: 该方法已在 endpoint_group 资源中验证可用,使用 `DescribeTaskResult` 接口轮询,避免重复实现。
37+
38+
### 3. instance_charge_type 和 tags 设为 ForceNew
39+
40+
**决策**: `instance_charge_type``tags` 字段设为 ForceNew,因为 ModifyGlobalAccelerator 接口不支持修改这两个字段。
41+
42+
**理由**: 云 API 的 Modify 接口仅支持 Name、Description、CrossBorderType、CrossBorderPromiseFlag 四个字段的修改。
43+
44+
### 4. Read 方法通过 DescribeGlobalAccelerators + Filter 实现
45+
46+
**决策**: 在 service 层新增 `DescribeGa2GlobalAcceleratorById` 方法,使用 `global-accelerator-id` Filter 查询单个实例。
47+
48+
**理由**: DescribeGlobalAccelerators 接口支持通过 Filters 按 ID 过滤,与 endpoint_group 的模式一致。
49+
50+
### 5. Schema 中声明 Timeouts
51+
52+
**决策**: 为 Create/Update/Delete 声明 20 分钟超时,与 endpoint_group 资源保持一致。
53+
54+
**理由**: 异步操作需要超时控制,20 分钟是同产品其他资源的标准超时时间。
55+
56+
## Risks / Trade-offs
57+
58+
- [Tags 不可更新] → 设为 ForceNew,用户修改 tags 会触发资源重建。这是 API 限制,无法规避。
59+
- [instance_charge_type 不可更新] → 设为 ForceNew,与 API 能力对齐。
60+
- [异步操作可能超时] → 使用 schema Timeouts 机制,用户可自定义超时时间。
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Why
2+
3+
TencentCloud Global Accelerator (GA2) 产品需要通过 Terraform 管理全球加速实例的生命周期(创建、查询、修改、删除),当前 provider 中尚未提供该资源,用户无法通过 IaC 方式管理 GA2 全球加速实例。
4+
5+
## What Changes
6+
7+
- 新增 Terraform 资源 `tencentcloud_ga2_global_accelerator`,支持全球加速实例的完整 CRUD 生命周期管理
8+
- 支持创建时指定名称、计费模式、描述、跨境类型、跨境承诺标志和标签
9+
- 支持修改名称、描述、跨境类型和跨境承诺标志
10+
- 支持删除全球加速实例
11+
- 所有写操作(Create/Modify/Delete)为异步接口,需轮询实例状态直到操作完成
12+
- 在 provider.go 和 provider.md 中注册新资源
13+
14+
## Capabilities
15+
16+
### New Capabilities
17+
18+
- `ga2-global-accelerator-resource`: 全球加速实例的 CRUD 资源管理,包括创建、读取、更新、删除操作,以及异步操作的状态轮询
19+
20+
### Modified Capabilities
21+
22+
(无)
23+
24+
## Impact
25+
26+
- 新增文件: `tencentcloud/services/ga2/resource_tc_ga2_global_accelerator.go`
27+
- 新增文件: `tencentcloud/services/ga2/resource_tc_ga2_global_accelerator_test.go`
28+
- 新增文件: `tencentcloud/services/ga2/resource_tc_ga2_global_accelerator.md`
29+
- 修改文件: `tencentcloud/provider.go`(注册资源)
30+
- 修改文件: `tencentcloud/provider.md`(添加资源文档引用)
31+
- 可能修改: `tencentcloud/services/ga2/service_tencentcloud_ga2.go`(添加服务层方法)
32+
- 依赖: `github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ga2/v20250115`(已在 vendor 中)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## ADDED Requirements
2+
3+
### Requirement: Create global accelerator instance
4+
5+
The system SHALL provide a Terraform resource `tencentcloud_ga2_global_accelerator` that creates a GA2 global accelerator instance by calling the `CreateGlobalAccelerator` API with the following parameters:
6+
- `name` (Required, string): Instance name, max 60 bytes
7+
- `instance_charge_type` (Optional, string, ForceNew): Billing mode, valid values: `PREPAID`, `POSTPAID`. Default: `POSTPAID`
8+
- `description` (Optional, string): Description, max 100 bytes
9+
- `cross_border_type` (Optional, string): Cross-border type, valid values: `HighQuality`, `Unicom`
10+
- `cross_border_promise_flag` (Optional, bool): Cross-border service promise flag
11+
- `tags` (Optional, map of string, ForceNew): Tag information
12+
13+
After successful creation, the system SHALL set the resource ID to the returned `GlobalAcceleratorId` and wait for the async task to complete by polling `DescribeTaskResult` until status is SUCCESS.
14+
15+
#### Scenario: Successful creation with required parameters only
16+
17+
- **WHEN** user provides a valid `name` in the Terraform configuration
18+
- **THEN** the system calls `CreateGlobalAccelerator` API, sets the resource ID to the returned `GlobalAcceleratorId`, waits for the task to complete, and reads back the resource state
19+
20+
#### Scenario: Successful creation with all parameters
21+
22+
- **WHEN** user provides `name`, `instance_charge_type`, `description`, `cross_border_type`, `cross_border_promise_flag`, and `tags`
23+
- **THEN** the system calls `CreateGlobalAccelerator` API with all provided parameters, sets the resource ID, waits for the task to complete, and reads back the resource state
24+
25+
#### Scenario: Creation fails with nil response
26+
27+
- **WHEN** the `CreateGlobalAccelerator` API returns a nil response or nil `GlobalAcceleratorId`
28+
- **THEN** the system returns a NonRetryableError
29+
30+
### Requirement: Read global accelerator instance
31+
32+
The system SHALL read the global accelerator instance state by calling `DescribeGlobalAccelerators` API with a `global-accelerator-id` filter. The system SHALL set the following computed attributes from the response:
33+
- `name` (string)
34+
- `description` (string)
35+
- `instance_charge_type` (string)
36+
- `cross_border_type` (string)
37+
- `create_time` (Computed, string)
38+
- `state` (Computed, string)
39+
- `status` (Computed, string)
40+
- `ddos_id` (Computed, string)
41+
- `cname` (Computed, string)
42+
43+
#### Scenario: Successful read
44+
45+
- **WHEN** the resource exists and `DescribeGlobalAccelerators` returns a matching instance
46+
- **THEN** the system sets all computed and configured attributes from the `GlobalAcceleratorSet` response
47+
48+
#### Scenario: Resource not found
49+
50+
- **WHEN** `DescribeGlobalAccelerators` returns an empty `GlobalAcceleratorSet` for the given ID
51+
- **THEN** the system removes the resource from state (calls `d.SetId("")`)
52+
53+
### Requirement: Update global accelerator instance
54+
55+
The system SHALL update the global accelerator instance by calling `ModifyGlobalAccelerator` API when any of the following fields change: `name`, `description`, `cross_border_type`, `cross_border_promise_flag`. After the API call, the system SHALL wait for the async task to complete.
56+
57+
The fields `instance_charge_type` and `tags` are ForceNew and SHALL NOT be included in the update request.
58+
59+
#### Scenario: Update name and description
60+
61+
- **WHEN** user changes `name` or `description` in the Terraform configuration
62+
- **THEN** the system calls `ModifyGlobalAccelerator` with the new values and the `GlobalAcceleratorId`, waits for the task to complete, and reads back the resource state
63+
64+
#### Scenario: Update cross-border settings
65+
66+
- **WHEN** user changes `cross_border_type` or `cross_border_promise_flag`
67+
- **THEN** the system calls `ModifyGlobalAccelerator` with the updated values, waits for the task to complete, and reads back the resource state
68+
69+
### Requirement: Delete global accelerator instance
70+
71+
The system SHALL delete the global accelerator instance by calling `DeleteGlobalAccelerator` API with the `GlobalAcceleratorId`. After the API call, the system SHALL wait for the async task to complete.
72+
73+
#### Scenario: Successful deletion
74+
75+
- **WHEN** user destroys the Terraform resource
76+
- **THEN** the system calls `DeleteGlobalAccelerator` with the resource ID, waits for the task to complete
77+
78+
#### Scenario: Resource already deleted
79+
80+
- **WHEN** `DeleteGlobalAccelerator` returns a resource not found error
81+
- **THEN** the system treats the deletion as successful (no error)
82+
83+
### Requirement: Import global accelerator instance
84+
85+
The system SHALL support importing an existing global accelerator instance using its `GlobalAcceleratorId`.
86+
87+
#### Scenario: Successful import
88+
89+
- **WHEN** user runs `terraform import tencentcloud_ga2_global_accelerator.example <global_accelerator_id>`
90+
- **THEN** the system reads the instance state using `DescribeGlobalAccelerators` and populates all attributes
91+
92+
### Requirement: Register resource in provider
93+
94+
The system SHALL register `tencentcloud_ga2_global_accelerator` in `tencentcloud/provider.go` resource map and add the corresponding entry in `tencentcloud/provider.md`.
95+
96+
#### Scenario: Resource is available after registration
97+
98+
- **WHEN** the provider is initialized
99+
- **THEN** `tencentcloud_ga2_global_accelerator` is available as a valid resource type
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## 1. Service Layer
2+
3+
- [x] 1.1 Add `DescribeGa2GlobalAcceleratorById` method to `tencentcloud/services/ga2/service_tencentcloud_ga2.go` that queries a single global accelerator instance by ID using `DescribeGlobalAccelerators` API with `global-accelerator-id` filter
4+
5+
## 2. Resource Implementation
6+
7+
- [x] 2.1 Create `tencentcloud/services/ga2/resource_tc_ga2_global_accelerator.go` with schema definition including all input fields (`name`, `instance_charge_type`, `description`, `cross_border_type`, `cross_border_promise_flag`, `tags`) and computed fields (`create_time`, `state`, `status`, `ddos_id`, `cname`), with Timeouts block and Import support
8+
- [x] 2.2 Implement `resourceTencentCloudGa2GlobalAcceleratorCreate` function that calls `CreateGlobalAccelerator` API, validates response, sets resource ID, and waits for async task completion via `WaitForGa2TaskFinish`
9+
- [x] 2.3 Implement `resourceTencentCloudGa2GlobalAcceleratorRead` function that calls `DescribeGa2GlobalAcceleratorById`, handles not-found case, and sets all attributes from response
10+
- [x] 2.4 Implement `resourceTencentCloudGa2GlobalAcceleratorUpdate` function that calls `ModifyGlobalAccelerator` API with changed fields (`name`, `description`, `cross_border_type`, `cross_border_promise_flag`) and waits for async task completion
11+
- [x] 2.5 Implement `resourceTencentCloudGa2GlobalAcceleratorDelete` function that calls `DeleteGlobalAccelerator` API and waits for async task completion
12+
13+
## 3. Provider Registration
14+
15+
- [x] 3.1 Register `tencentcloud_ga2_global_accelerator` resource in `tencentcloud/provider.go` resource map
16+
- [x] 3.2 Add `tencentcloud_ga2_global_accelerator` entry in `tencentcloud/provider.md`
17+
18+
## 4. Documentation
19+
20+
- [x] 4.1 Create `tencentcloud/services/ga2/resource_tc_ga2_global_accelerator.md` with Example Usage and Import sections
21+
22+
## 5. Unit Tests
23+
24+
- [x] 5.1 Create `tencentcloud/services/ga2/resource_tc_ga2_global_accelerator_test.go` with gomonkey-based unit tests covering Create, Read, Update, and Delete operations
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## ADDED Requirements
2+
3+
### Requirement: Create global accelerator instance
4+
5+
The system SHALL provide a Terraform resource `tencentcloud_ga2_global_accelerator` that creates a GA2 global accelerator instance by calling the `CreateGlobalAccelerator` API with the following parameters:
6+
- `name` (Required, string): Instance name, max 60 bytes
7+
- `instance_charge_type` (Optional, string, ForceNew): Billing mode, valid values: `PREPAID`, `POSTPAID`. Default: `POSTPAID`
8+
- `description` (Optional, string): Description, max 100 bytes
9+
- `cross_border_type` (Optional, string): Cross-border type, valid values: `HighQuality`, `Unicom`
10+
- `cross_border_promise_flag` (Optional, bool): Cross-border service promise flag
11+
- `tags` (Optional, map of string, ForceNew): Tag information
12+
13+
After successful creation, the system SHALL set the resource ID to the returned `GlobalAcceleratorId` and wait for the async task to complete by polling `DescribeTaskResult` until status is SUCCESS.
14+
15+
#### Scenario: Successful creation with required parameters only
16+
17+
- **WHEN** user provides a valid `name` in the Terraform configuration
18+
- **THEN** the system calls `CreateGlobalAccelerator` API, sets the resource ID to the returned `GlobalAcceleratorId`, waits for the task to complete, and reads back the resource state
19+
20+
#### Scenario: Successful creation with all parameters
21+
22+
- **WHEN** user provides `name`, `instance_charge_type`, `description`, `cross_border_type`, `cross_border_promise_flag`, and `tags`
23+
- **THEN** the system calls `CreateGlobalAccelerator` API with all provided parameters, sets the resource ID, waits for the task to complete, and reads back the resource state
24+
25+
#### Scenario: Creation fails with nil response
26+
27+
- **WHEN** the `CreateGlobalAccelerator` API returns a nil response or nil `GlobalAcceleratorId`
28+
- **THEN** the system returns a NonRetryableError
29+
30+
### Requirement: Read global accelerator instance
31+
32+
The system SHALL read the global accelerator instance state by calling `DescribeGlobalAccelerators` API with a `global-accelerator-id` filter. The system SHALL set the following computed attributes from the response:
33+
- `name` (string)
34+
- `description` (string)
35+
- `instance_charge_type` (string)
36+
- `cross_border_type` (string)
37+
- `create_time` (Computed, string)
38+
- `state` (Computed, string)
39+
- `status` (Computed, string)
40+
- `ddos_id` (Computed, string)
41+
- `cname` (Computed, string)
42+
43+
#### Scenario: Successful read
44+
45+
- **WHEN** the resource exists and `DescribeGlobalAccelerators` returns a matching instance
46+
- **THEN** the system sets all computed and configured attributes from the `GlobalAcceleratorSet` response
47+
48+
#### Scenario: Resource not found
49+
50+
- **WHEN** `DescribeGlobalAccelerators` returns an empty `GlobalAcceleratorSet` for the given ID
51+
- **THEN** the system removes the resource from state (calls `d.SetId("")`)
52+
53+
### Requirement: Update global accelerator instance
54+
55+
The system SHALL update the global accelerator instance by calling `ModifyGlobalAccelerator` API when any of the following fields change: `name`, `description`, `cross_border_type`, `cross_border_promise_flag`. After the API call, the system SHALL wait for the async task to complete.
56+
57+
The fields `instance_charge_type` and `tags` are ForceNew and SHALL NOT be included in the update request.
58+
59+
#### Scenario: Update name and description
60+
61+
- **WHEN** user changes `name` or `description` in the Terraform configuration
62+
- **THEN** the system calls `ModifyGlobalAccelerator` with the new values and the `GlobalAcceleratorId`, waits for the task to complete, and reads back the resource state
63+
64+
#### Scenario: Update cross-border settings
65+
66+
- **WHEN** user changes `cross_border_type` or `cross_border_promise_flag`
67+
- **THEN** the system calls `ModifyGlobalAccelerator` with the updated values, waits for the task to complete, and reads back the resource state
68+
69+
### Requirement: Delete global accelerator instance
70+
71+
The system SHALL delete the global accelerator instance by calling `DeleteGlobalAccelerator` API with the `GlobalAcceleratorId`. After the API call, the system SHALL wait for the async task to complete.
72+
73+
#### Scenario: Successful deletion
74+
75+
- **WHEN** user destroys the Terraform resource
76+
- **THEN** the system calls `DeleteGlobalAccelerator` with the resource ID, waits for the task to complete
77+
78+
#### Scenario: Resource already deleted
79+
80+
- **WHEN** `DeleteGlobalAccelerator` returns a resource not found error
81+
- **THEN** the system treats the deletion as successful (no error)
82+
83+
### Requirement: Import global accelerator instance
84+
85+
The system SHALL support importing an existing global accelerator instance using its `GlobalAcceleratorId`.
86+
87+
#### Scenario: Successful import
88+
89+
- **WHEN** user runs `terraform import tencentcloud_ga2_global_accelerator.example <global_accelerator_id>`
90+
- **THEN** the system reads the instance state using `DescribeGlobalAccelerators` and populates all attributes
91+
92+
### Requirement: Register resource in provider
93+
94+
The system SHALL register `tencentcloud_ga2_global_accelerator` in `tencentcloud/provider.go` resource map and add the corresponding entry in `tencentcloud/provider.md`.
95+
96+
#### Scenario: Resource is available after registration
97+
98+
- **WHEN** the provider is initialized
99+
- **THEN** `tencentcloud_ga2_global_accelerator` is available as a valid resource type

tencentcloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,7 @@ func Provider() *schema.Provider {
17221722
"tencentcloud_dayu_l7_rule_v2": dayuv2.ResourceTencentCloudDayuL7RuleV2(),
17231723
"tencentcloud_dayu_eip": dayuv2.ResourceTencentCloudDayuEip(),
17241724
"tencentcloud_ga2_endpoint_group": ga2.ResourceTencentCloudGa2EndpointGroup(),
1725+
"tencentcloud_ga2_global_accelerator": ga2.ResourceTencentCloudGa2GlobalAccelerator(),
17251726
"tencentcloud_gaap_proxy": gaap.ResourceTencentCloudGaapProxy(),
17261727
"tencentcloud_gaap_realserver": gaap.ResourceTencentCloudGaapRealserver(),
17271728
"tencentcloud_gaap_layer4_listener": gaap.ResourceTencentCloudGaapLayer4Listener(),

tencentcloud/provider.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,11 @@ tencentcloud_igtm_strategy
26242624
tencentcloud_igtm_package_instance
26252625
tencentcloud_igtm_package_task
26262626

2627+
Global Accelerator(GA2)
2628+
Resource
2629+
tencentcloud_ga2_endpoint_group
2630+
tencentcloud_ga2_global_accelerator
2631+
26272632
VCube
26282633
Resource
26292634
tencentcloud_vcube_application_and_video

0 commit comments

Comments
 (0)