Skip to content

Commit 3614ab5

Browse files
committed
add life cycle rules
1 parent 5cfb575 commit 3614ab5

File tree

6 files changed

+160
-16
lines changed

6 files changed

+160
-16
lines changed

tencentcloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ Cloud HDFS(CHDFS)
954954
tencentcloud_chdfs_access_group
955955
tencentcloud_chdfs_access_rule
956956
tencentcloud_chdfs_file_system
957+
tencentcloud_chdfs_life_cycle_rule
957958
958959
*/
959960
package tencentcloud

tencentcloud/resource_tc_chdfs_life_cycle_rule.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ Example Usage
55
66
```hcl
77
resource "tencentcloud_chdfs_life_cycle_rule" "life_cycle_rule" {
8-
file_system_id = "xxxx"
8+
file_system_id = "f14mpfy5lh4e"
9+
910
life_cycle_rule {
10-
life_cycle_rule_name = "test"
11-
path = "/"
11+
life_cycle_rule_name = "terraform-test"
12+
path = "/test"
13+
status = 1
14+
1215
transitions {
13-
days = 1
16+
days = 30
1417
type = 1
1518
}
16-
status = 1
1719
}
1820
}
1921
```
@@ -121,10 +123,9 @@ func resourceTencentCloudChdfsLifeCycleRuleCreate(d *schema.ResourceData, meta i
121123
logId := getLogId(contextNil)
122124

123125
var (
124-
request = chdfs.NewCreateLifeCycleRulesRequest()
125-
//response = chdfs.NewCreateLifeCycleRulesResponse()
126-
fileSystemId string
127-
lifeCycleRuleId uint64
126+
request = chdfs.NewCreateLifeCycleRulesRequest()
127+
fileSystemId string
128+
path string
128129
)
129130
if v, ok := d.GetOk("file_system_id"); ok {
130131
fileSystemId = v.(string)
@@ -137,6 +138,7 @@ func resourceTencentCloudChdfsLifeCycleRuleCreate(d *schema.ResourceData, meta i
137138
lifeCycleRule.LifeCycleRuleName = helper.String(v.(string))
138139
}
139140
if v, ok := dMap["path"]; ok {
141+
path = v.(string)
140142
lifeCycleRule.Path = helper.String(v.(string))
141143
}
142144
if v, ok := dMap["transitions"]; ok {
@@ -173,7 +175,14 @@ func resourceTencentCloudChdfsLifeCycleRuleCreate(d *schema.ResourceData, meta i
173175
return err
174176
}
175177

176-
d.SetId(fileSystemId + FILED_SP + helper.UInt64ToStr(lifeCycleRuleId))
178+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
179+
service := ChdfsService{client: meta.(*TencentCloudClient).apiV3Conn}
180+
lifeCycleRule, err := service.DescribeChdfsLifeCycleRuleByPath(ctx, fileSystemId, path)
181+
if err != nil {
182+
return err
183+
}
184+
185+
d.SetId(fileSystemId + FILED_SP + helper.UInt64ToStr(*lifeCycleRule.LifeCycleRuleId))
177186

178187
return resourceTencentCloudChdfsLifeCycleRuleRead(d, meta)
179188
}
@@ -239,7 +248,7 @@ func resourceTencentCloudChdfsLifeCycleRuleRead(d *schema.ResourceData, meta int
239248
transitionsList = append(transitionsList, transitionsMap)
240249
}
241250

242-
lifeCycleRuleMap["transitions"] = []interface{}{transitionsList}
251+
lifeCycleRuleMap["transitions"] = transitionsList
243252
}
244253

245254
if lifeCycleRule.Status != nil {

tencentcloud/resource_tc_chdfs_life_cycle_rule_test.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ func TestAccTencentCloudNeedFixChdfsLifeCycleRuleResource_basic(t *testing.T) {
1818
Config: testAccChdfsLifeCycleRule,
1919
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_chdfs_life_cycle_rule.life_cycle_rule", "id")),
2020
},
21+
{
22+
Config: testAccChdfsLifeCycleRuleUpdate,
23+
Check: resource.ComposeTestCheckFunc(
24+
resource.TestCheckResourceAttrSet("tencentcloud_chdfs_life_cycle_rule.life_cycle_rule", "id"),
25+
resource.TestCheckResourceAttr("tencentcloud_chdfs_life_cycle_rule.life_cycle_rule", "life_cycle_rule.0.life_cycle_rule_name", "terraform-for-test"),
26+
resource.TestCheckResourceAttr("tencentcloud_chdfs_life_cycle_rule.life_cycle_rule", "life_cycle_rule.0.path", "/terraform"),
27+
resource.TestCheckResourceAttr("tencentcloud_chdfs_life_cycle_rule.life_cycle_rule", "life_cycle_rule.0.status", "2"),
28+
),
29+
},
2130
{
2231
ResourceName: "tencentcloud_chdfs_life_cycle_rule.life_cycle_rule",
2332
ImportState: true,
@@ -30,15 +39,36 @@ func TestAccTencentCloudNeedFixChdfsLifeCycleRuleResource_basic(t *testing.T) {
3039
const testAccChdfsLifeCycleRule = `
3140
3241
resource "tencentcloud_chdfs_life_cycle_rule" "life_cycle_rule" {
33-
file_system_id = "xxxx"
42+
file_system_id = "f14mpfy5lh4e"
43+
3444
life_cycle_rule {
35-
life_cycle_rule_name = "test"
36-
path = "/"
45+
life_cycle_rule_name = "terraform-test"
46+
path = "/test"
47+
status = 1
48+
3749
transitions {
38-
days = 1
50+
days = 30
51+
type = 1
52+
}
53+
}
54+
}
55+
56+
`
57+
58+
const testAccChdfsLifeCycleRuleUpdate = `
59+
60+
resource "tencentcloud_chdfs_life_cycle_rule" "life_cycle_rule" {
61+
file_system_id = "f14mpfy5lh4e"
62+
63+
life_cycle_rule {
64+
life_cycle_rule_name = "terraform-for-test"
65+
path = "/terraform"
66+
status = 2
67+
68+
transitions {
69+
days = 30
3970
type = 1
4071
}
41-
status = 1
4272
}
4373
}
4474

tencentcloud/service_tencentcloud_chdfs.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,40 @@ func (me *ChdfsService) DescribeChdfsLifeCycleRuleById(ctx context.Context, file
228228
return
229229
}
230230

231+
func (me *ChdfsService) DescribeChdfsLifeCycleRuleByPath(ctx context.Context, fileSystemId string, path string) (lifeCycleRule *chdfs.LifeCycleRule, errRet error) {
232+
logId := getLogId(ctx)
233+
234+
request := chdfs.NewDescribeLifeCycleRulesRequest()
235+
request.FileSystemId = &fileSystemId
236+
237+
defer func() {
238+
if errRet != nil {
239+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
240+
}
241+
}()
242+
243+
ratelimit.Check(request.GetAction())
244+
245+
response, err := me.client.UseChdfsClient().DescribeLifeCycleRules(request)
246+
if err != nil {
247+
errRet = err
248+
return
249+
}
250+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
251+
252+
if len(response.Response.LifeCycleRules) < 1 {
253+
return
254+
}
255+
256+
for _, rule := range response.Response.LifeCycleRules {
257+
if *rule.Path == path {
258+
lifeCycleRule = rule
259+
break
260+
}
261+
}
262+
return
263+
}
264+
231265
func (me *ChdfsService) DeleteChdfsLifeCycleRuleById(ctx context.Context, lifeCycleRuleId string) (errRet error) {
232266
logId := getLogId(ctx)
233267

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
subcategory: "Cloud HDFS(CHDFS)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_chdfs_life_cycle_rule"
5+
sidebar_current: "docs-tencentcloud-resource-chdfs_life_cycle_rule"
6+
description: |-
7+
Provides a resource to create a chdfs life_cycle_rule
8+
---
9+
10+
# tencentcloud_chdfs_life_cycle_rule
11+
12+
Provides a resource to create a chdfs life_cycle_rule
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_chdfs_life_cycle_rule" "life_cycle_rule" {
18+
file_system_id = "f14mpfy5lh4e"
19+
20+
life_cycle_rule {
21+
life_cycle_rule_name = "terraform-test"
22+
path = "/test"
23+
status = 1
24+
25+
transitions {
26+
days = 30
27+
type = 1
28+
}
29+
}
30+
}
31+
```
32+
33+
## Argument Reference
34+
35+
The following arguments are supported:
36+
37+
* `file_system_id` - (Required, String) file system id.
38+
* `life_cycle_rule` - (Required, List) life cycle rule.
39+
40+
The `life_cycle_rule` object supports the following:
41+
42+
* `life_cycle_rule_name` - (Optional, String) rule name.
43+
* `path` - (Optional, String) rule op path.
44+
* `status` - (Optional, Int) rule status, 1:open, 2:close.
45+
* `transitions` - (Optional, List) life cycle rule transition list.
46+
47+
The `transitions` object supports the following:
48+
49+
* `days` - (Required, Int) trigger days(n day).
50+
* `type` - (Required, Int) transition type, 1: archive, 2: delete, 3: low rate.
51+
52+
## Attributes Reference
53+
54+
In addition to all arguments above, the following attributes are exported:
55+
56+
* `id` - ID of the resource.
57+
58+
59+
60+
## Import
61+
62+
chdfs life_cycle_rule can be imported using the id, e.g.
63+
64+
```
65+
terraform import tencentcloud_chdfs_life_cycle_rule.life_cycle_rule file_system_id#life_cycle_rule_id
66+
```
67+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@
577577
<li>
578578
<a href="/docs/providers/tencentcloud/r/chdfs_file_system.html">tencentcloud_chdfs_file_system</a>
579579
</li>
580+
<li>
581+
<a href="/docs/providers/tencentcloud/r/chdfs_life_cycle_rule.html">tencentcloud_chdfs_life_cycle_rule</a>
582+
</li>
580583
</ul>
581584
</li>
582585
</ul>

0 commit comments

Comments
 (0)