Skip to content

Commit a464e1e

Browse files
tongyimingmikatong
andauthored
support gaap group (#2376)
* support gaap group * add changelog * update doc --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent aa08764 commit a464e1e

File tree

8 files changed

+367
-0
lines changed

8 files changed

+367
-0
lines changed

.changelog/2376.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
tencentcloud_gaap_proxy_group
3+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Provides a resource to create a gaap proxy group
2+
3+
Example Usage
4+
5+
```hcl
6+
resource "tencentcloud_gaap_proxy_group" "proxy_group" {
7+
project_id = 0
8+
group_name = "tf-test-update"
9+
real_server_region = "Beijing"
10+
ip_address_version = "IPv4"
11+
package_type = "Thunder"
12+
}
13+
```
14+
15+
Import
16+
17+
gaap proxy_group can be imported using the id, e.g.
18+
19+
```
20+
terraform import tencentcloud_gaap_proxy_group.proxy_group proxy_group_id
21+
```

tencentcloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ func Provider() *schema.Provider {
11201120
"tencentcloud_gaap_domain_error_page": resourceTencentCloudGaapDomainErrorPageInfo(),
11211121
"tencentcloud_gaap_global_domain_dns": resourceTencentCloudGaapGlobalDomainDns(),
11221122
"tencentcloud_gaap_global_domain": resourceTencentCloudGaapGlobalDomain(),
1123+
"tencentcloud_gaap_proxy_group": resourceTencentCloudGaapProxyGroup(),
11231124
"tencentcloud_ssl_certificate": resourceTencentCloudSslCertificate(),
11241125
"tencentcloud_ssl_pay_certificate": resourceTencentCloudSSLInstance(),
11251126
"tencentcloud_ssl_free_certificate": resourceTencentCloudSSLFreeCertificate(),

tencentcloud/provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ Global Application Acceleration(GAAP)
611611

612612
Resource
613613
tencentcloud_gaap_proxy
614+
tencentcloud_gaap_proxy_group
614615
tencentcloud_gaap_realserver
615616
tencentcloud_gaap_layer4_listener
616617
tencentcloud_gaap_layer7_listener
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
package tencentcloud
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
gaap "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap/v20180529"
11+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
12+
)
13+
14+
func resourceTencentCloudGaapProxyGroup() *schema.Resource {
15+
return &schema.Resource{
16+
Create: resourceTencentCloudGaapProxyGroupCreate,
17+
Read: resourceTencentCloudGaapProxyGroupRead,
18+
Update: resourceTencentCloudGaapProxyGroupUpdate,
19+
Delete: resourceTencentCloudGaapProxyGroupDelete,
20+
Importer: &schema.ResourceImporter{
21+
State: schema.ImportStatePassthrough,
22+
},
23+
Schema: map[string]*schema.Schema{
24+
"project_id": {
25+
Required: true,
26+
Type: schema.TypeInt,
27+
Description: "ID of the project to which the proxy group belongs.",
28+
},
29+
30+
"group_name": {
31+
Required: true,
32+
Type: schema.TypeString,
33+
Description: "Channel group alias.",
34+
},
35+
36+
"real_server_region": {
37+
Required: true,
38+
Type: schema.TypeString,
39+
Description: "real server region, refer to the interface DescribeDestRegions to return the RegionId in the parameter RegionDetail.",
40+
},
41+
42+
"ip_address_version": {
43+
Optional: true,
44+
Type: schema.TypeString,
45+
Description: "IP version, can be taken as IPv4 or IPv6 with a default value of IPv4.",
46+
},
47+
48+
"package_type": {
49+
Optional: true,
50+
Type: schema.TypeString,
51+
Description: "Package type of channel group. Available values: Thunder and Accelerator. Default is Thunder.",
52+
},
53+
},
54+
}
55+
}
56+
57+
func resourceTencentCloudGaapProxyGroupCreate(d *schema.ResourceData, meta interface{}) error {
58+
defer logElapsed("resource.tencentcloud_gaap_proxy_group.create")()
59+
defer inconsistentCheck(d, meta)()
60+
61+
logId := getLogId(contextNil)
62+
63+
var (
64+
request = gaap.NewCreateProxyGroupRequest()
65+
response = gaap.NewCreateProxyGroupResponse()
66+
groupId string
67+
)
68+
if v, ok := d.GetOkExists("project_id"); ok {
69+
request.ProjectId = helper.IntUint64(v.(int))
70+
}
71+
72+
if v, ok := d.GetOk("group_name"); ok {
73+
request.GroupName = helper.String(v.(string))
74+
}
75+
76+
if v, ok := d.GetOk("real_server_region"); ok {
77+
request.RealServerRegion = helper.String(v.(string))
78+
}
79+
80+
if v, ok := d.GetOk("ip_address_version"); ok {
81+
request.IPAddressVersion = helper.String(v.(string))
82+
}
83+
84+
if v, ok := d.GetOk("package_type"); ok {
85+
request.PackageType = helper.String(v.(string))
86+
}
87+
88+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
89+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseGaapClient().CreateProxyGroup(request)
90+
if e != nil {
91+
return retryError(e)
92+
} else {
93+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
94+
}
95+
response = result
96+
return nil
97+
})
98+
if err != nil {
99+
log.Printf("[CRITAL]%s create gaap proxyGroup failed, reason:%+v", logId, err)
100+
return err
101+
}
102+
103+
groupId = *response.Response.GroupId
104+
d.SetId(groupId)
105+
106+
return resourceTencentCloudGaapProxyGroupRead(d, meta)
107+
}
108+
109+
func resourceTencentCloudGaapProxyGroupRead(d *schema.ResourceData, meta interface{}) error {
110+
defer logElapsed("resource.tencentcloud_gaap_proxy_group.read")()
111+
defer inconsistentCheck(d, meta)()
112+
113+
logId := getLogId(contextNil)
114+
115+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
116+
117+
service := GaapService{client: meta.(*TencentCloudClient).apiV3Conn}
118+
119+
groupId := d.Id()
120+
121+
proxyGroup, err := service.DescribeGaapProxyGroupById(ctx, groupId)
122+
if err != nil {
123+
return err
124+
}
125+
126+
if proxyGroup == nil {
127+
d.SetId("")
128+
log.Printf("[WARN]%s resource `GaapProxyGroup` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
129+
return nil
130+
}
131+
132+
if proxyGroup.ProjectId != nil {
133+
_ = d.Set("project_id", proxyGroup.ProjectId)
134+
}
135+
136+
if proxyGroup.GroupName != nil {
137+
_ = d.Set("group_name", proxyGroup.GroupName)
138+
}
139+
140+
if proxyGroup.RealServerRegionInfo != nil && proxyGroup.RealServerRegionInfo.RegionId != nil {
141+
_ = d.Set("real_server_region", proxyGroup.RealServerRegionInfo.RegionId)
142+
}
143+
144+
if proxyGroup.IPAddressVersion != nil {
145+
_ = d.Set("ip_address_version", proxyGroup.IPAddressVersion)
146+
}
147+
148+
if proxyGroup.PackageType != nil {
149+
_ = d.Set("package_type", proxyGroup.PackageType)
150+
}
151+
152+
return nil
153+
}
154+
155+
func resourceTencentCloudGaapProxyGroupUpdate(d *schema.ResourceData, meta interface{}) error {
156+
defer logElapsed("resource.tencentcloud_gaap_proxy_group.update")()
157+
defer inconsistentCheck(d, meta)()
158+
159+
logId := getLogId(contextNil)
160+
161+
request := gaap.NewModifyProxyGroupAttributeRequest()
162+
163+
groupId := d.Id()
164+
165+
request.GroupId = &groupId
166+
167+
immutableArgs := []string{"real_server_region", "ip_address_version", "package_type"}
168+
169+
for _, v := range immutableArgs {
170+
if d.HasChange(v) {
171+
return fmt.Errorf("argument `%s` cannot be changed", v)
172+
}
173+
}
174+
175+
isChanged := false
176+
if d.HasChange("project_id") {
177+
if v, ok := d.GetOkExists("project_id"); ok {
178+
request.ProjectId = helper.IntUint64(v.(int))
179+
isChanged = true
180+
}
181+
}
182+
183+
if d.HasChange("group_name") {
184+
if v, ok := d.GetOk("group_name"); ok {
185+
request.GroupName = helper.String(v.(string))
186+
isChanged = true
187+
}
188+
}
189+
190+
if isChanged {
191+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
192+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseGaapClient().ModifyProxyGroupAttribute(request)
193+
if e != nil {
194+
return retryError(e)
195+
} else {
196+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
197+
}
198+
return nil
199+
})
200+
if err != nil {
201+
log.Printf("[CRITAL]%s update gaap proxyGroup failed, reason:%+v", logId, err)
202+
return err
203+
}
204+
}
205+
206+
return resourceTencentCloudGaapProxyGroupRead(d, meta)
207+
}
208+
209+
func resourceTencentCloudGaapProxyGroupDelete(d *schema.ResourceData, meta interface{}) error {
210+
defer logElapsed("resource.tencentcloud_gaap_proxy_group.delete")()
211+
defer inconsistentCheck(d, meta)()
212+
213+
logId := getLogId(contextNil)
214+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
215+
216+
service := GaapService{client: meta.(*TencentCloudClient).apiV3Conn}
217+
groupId := d.Id()
218+
219+
if err := service.DeleteGaapProxyGroupById(ctx, groupId); err != nil {
220+
return err
221+
}
222+
223+
return nil
224+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudGaapProxyGroupResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
13+
Providers: testAccProviders,
14+
Steps: []resource.TestStep{
15+
{
16+
Config: testAccGaapProxyGroup,
17+
Check: resource.ComposeTestCheckFunc(
18+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy_group.proxy_group", "id"),
19+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy_group.proxy_group", "group_name", "tf-test"),
20+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy_group.proxy_group", "ip_address_version", "IPv4"),
21+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy_group.proxy_group", "package_type", "Thunder"),
22+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy_group.proxy_group", "project_id", "0"),
23+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy_group.proxy_group", "real_server_region", "Beijing"),
24+
),
25+
},
26+
{
27+
Config: testAccGaapProxyGroupUpdate,
28+
Check: resource.ComposeTestCheckFunc(
29+
resource.TestCheckResourceAttrSet("tencentcloud_gaap_proxy_group.proxy_group", "id"),
30+
resource.TestCheckResourceAttr("tencentcloud_gaap_proxy_group.proxy_group", "group_name", "tf-test-update"),
31+
),
32+
},
33+
{
34+
ResourceName: "tencentcloud_gaap_proxy_group.proxy_group",
35+
ImportState: true,
36+
ImportStateVerify: true,
37+
},
38+
},
39+
})
40+
}
41+
42+
const testAccGaapProxyGroup = `
43+
resource "tencentcloud_gaap_proxy_group" "proxy_group" {
44+
project_id = 0
45+
group_name = "tf-test"
46+
real_server_region = "Beijing"
47+
ip_address_version = "IPv4"
48+
package_type = "Thunder"
49+
}
50+
`
51+
52+
const testAccGaapProxyGroupUpdate = `
53+
resource "tencentcloud_gaap_proxy_group" "proxy_group" {
54+
project_id = 0
55+
group_name = "tf-test-update"
56+
real_server_region = "Beijing"
57+
ip_address_version = "IPv4"
58+
package_type = "Thunder"
59+
}
60+
`
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
subcategory: "Global Application Acceleration(GAAP)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_gaap_proxy_group"
5+
sidebar_current: "docs-tencentcloud-resource-gaap_proxy_group"
6+
description: |-
7+
Provides a resource to create a gaap proxy group
8+
---
9+
10+
# tencentcloud_gaap_proxy_group
11+
12+
Provides a resource to create a gaap proxy group
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_gaap_proxy_group" "proxy_group" {
18+
project_id = 0
19+
group_name = "tf-test-update"
20+
real_server_region = "Beijing"
21+
ip_address_version = "IPv4"
22+
package_type = "Thunder"
23+
}
24+
```
25+
26+
## Argument Reference
27+
28+
The following arguments are supported:
29+
30+
* `group_name` - (Required, String) Channel group alias.
31+
* `project_id` - (Required, Int) ID of the project to which the proxy group belongs.
32+
* `real_server_region` - (Required, String) real server region, refer to the interface DescribeDestRegions to return the RegionId in the parameter RegionDetail.
33+
* `ip_address_version` - (Optional, String) IP version, can be taken as IPv4 or IPv6 with a default value of IPv4.
34+
* `package_type` - (Optional, String) Package type of channel group. Available values: Thunder and Accelerator. Default is Thunder.
35+
36+
## Attributes Reference
37+
38+
In addition to all arguments above, the following attributes are exported:
39+
40+
* `id` - ID of the resource.
41+
42+
43+
44+
## Import
45+
46+
gaap proxy_group can be imported using the id, e.g.
47+
48+
```
49+
terraform import tencentcloud_gaap_proxy_group.proxy_group proxy_group_id
50+
```
51+

0 commit comments

Comments
 (0)