Skip to content

Commit d5e0a43

Browse files
authored
Merge pull request #1567 from tencentcloudstack/feat/support_chdfs_access
support chdfs access group
2 parents cbb613a + 719b18e commit d5e0a43

File tree

17 files changed

+4751
-8
lines changed

17 files changed

+4751
-8
lines changed

.changelog/1567.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_chdfs_access_group
3+
```

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ require (
3131
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.576
3232
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.539
3333
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.581
34+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600
3435
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.403
3536
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.599
3637
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
3738
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.412
38-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.599
39+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.600
3940
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.553
4041
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589
4142
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.572

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.539 h1:0L6nZhT
472472
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.539/go.mod h1:6Syk7W5fdDf0BLvX+RXL5obQ6unkt3Id4aN2QqVrV6U=
473473
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.581 h1:Ei818gJRB9wd1sGux9x9Hi3l9XwfYbPBhri6T3aYorc=
474474
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.581/go.mod h1:T7/YP64GYsB74saN6wG9IOQ1/XZFWX2MKEM9tphORYk=
475+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600 h1:qSpp4rEgAzfXhi1rPxes+AJp2mwnsyRGPY/Km1FuYGs=
476+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600/go.mod h1:xud1dQ7Rc23yC5kS00TYRrvZ/A+94EOkwquaI6xGVac=
475477
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.403 h1:rD9H4dQkULnRpq1BiD2KuDKsd9VEKHun2gMT+V6DNOE=
476478
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.403/go.mod h1:yWwwGj2gV0hRPfM9GXG4EgDee0cEWYcAwl/M8CTTvzM=
477479
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.591 h1:Rg1AD/9y3pwo7iQ//YwylFrQYsjFcYMCESA6XDkzlvI=
@@ -527,6 +529,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.593 h1:VjzQ
527529
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.593/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
528530
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.599 h1:9rMFA8++HynZHYz32gAluJ2ONtz7NjhlBaiomVHWwdw=
529531
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.599/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
532+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.600 h1:rYI1ZQUubjG6r87H65nn5Zwfo5J03rcFxefmVek+Wis=
533+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.600/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
530534
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.553 h1:Pl1kYgFhJp0QSoVFSzRsiGk+HfEAkBTQg7+O60tytNA=
531535
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.553/go.mod h1:dnnqPxXYK+kax3e1MKo/PI3iWJtytm6ogWKQHJS7SGE=
532536
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589 h1:LZihgirMH0vsaGScYexxwY0fTss9vHaSZs/YOQUVESg=

tencentcloud/connectivity/client.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
cdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb/v20170320"
2626
cdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
2727
cfs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs/v20190719"
28+
chdfs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs/v20201112"
2829
ckafka "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka/v20190819"
2930
clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
3031
audit "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit/v20190319"
@@ -156,6 +157,7 @@ type TencentCloudClient struct {
156157
tsfConn *tsf.Client
157158
mpsConn *mps.Client
158159
cwpConn *cwp.Client
160+
chdfsConn *chdfs.Client
159161
}
160162

161163
// NewClientProfile returns a new ClientProfile
@@ -1069,6 +1071,20 @@ func (me *TencentCloudClient) UseCwpClient() *cwp.Client {
10691071
return me.cwpConn
10701072
}
10711073

1074+
// UseChdfsClient returns chdfs client for service
1075+
func (me *TencentCloudClient) UseChdfsClient() *chdfs.Client {
1076+
if me.chdfsConn != nil {
1077+
return me.chdfsConn
1078+
}
1079+
1080+
cpf := me.NewClientProfile(300)
1081+
cpf.Language = "zh-CN"
1082+
me.chdfsConn, _ = chdfs.NewClient(me.Credential, me.Region, cpf)
1083+
me.chdfsConn.WithHttpTransport(&LogRoundTripper{})
1084+
1085+
return me.chdfsConn
1086+
}
1087+
10721088
func getEnvDefault(key string, defVal int) int {
10731089
val, ex := os.LookupEnv(key)
10741090
if !ex {

tencentcloud/provider.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,10 @@ Media Processing Service(MPS)
945945
tencentcloud_mps_transcode_template
946946
tencentcloud_mps_watermark_template
947947
948+
Cloud HDFS(CHDFS)
949+
Resource
950+
tencentcloud_chdfs_access_group
951+
948952
*/
949953
package tencentcloud
950954

@@ -1686,6 +1690,7 @@ func Provider() terraform.ResourceProvider {
16861690
"tencentcloud_cbs_disk_backup": resourceTencentCloudCbsDiskBackup(),
16871691
"tencentcloud_cbs_snapshot_share_permission": resourceTencentCloudCbsSnapshotSharePermission(),
16881692
"tencentcloud_cbs_disk_backup_rollback_operation": resourceTencentCloudCbsDiskBackupRollbackOperation(),
1693+
"tencentcloud_chdfs_access_group": resourceTencentCloudChdfsAccessGroup(),
16891694
},
16901695

16911696
ConfigureFunc: providerConfigure,
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
/*
2+
Provides a resource to create a chdfs access_group
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_chdfs_access_group" "access_group" {
8+
access_group_name = "testAccessGroup"
9+
vpc_type = 1
10+
vpc_id = "vpc-4owdpnwr"
11+
description = "test access group"
12+
}
13+
```
14+
15+
Import
16+
17+
chdfs access_group can be imported using the id, e.g.
18+
19+
```
20+
terraform import tencentcloud_chdfs_access_group.access_group access_group_id
21+
```
22+
*/
23+
package tencentcloud
24+
25+
import (
26+
"context"
27+
"fmt"
28+
"log"
29+
30+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
31+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
32+
chdfs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs/v20201112"
33+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
34+
)
35+
36+
func resourceTencentCloudChdfsAccessGroup() *schema.Resource {
37+
return &schema.Resource{
38+
Create: resourceTencentCloudChdfsAccessGroupCreate,
39+
Read: resourceTencentCloudChdfsAccessGroupRead,
40+
Update: resourceTencentCloudChdfsAccessGroupUpdate,
41+
Delete: resourceTencentCloudChdfsAccessGroupDelete,
42+
Importer: &schema.ResourceImporter{
43+
State: schema.ImportStatePassthrough,
44+
},
45+
Schema: map[string]*schema.Schema{
46+
"access_group_name": {
47+
Required: true,
48+
Type: schema.TypeString,
49+
Description: "Permission group name.",
50+
},
51+
52+
"vpc_type": {
53+
Required: true,
54+
Type: schema.TypeInt,
55+
Description: "vpc network type(1:CVM, 2:BM 1.0).",
56+
},
57+
58+
"vpc_id": {
59+
Required: true,
60+
Type: schema.TypeString,
61+
Description: "VPC ID.",
62+
},
63+
64+
"description": {
65+
Optional: true,
66+
Type: schema.TypeString,
67+
Description: "Permission group description, default empty.",
68+
},
69+
},
70+
}
71+
}
72+
73+
func resourceTencentCloudChdfsAccessGroupCreate(d *schema.ResourceData, meta interface{}) error {
74+
defer logElapsed("resource.tencentcloud_chdfs_access_group.create")()
75+
defer inconsistentCheck(d, meta)()
76+
77+
logId := getLogId(contextNil)
78+
79+
var (
80+
request = chdfs.NewCreateAccessGroupRequest()
81+
response = chdfs.NewCreateAccessGroupResponse()
82+
accessGroupId string
83+
)
84+
if v, ok := d.GetOk("access_group_name"); ok {
85+
request.AccessGroupName = helper.String(v.(string))
86+
}
87+
88+
if v, _ := d.GetOk("vpc_type"); v != nil {
89+
request.VpcType = helper.IntUint64(v.(int))
90+
}
91+
92+
if v, ok := d.GetOk("vpc_id"); ok {
93+
request.VpcId = helper.String(v.(string))
94+
}
95+
96+
if v, ok := d.GetOk("description"); ok {
97+
request.Description = helper.String(v.(string))
98+
}
99+
100+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
101+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseChdfsClient().CreateAccessGroup(request)
102+
if e != nil {
103+
return retryError(e)
104+
} else {
105+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
106+
}
107+
response = result
108+
return nil
109+
})
110+
if err != nil {
111+
log.Printf("[CRITAL]%s create chdfs accessGroup failed, reason:%+v", logId, err)
112+
return err
113+
}
114+
115+
accessGroupId = *response.Response.AccessGroup.AccessGroupId
116+
d.SetId(accessGroupId)
117+
118+
return resourceTencentCloudChdfsAccessGroupRead(d, meta)
119+
}
120+
121+
func resourceTencentCloudChdfsAccessGroupRead(d *schema.ResourceData, meta interface{}) error {
122+
defer logElapsed("resource.tencentcloud_chdfs_access_group.read")()
123+
defer inconsistentCheck(d, meta)()
124+
125+
logId := getLogId(contextNil)
126+
127+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
128+
129+
service := ChdfsService{client: meta.(*TencentCloudClient).apiV3Conn}
130+
131+
accessGroupId := d.Id()
132+
133+
accessGroup, err := service.DescribeChdfsAccessGroupById(ctx, accessGroupId)
134+
if err != nil {
135+
return err
136+
}
137+
138+
if accessGroup == nil {
139+
d.SetId("")
140+
log.Printf("[WARN]%s resource `ChdfsAccessGroup` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
141+
return nil
142+
}
143+
144+
if accessGroup.AccessGroupName != nil {
145+
_ = d.Set("access_group_name", accessGroup.AccessGroupName)
146+
}
147+
148+
if accessGroup.VpcType != nil {
149+
_ = d.Set("vpc_type", accessGroup.VpcType)
150+
}
151+
152+
if accessGroup.VpcId != nil {
153+
_ = d.Set("vpc_id", accessGroup.VpcId)
154+
}
155+
156+
if accessGroup.Description != nil {
157+
_ = d.Set("description", accessGroup.Description)
158+
}
159+
160+
return nil
161+
}
162+
163+
func resourceTencentCloudChdfsAccessGroupUpdate(d *schema.ResourceData, meta interface{}) error {
164+
defer logElapsed("resource.tencentcloud_chdfs_access_group.update")()
165+
defer inconsistentCheck(d, meta)()
166+
167+
logId := getLogId(contextNil)
168+
169+
request := chdfs.NewModifyAccessGroupRequest()
170+
171+
accessGroupId := d.Id()
172+
173+
request.AccessGroupId = &accessGroupId
174+
175+
immutableArgs := []string{"vpc_type", "vpc_id"}
176+
177+
for _, v := range immutableArgs {
178+
if d.HasChange(v) {
179+
return fmt.Errorf("argument `%s` cannot be changed", v)
180+
}
181+
}
182+
183+
if d.HasChange("access_group_name") {
184+
if v, ok := d.GetOk("access_group_name"); ok {
185+
request.AccessGroupName = helper.String(v.(string))
186+
}
187+
}
188+
189+
if d.HasChange("description") {
190+
if v, ok := d.GetOk("description"); ok {
191+
request.Description = helper.String(v.(string))
192+
}
193+
}
194+
195+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
196+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseChdfsClient().ModifyAccessGroup(request)
197+
if e != nil {
198+
return retryError(e)
199+
} else {
200+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
201+
}
202+
return nil
203+
})
204+
if err != nil {
205+
log.Printf("[CRITAL]%s update chdfs accessGroup failed, reason:%+v", logId, err)
206+
return err
207+
}
208+
209+
return resourceTencentCloudChdfsAccessGroupRead(d, meta)
210+
}
211+
212+
func resourceTencentCloudChdfsAccessGroupDelete(d *schema.ResourceData, meta interface{}) error {
213+
defer logElapsed("resource.tencentcloud_chdfs_access_group.delete")()
214+
defer inconsistentCheck(d, meta)()
215+
216+
logId := getLogId(contextNil)
217+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
218+
219+
service := ChdfsService{client: meta.(*TencentCloudClient).apiV3Conn}
220+
accessGroupId := d.Id()
221+
222+
if err := service.DeleteChdfsAccessGroupById(ctx, accessGroupId); err != nil {
223+
return err
224+
}
225+
226+
return nil
227+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudChdfsAccessGroupResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccChdfsAccessGroup,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_chdfs_access_group.access_group", "id")),
20+
},
21+
{
22+
Config: testAccChdfsAccessGroupUpdate,
23+
Check: resource.ComposeTestCheckFunc(
24+
resource.TestCheckResourceAttrSet("tencentcloud_chdfs_access_group.access_group", "id"),
25+
resource.TestCheckResourceAttr("tencentcloud_chdfs_access_group.access_group", "access_group_name", "testAccessGroupTotal"),
26+
resource.TestCheckResourceAttr("tencentcloud_chdfs_access_group.access_group", "description", "test access group total"),
27+
),
28+
},
29+
{
30+
ResourceName: "tencentcloud_chdfs_access_group.access_group",
31+
ImportState: true,
32+
ImportStateVerify: true,
33+
},
34+
},
35+
})
36+
}
37+
38+
const testAccChdfsAccessGroup = `
39+
40+
resource "tencentcloud_chdfs_access_group" "access_group" {
41+
access_group_name = "testAccessGroup"
42+
vpc_type = 1
43+
vpc_id = "vpc-4owdpnwr"
44+
description = "test access group"
45+
}
46+
47+
`
48+
49+
const testAccChdfsAccessGroupUpdate = `
50+
51+
resource "tencentcloud_chdfs_access_group" "access_group" {
52+
access_group_name = "testAccessGroupTotal"
53+
vpc_type = 1
54+
vpc_id = "vpc-4owdpnwr"
55+
description = "test access group total"
56+
}
57+
58+
`

0 commit comments

Comments
 (0)