Skip to content

Commit a545977

Browse files
committed
add mount point atttach
1 parent 9636994 commit a545977

File tree

6 files changed

+285
-0
lines changed

6 files changed

+285
-0
lines changed

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ Cloud HDFS(CHDFS)
956956
tencentcloud_chdfs_file_system
957957
tencentcloud_chdfs_life_cycle_rule
958958
tencentcloud_chdfs_mount_point
959+
tencentcloud_chdfs_mount_point_attachment
959960
960961
*/
961962
package tencentcloud
@@ -1706,6 +1707,7 @@ func Provider() terraform.ResourceProvider {
17061707
"tencentcloud_chdfs_file_system": resourceTencentCloudChdfsFileSystem(),
17071708
"tencentcloud_chdfs_life_cycle_rule": resourceTencentCloudChdfsLifeCycleRule(),
17081709
"tencentcloud_chdfs_mount_point": resourceTencentCloudChdfsMountPoint(),
1710+
"tencentcloud_chdfs_mount_point_attachment": resourceTencentCloudChdfsMountPointAttachment(),
17091711
},
17101712

17111713
ConfigureFunc: providerConfigure,
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
Provides a resource to create a chdfs mount_point_attachment
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_chdfs_mount_point_attachment" "mount_point_attachment" {
8+
access_group_ids = [
9+
"ag-bvmzrbsm",
10+
"ag-lairqrgr",
11+
]
12+
mount_point_id = "f14mpfy5lh4e-KuiL"
13+
}
14+
```
15+
16+
Import
17+
18+
chdfs mount_point_attachment can be imported using the id, e.g.
19+
20+
```
21+
terraform import tencentcloud_chdfs_mount_point_attachment.mount_point_attachment mount_point_id
22+
```
23+
*/
24+
package tencentcloud
25+
26+
import (
27+
"context"
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 resourceTencentCloudChdfsMountPointAttachment() *schema.Resource {
37+
return &schema.Resource{
38+
Create: resourceTencentCloudChdfsMountPointAttachmentCreate,
39+
Read: resourceTencentCloudChdfsMountPointAttachmentRead,
40+
Delete: resourceTencentCloudChdfsMountPointAttachmentDelete,
41+
Importer: &schema.ResourceImporter{
42+
State: schema.ImportStatePassthrough,
43+
},
44+
Schema: map[string]*schema.Schema{
45+
"mount_point_id": {
46+
Required: true,
47+
ForceNew: true,
48+
Type: schema.TypeString,
49+
Description: "associate mount point.",
50+
},
51+
52+
"access_group_ids": {
53+
Required: true,
54+
ForceNew: true,
55+
Type: schema.TypeSet,
56+
Elem: &schema.Schema{
57+
Type: schema.TypeString,
58+
},
59+
Description: "associate access group id.",
60+
},
61+
},
62+
}
63+
}
64+
65+
func resourceTencentCloudChdfsMountPointAttachmentCreate(d *schema.ResourceData, meta interface{}) error {
66+
defer logElapsed("resource.tencentcloud_chdfs_mount_point_attachment.create")()
67+
defer inconsistentCheck(d, meta)()
68+
69+
logId := getLogId(contextNil)
70+
71+
var (
72+
request = chdfs.NewAssociateAccessGroupsRequest()
73+
mountPointId string
74+
)
75+
if v, ok := d.GetOk("mount_point_id"); ok {
76+
mountPointId = v.(string)
77+
request.MountPointId = helper.String(v.(string))
78+
}
79+
80+
if v, ok := d.GetOk("access_group_ids"); ok {
81+
accessGroupIdsSet := v.(*schema.Set).List()
82+
for i := range accessGroupIdsSet {
83+
accessGroupIds := accessGroupIdsSet[i].(string)
84+
request.AccessGroupIds = append(request.AccessGroupIds, &accessGroupIds)
85+
}
86+
}
87+
88+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
89+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseChdfsClient().AssociateAccessGroups(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+
return nil
96+
})
97+
if err != nil {
98+
log.Printf("[CRITAL]%s create chdfs mountPointAttachment failed, reason:%+v", logId, err)
99+
return err
100+
}
101+
102+
d.SetId(mountPointId)
103+
104+
return resourceTencentCloudChdfsMountPointAttachmentRead(d, meta)
105+
}
106+
107+
func resourceTencentCloudChdfsMountPointAttachmentRead(d *schema.ResourceData, meta interface{}) error {
108+
defer logElapsed("resource.tencentcloud_chdfs_mount_point_attachment.read")()
109+
defer inconsistentCheck(d, meta)()
110+
111+
logId := getLogId(contextNil)
112+
113+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
114+
115+
service := ChdfsService{client: meta.(*TencentCloudClient).apiV3Conn}
116+
117+
mountPointId := d.Id()
118+
119+
mountPointAttachment, err := service.DescribeChdfsMountPointById(ctx, mountPointId)
120+
if err != nil {
121+
return err
122+
}
123+
124+
if mountPointAttachment == nil {
125+
d.SetId("")
126+
log.Printf("[WARN]%s resource `ChdfsMountPointAttachment` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
127+
return nil
128+
}
129+
130+
if mountPointAttachment.MountPointId != nil {
131+
_ = d.Set("mount_point_id", mountPointAttachment.MountPointId)
132+
}
133+
134+
if mountPointAttachment.AccessGroupIds != nil {
135+
_ = d.Set("access_group_ids", mountPointAttachment.AccessGroupIds)
136+
}
137+
138+
return nil
139+
}
140+
141+
func resourceTencentCloudChdfsMountPointAttachmentDelete(d *schema.ResourceData, meta interface{}) error {
142+
defer logElapsed("resource.tencentcloud_chdfs_mount_point_attachment.delete")()
143+
defer inconsistentCheck(d, meta)()
144+
145+
logId := getLogId(contextNil)
146+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
147+
148+
service := ChdfsService{client: meta.(*TencentCloudClient).apiV3Conn}
149+
150+
mountPointId := d.Id()
151+
152+
mountPoint, err := service.DescribeChdfsMountPointById(ctx, mountPointId)
153+
if err != nil {
154+
return err
155+
}
156+
157+
if err := service.DeleteChdfsMountPointAttachmentById(ctx, mountPointId, mountPoint.AccessGroupIds); err != nil {
158+
return err
159+
}
160+
161+
return nil
162+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudChdfsMountPointAttachmentResource_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: testAccChdfsMountPointAttachment,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_chdfs_mount_point_attachment.mount_point_attachment", "id")),
20+
},
21+
{
22+
ResourceName: "tencentcloud_chdfs_mount_point_attachment.mount_point_attachment",
23+
ImportState: true,
24+
ImportStateVerify: true,
25+
},
26+
},
27+
})
28+
}
29+
30+
const testAccChdfsMountPointAttachment = `
31+
32+
resource "tencentcloud_chdfs_mount_point" "mount_point" {
33+
file_system_id = "f14mpfy5lh4e"
34+
mount_point_name = "terraform-test-mount-attach"
35+
mount_point_status = 1
36+
}
37+
38+
resource "tencentcloud_chdfs_mount_point_attachment" "mount_point_attachment" {
39+
access_group_ids = [
40+
"ag-bvmzrbsm",
41+
]
42+
mount_point_id = tencentcloud_chdfs_mount_point.mount_point.id
43+
}
44+
45+
`

tencentcloud/service_tencentcloud_chdfs.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,28 @@ func (me *ChdfsService) DeleteChdfsMountPointById(ctx context.Context, mountPoin
338338

339339
return
340340
}
341+
342+
func (me *ChdfsService) DeleteChdfsMountPointAttachmentById(ctx context.Context, mountPointId string, accessGroupIds []*string) (errRet error) {
343+
logId := getLogId(ctx)
344+
345+
request := chdfs.NewDisassociateAccessGroupsRequest()
346+
request.MountPointId = &mountPointId
347+
request.AccessGroupIds = accessGroupIds
348+
349+
defer func() {
350+
if errRet != nil {
351+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
352+
}
353+
}()
354+
355+
ratelimit.Check(request.GetAction())
356+
357+
response, err := me.client.UseChdfsClient().DisassociateAccessGroups(request)
358+
if err != nil {
359+
errRet = err
360+
return
361+
}
362+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
363+
364+
return
365+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
subcategory: "Cloud HDFS(CHDFS)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_chdfs_mount_point_attachment"
5+
sidebar_current: "docs-tencentcloud-resource-chdfs_mount_point_attachment"
6+
description: |-
7+
Provides a resource to create a chdfs mount_point_attachment
8+
---
9+
10+
# tencentcloud_chdfs_mount_point_attachment
11+
12+
Provides a resource to create a chdfs mount_point_attachment
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_chdfs_mount_point_attachment" "mount_point_attachment" {
18+
access_group_ids = [
19+
"ag-bvmzrbsm",
20+
"ag-lairqrgr",
21+
]
22+
mount_point_id = "f14mpfy5lh4e-KuiL"
23+
}
24+
```
25+
26+
## Argument Reference
27+
28+
The following arguments are supported:
29+
30+
* `access_group_ids` - (Required, Set: [`String`], ForceNew) associate access group id.
31+
* `mount_point_id` - (Required, String, ForceNew) associate mount point.
32+
33+
## Attributes Reference
34+
35+
In addition to all arguments above, the following attributes are exported:
36+
37+
* `id` - ID of the resource.
38+
39+
40+
41+
## Import
42+
43+
chdfs mount_point_attachment can be imported using the id, e.g.
44+
45+
```
46+
terraform import tencentcloud_chdfs_mount_point_attachment.mount_point_attachment mount_point_id
47+
```
48+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@
583583
<li>
584584
<a href="/docs/providers/tencentcloud/r/chdfs_mount_point.html">tencentcloud_chdfs_mount_point</a>
585585
</li>
586+
<li>
587+
<a href="/docs/providers/tencentcloud/r/chdfs_mount_point_attachment.html">tencentcloud_chdfs_mount_point_attachment</a>
588+
</li>
586589
</ul>
587590
</li>
588591
</ul>

0 commit comments

Comments
 (0)