Skip to content

Commit ac5359e

Browse files
authored
add chdfs datasource (#1870)
* add chdfs datasource * add chdfs datasource
1 parent 3bb3c2c commit ac5359e

File tree

7 files changed

+321
-0
lines changed

7 files changed

+321
-0
lines changed

.changelog/1870.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-data-source
2+
tencentcloud_chdfs_file_systems
3+
```
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/*
2+
Use this data source to query detailed information of chdfs file_systems
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_chdfs_file_systems" "file_systems" {}
8+
```
9+
*/
10+
package tencentcloud
11+
12+
import (
13+
"context"
14+
15+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
16+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
17+
chdfs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs/v20201112"
18+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
19+
)
20+
21+
func dataSourceTencentCloudChdfsFileSystems() *schema.Resource {
22+
return &schema.Resource{
23+
Read: dataSourceTencentCloudChdfsFileSystemsRead,
24+
Schema: map[string]*schema.Schema{
25+
"file_systems": {
26+
Computed: true,
27+
Type: schema.TypeList,
28+
Description: "file system list.",
29+
Elem: &schema.Resource{
30+
Schema: map[string]*schema.Schema{
31+
"app_id": {
32+
Type: schema.TypeInt,
33+
Computed: true,
34+
Description: "appid of the user.",
35+
},
36+
"file_system_name": {
37+
Type: schema.TypeString,
38+
Computed: true,
39+
Description: "file system name.",
40+
},
41+
"description": {
42+
Type: schema.TypeString,
43+
Computed: true,
44+
Description: "desc of the file system.",
45+
},
46+
"region": {
47+
Type: schema.TypeString,
48+
Computed: true,
49+
Description: "region of the file system.",
50+
},
51+
"file_system_id": {
52+
Type: schema.TypeString,
53+
Computed: true,
54+
Description: "file system id.",
55+
},
56+
"create_time": {
57+
Type: schema.TypeString,
58+
Computed: true,
59+
Description: "create time.",
60+
},
61+
"block_size": {
62+
Type: schema.TypeInt,
63+
Computed: true,
64+
Description: "block size of the file system(byte).",
65+
},
66+
"capacity_quota": {
67+
Type: schema.TypeInt,
68+
Computed: true,
69+
Description: "capacity of the file system(byte).",
70+
},
71+
"status": {
72+
Type: schema.TypeInt,
73+
Computed: true,
74+
Description: "status of the file system(1: creating create success 3: create failed).",
75+
},
76+
"super_users": {
77+
Type: schema.TypeSet,
78+
Elem: &schema.Schema{
79+
Type: schema.TypeString,
80+
},
81+
Computed: true,
82+
Description: "super users of the file system.",
83+
},
84+
"posix_acl": {
85+
Type: schema.TypeBool,
86+
Computed: true,
87+
Description: "check POSIX ACL or not.",
88+
},
89+
"enable_ranger": {
90+
Type: schema.TypeBool,
91+
Computed: true,
92+
Description: "check the ranger address or not.",
93+
},
94+
"ranger_service_addresses": {
95+
Type: schema.TypeSet,
96+
Elem: &schema.Schema{
97+
Type: schema.TypeString,
98+
},
99+
Computed: true,
100+
Description: "ranger address list.",
101+
},
102+
},
103+
},
104+
},
105+
106+
"result_output_file": {
107+
Type: schema.TypeString,
108+
Optional: true,
109+
Description: "Used to save results.",
110+
},
111+
},
112+
}
113+
}
114+
115+
func dataSourceTencentCloudChdfsFileSystemsRead(d *schema.ResourceData, meta interface{}) error {
116+
defer logElapsed("data_source.tencentcloud_chdfs_file_systems.read")()
117+
defer inconsistentCheck(d, meta)()
118+
119+
logId := getLogId(contextNil)
120+
121+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
122+
123+
service := ChdfsService{client: meta.(*TencentCloudClient).apiV3Conn}
124+
125+
var fileSystems []*chdfs.FileSystem
126+
127+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
128+
result, e := service.DescribeChdfsFileSystems(ctx)
129+
if e != nil {
130+
return retryError(e)
131+
}
132+
fileSystems = result
133+
return nil
134+
})
135+
if err != nil {
136+
return err
137+
}
138+
139+
ids := make([]string, 0, len(fileSystems))
140+
tmpList := make([]map[string]interface{}, 0, len(fileSystems))
141+
142+
if fileSystems != nil {
143+
for _, fileSystem := range fileSystems {
144+
fileSystemMap := map[string]interface{}{}
145+
146+
if fileSystem.AppId != nil {
147+
fileSystemMap["app_id"] = fileSystem.AppId
148+
}
149+
150+
if fileSystem.FileSystemName != nil {
151+
fileSystemMap["file_system_name"] = fileSystem.FileSystemName
152+
}
153+
154+
if fileSystem.Description != nil {
155+
fileSystemMap["description"] = fileSystem.Description
156+
}
157+
158+
if fileSystem.Region != nil {
159+
fileSystemMap["region"] = fileSystem.Region
160+
}
161+
162+
if fileSystem.FileSystemId != nil {
163+
fileSystemMap["file_system_id"] = fileSystem.FileSystemId
164+
}
165+
166+
if fileSystem.CreateTime != nil {
167+
fileSystemMap["create_time"] = fileSystem.CreateTime
168+
}
169+
170+
if fileSystem.BlockSize != nil {
171+
fileSystemMap["block_size"] = fileSystem.BlockSize
172+
}
173+
174+
if fileSystem.CapacityQuota != nil {
175+
fileSystemMap["capacity_quota"] = fileSystem.CapacityQuota
176+
}
177+
178+
if fileSystem.Status != nil {
179+
fileSystemMap["status"] = fileSystem.Status
180+
}
181+
182+
if fileSystem.SuperUsers != nil {
183+
fileSystemMap["super_users"] = fileSystem.SuperUsers
184+
}
185+
186+
if fileSystem.PosixAcl != nil {
187+
fileSystemMap["posix_acl"] = fileSystem.PosixAcl
188+
}
189+
190+
if fileSystem.EnableRanger != nil {
191+
fileSystemMap["enable_ranger"] = fileSystem.EnableRanger
192+
}
193+
194+
if fileSystem.RangerServiceAddresses != nil {
195+
fileSystemMap["ranger_service_addresses"] = fileSystem.RangerServiceAddresses
196+
}
197+
198+
ids = append(ids, *fileSystem.FileSystemId)
199+
tmpList = append(tmpList, fileSystemMap)
200+
}
201+
202+
_ = d.Set("file_systems", tmpList)
203+
}
204+
205+
d.SetId(helper.DataResourceIdsHash(ids))
206+
output, ok := d.GetOk("result_output_file")
207+
if ok && output.(string) != "" {
208+
if e := writeToFile(output.(string), tmpList); e != nil {
209+
return e
210+
}
211+
}
212+
return nil
213+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudChdfsFileSystemsDataSource_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: testAccChdfsFileSystemsDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_chdfs_file_systems.file_systems")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccChdfsFileSystemsDataSource = `
26+
27+
data "tencentcloud_chdfs_file_systems" "file_systems" {}
28+
29+
`

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ Cloud HDFS(CHDFS)
13771377
Data Source
13781378
tencentcloud_chdfs_access_groups
13791379
tencentcloud_chdfs_mount_points
1380+
tencentcloud_chdfs_file_systems
13801381
13811382
Resource
13821383
tencentcloud_chdfs_access_group
@@ -1913,6 +1914,7 @@ func Provider() *schema.Provider {
19131914
"tencentcloud_css_domains": dataSourceTencentCloudCssDomains(),
19141915
"tencentcloud_chdfs_access_groups": dataSourceTencentCloudChdfsAccessGroups(),
19151916
"tencentcloud_chdfs_mount_points": dataSourceTencentCloudChdfsMountPoints(),
1917+
"tencentcloud_chdfs_file_systems": dataSourceTencentCloudChdfsFileSystems(),
19161918
"tencentcloud_tcm_mesh": dataSourceTencentCloudTcmMesh(),
19171919
"tencentcloud_lighthouse_firewall_rules_template": dataSourceTencentCloudLighthouseFirewallRulesTemplate(),
19181920
"tencentcloud_cvm_instance_vnc_url": dataSourceTencentCloudCvmInstanceVncUrl(),

tencentcloud/service_tencentcloud_chdfs.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,29 @@ func (me *ChdfsService) DescribeChdfsMountPointsByFilter(ctx context.Context, pa
436436

437437
return
438438
}
439+
440+
func (me *ChdfsService) DescribeChdfsFileSystems(ctx context.Context) (fileSystems []*chdfs.FileSystem, errRet error) {
441+
var (
442+
logId = getLogId(ctx)
443+
request = chdfs.NewDescribeFileSystemsRequest()
444+
)
445+
446+
defer func() {
447+
if errRet != nil {
448+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
449+
}
450+
}()
451+
452+
ratelimit.Check(request.GetAction())
453+
454+
response, err := me.client.UseChdfsClient().DescribeFileSystems(request)
455+
if err != nil {
456+
errRet = err
457+
return
458+
}
459+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
460+
461+
fileSystems = response.Response.FileSystems
462+
463+
return
464+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
subcategory: "Cloud HDFS(CHDFS)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_chdfs_file_systems"
5+
sidebar_current: "docs-tencentcloud-datasource-chdfs_file_systems"
6+
description: |-
7+
Use this data source to query detailed information of chdfs file_systems
8+
---
9+
10+
# tencentcloud_chdfs_file_systems
11+
12+
Use this data source to query detailed information of chdfs file_systems
13+
14+
## Example Usage
15+
16+
```hcl
17+
data "tencentcloud_chdfs_file_systems" "file_systems" {}
18+
```
19+
20+
## Argument Reference
21+
22+
The following arguments are supported:
23+
24+
* `result_output_file` - (Optional, String) Used to save results.
25+
26+
## Attributes Reference
27+
28+
In addition to all arguments above, the following attributes are exported:
29+
30+
* `file_systems` - file system list.
31+
* `app_id` - appid of the user.
32+
* `block_size` - block size of the file system(byte).
33+
* `capacity_quota` - capacity of the file system(byte).
34+
* `create_time` - create time.
35+
* `description` - desc of the file system.
36+
* `enable_ranger` - check the ranger address or not.
37+
* `file_system_id` - file system id.
38+
* `file_system_name` - file system name.
39+
* `posix_acl` - check POSIX ACL or not.
40+
* `ranger_service_addresses` - ranger address list.
41+
* `region` - region of the file system.
42+
* `status` - status of the file system(1: creating create success 3: create failed).
43+
* `super_users` - super users of the file system.
44+
45+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,9 @@
626626
<li>
627627
<a href="/docs/providers/tencentcloud/d/chdfs_access_groups.html">tencentcloud_chdfs_access_groups</a>
628628
</li>
629+
<li>
630+
<a href="/docs/providers/tencentcloud/d/chdfs_file_systems.html">tencentcloud_chdfs_file_systems</a>
631+
</li>
629632
<li>
630633
<a href="/docs/providers/tencentcloud/d/chdfs_mount_points.html">tencentcloud_chdfs_mount_points</a>
631634
</li>

0 commit comments

Comments
 (0)