Skip to content

Commit 2c4a42f

Browse files
tongyimingmikatong
andauthored
support chc (#1669)
* support chc * add changelog * merge chc config resource * update changelog --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 6ce83e8 commit 2c4a42f

16 files changed

+2000
-0
lines changed

.changelog/1669.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:new-data-source
2+
tencentcloud_cvm_chc_hosts
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_cvm_chc_denied_actions
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_cvm_chc_config
11+
```
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
Use this data source to query detailed information of cvm chc_denied_actions
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_cvm_chc_denied_actions" "chc_denied_actions" {
8+
chc_ids = ["chc-xxxxx"]
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
19+
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
20+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
21+
)
22+
23+
func dataSourceTencentCloudCvmChcDeniedActions() *schema.Resource {
24+
return &schema.Resource{
25+
Read: dataSourceTencentCloudCvmChcDeniedActionsRead,
26+
Schema: map[string]*schema.Schema{
27+
"chc_ids": {
28+
Required: true,
29+
Type: schema.TypeSet,
30+
Elem: &schema.Schema{
31+
Type: schema.TypeString,
32+
},
33+
Description: "CHC host IDs.",
34+
},
35+
36+
"chc_host_denied_action_set": {
37+
Computed: true,
38+
Type: schema.TypeList,
39+
Description: "Actions not allowed for the CHC instance.",
40+
Elem: &schema.Resource{
41+
Schema: map[string]*schema.Schema{
42+
"chc_id": {
43+
Type: schema.TypeString,
44+
Computed: true,
45+
Description: "CHC instance ID.",
46+
},
47+
"state": {
48+
Type: schema.TypeString,
49+
Computed: true,
50+
Description: "CHC instance status.",
51+
},
52+
"deny_actions": {
53+
Type: schema.TypeSet,
54+
Elem: &schema.Schema{
55+
Type: schema.TypeString,
56+
},
57+
Computed: true,
58+
Description: "Actions not allowed for the current CHC instance.",
59+
},
60+
},
61+
},
62+
},
63+
64+
"result_output_file": {
65+
Type: schema.TypeString,
66+
Optional: true,
67+
Description: "Used to save results.",
68+
},
69+
},
70+
}
71+
}
72+
73+
func dataSourceTencentCloudCvmChcDeniedActionsRead(d *schema.ResourceData, meta interface{}) error {
74+
defer logElapsed("data_source.tencentcloud_cvm_chc_denied_actions.read")()
75+
defer inconsistentCheck(d, meta)()
76+
77+
logId := getLogId(contextNil)
78+
79+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
80+
81+
paramMap := make(map[string]interface{})
82+
if v, ok := d.GetOk("chc_ids"); ok {
83+
chcIdsSet := v.(*schema.Set).List()
84+
paramMap["chc_ids"] = helper.InterfacesStrings(chcIdsSet)
85+
}
86+
87+
service := CvmService{client: meta.(*TencentCloudClient).apiV3Conn}
88+
89+
var chcHostDeniedActionSet []*cvm.ChcHostDeniedActions
90+
91+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
92+
result, e := service.DescribeCvmChcDeniedActionsByFilter(ctx, paramMap)
93+
if e != nil {
94+
return retryError(e)
95+
}
96+
chcHostDeniedActionSet = result
97+
return nil
98+
})
99+
if err != nil {
100+
return err
101+
}
102+
103+
ids := make([]string, 0, len(chcHostDeniedActionSet))
104+
tmpList := make([]map[string]interface{}, 0, len(chcHostDeniedActionSet))
105+
106+
if len(chcHostDeniedActionSet) > 0 {
107+
for _, chcHostDeniedActions := range chcHostDeniedActionSet {
108+
chcHostDeniedActionsMap := map[string]interface{}{}
109+
110+
if chcHostDeniedActions.ChcId != nil {
111+
chcHostDeniedActionsMap["chc_id"] = chcHostDeniedActions.ChcId
112+
}
113+
114+
if chcHostDeniedActions.State != nil {
115+
chcHostDeniedActionsMap["state"] = chcHostDeniedActions.State
116+
}
117+
118+
if chcHostDeniedActions.DenyActions != nil {
119+
chcHostDeniedActionsMap["deny_actions"] = chcHostDeniedActions.DenyActions
120+
}
121+
122+
ids = append(ids, *chcHostDeniedActions.ChcId)
123+
tmpList = append(tmpList, chcHostDeniedActionsMap)
124+
}
125+
126+
_ = d.Set("chc_host_denied_action_set", tmpList)
127+
}
128+
129+
d.SetId(helper.DataResourceIdsHash(ids))
130+
output, ok := d.GetOk("result_output_file")
131+
if ok && output.(string) != "" {
132+
if e := writeToFile(output.(string), tmpList); e != nil {
133+
return e
134+
}
135+
}
136+
return nil
137+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudCvmChcDeniedActionsDataSource_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: testAccCvmChcDeniedActionsDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_cvm_chc_denied_actions.chc_denied_actions")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccCvmChcDeniedActionsDataSource = `
26+
27+
data "tencentcloud_cvm_chc_denied_actions" "chc_denied_actions" {
28+
chc_ids = ["chc-0brmw3wl"]
29+
}
30+
`

0 commit comments

Comments
 (0)