Skip to content

Commit 8fe5c25

Browse files
authored
feat(bh): [116578841] Add Dasb resource (#2566)
* add * add * add * add * add * fix/bh
1 parent de8bb0f commit 8fe5c25

9 files changed

+263
-78
lines changed

.changelog/2566.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_dasb_resource
3+
```

tencentcloud/provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,7 @@ Cloud Firewall(CFW)
20802080

20812081
Bastion Host(BH)
20822082
Resource
2083+
tencentcloud_dasb_resource
20832084
tencentcloud_dasb_acl
20842085
tencentcloud_dasb_cmd_template
20852086
tencentcloud_dasb_device_group

tencentcloud/services/bh/resource_tc_dasb_acl.md

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,39 @@ Provides a resource to create a dasb acl
33
Example Usage
44

55
```hcl
6+
resource "tencentcloud_dasb_user" "example" {
7+
user_name = "tf_example"
8+
real_name = "terraform"
9+
phone = "+86|18345678782"
10+
11+
auth_type = 0
12+
}
13+
14+
resource "tencentcloud_dasb_user_group" "example" {
15+
name = "tf_example"
16+
}
17+
18+
resource "tencentcloud_dasb_device" "example" {
19+
os_name = "Linux"
20+
ip = "192.168.0.1"
21+
port = 80
22+
name = "tf_example"
23+
}
24+
25+
resource "tencentcloud_dasb_device_group" "example" {
26+
name = "tf_example"
27+
}
28+
29+
resource "tencentcloud_dasb_device_account" "example" {
30+
device_id = tencentcloud_dasb_device.example.id
31+
account = "root"
32+
}
33+
34+
resource "tencentcloud_dasb_cmd_template" "example" {
35+
name = "tf_example"
36+
cmd_list = "rm -rf*"
37+
}
38+
639
resource "tencentcloud_dasb_acl" "example" {
740
name = "tf_example"
841
allow_disk_redirect = true
@@ -15,22 +48,19 @@ resource "tencentcloud_dasb_acl" "example" {
1548
allow_file_down = true
1649
max_file_up_size = 0
1750
max_file_down_size = 0
18-
user_id_set = ["6", "2"]
19-
user_group_id_set = ["6", "36"]
20-
device_id_set = ["39", "81"]
21-
device_group_id_set = ["2", "3"]
22-
account_set = ["root"]
23-
cmd_template_id_set = ["1", "7"]
51+
user_id_set = [tencentcloud_dasb_user.example.id]
52+
user_group_id_set = [tencentcloud_dasb_user_group.example.id]
53+
device_id_set = [tencentcloud_dasb_device.example.id]
54+
device_group_id_set = [tencentcloud_dasb_device_group.example.id]
55+
account_set = [tencentcloud_dasb_device_account.example.id]
56+
cmd_template_id_set = [tencentcloud_dasb_cmd_template.example.id]
2457
ac_template_id_set = []
2558
allow_disk_file_up = true
2659
allow_disk_file_down = true
2760
allow_shell_file_up = true
2861
allow_shell_file_down = true
2962
allow_file_del = true
3063
allow_access_credential = true
31-
department_id = "1.2"
32-
validate_from = "2023-09-22T00:00:00+08:00"
33-
validate_to = "2024-09-23T00:00:00+08:00"
3464
}
3565
```
3666

tencentcloud/services/bh/resource_tc_dasb_resource.go

Lines changed: 99 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,14 @@ func ResourceTencentCloudDasbResource() *schema.Resource {
5252
Description: "Number of resource nodes.",
5353
},
5454
"time_unit": {
55-
Required: true,
56-
Type: schema.TypeString,
57-
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"m"}),
58-
Description: "Billing cycle, only support m: month.",
55+
Optional: true,
56+
Type: schema.TypeString,
57+
Description: "Billing cycle, only support m: month. This field is mandatory, fill in m.",
5958
},
6059
"time_span": {
61-
Required: true,
62-
Type: schema.TypeInt,
63-
ValidateFunc: tccommon.ValidateIntegerMin(1),
64-
Description: "Billing time.",
60+
Optional: true,
61+
Type: schema.TypeInt,
62+
Description: "Billing time. This field is mandatory, with a minimum value of 1.",
6563
},
6664
"auto_renew_flag": {
6765
Required: true,
@@ -70,22 +68,32 @@ func ResourceTencentCloudDasbResource() *schema.Resource {
7068
Description: "Automatic renewal. 1 is auto renew flag, 0 is not.",
7169
},
7270
"deploy_zone": {
73-
Optional: true,
71+
Required: true,
7472
Type: schema.TypeString,
7573
Description: "Deploy zone.",
7674
},
77-
"package_bandwidth": {
78-
Optional: true,
79-
Computed: true,
80-
Type: schema.TypeInt,
81-
Description: "Number of bandwidth expansion packets (4M).",
75+
"cidr_block": {
76+
Required: true,
77+
Type: schema.TypeString,
78+
Description: "Subnet segments that require service activation.",
79+
},
80+
"vpc_cidr_block": {
81+
Required: true,
82+
Type: schema.TypeString,
83+
Description: "The network segment corresponding to the VPC that requires service activation.",
8284
},
83-
"package_node": {
85+
"package_bandwidth": {
8486
Optional: true,
8587
Computed: true,
8688
Type: schema.TypeInt,
87-
Description: "Number of authorized point extension packages (50 points).",
89+
Description: "Number of bandwidth expansion packets (4M), The set value is an integer multiple of 4.",
8890
},
91+
//"package_node": {
92+
// Optional: true,
93+
// Computed: true,
94+
// Type: schema.TypeInt,
95+
// Description: "Number of authorized point extension packages (50 points). Cannot exceed 100.",
96+
//},
8997
},
9098
}
9199
}
@@ -98,21 +106,31 @@ func resourceTencentCloudDasbResourceCreate(d *schema.ResourceData, meta interfa
98106
logId = tccommon.GetLogId(tccommon.ContextNil)
99107
request = dasb.NewCreateResourceRequest()
100108
response = dasb.NewCreateResourceResponse()
109+
deployRequest = dasb.NewDeployResourceRequest()
101110
describeRequest = dasb.NewDescribeResourcesRequest()
102111
modifyRequest = dasb.NewModifyResourceRequest()
103112
resourceId string
113+
vpcId string
114+
subnetId string
115+
deployRegion string
116+
deployZone string
117+
cidrBlock string
118+
vpcCidrBlock string
104119
)
105120

106121
if v, ok := d.GetOk("deploy_region"); ok {
107122
request.DeployRegion = helper.String(v.(string))
123+
deployRegion = v.(string)
108124
}
109125

110126
if v, ok := d.GetOk("vpc_id"); ok {
111127
request.VpcId = helper.String(v.(string))
128+
vpcId = v.(string)
112129
}
113130

114131
if v, ok := d.GetOk("subnet_id"); ok {
115132
request.SubnetId = helper.String(v.(string))
133+
subnetId = v.(string)
116134
}
117135

118136
if v, ok := d.GetOk("resource_edition"); ok {
@@ -139,6 +157,15 @@ func resourceTencentCloudDasbResourceCreate(d *schema.ResourceData, meta interfa
139157

140158
if v, ok := d.GetOk("deploy_zone"); ok {
141159
request.DeployZone = helper.String(v.(string))
160+
deployZone = v.(string)
161+
}
162+
163+
if v, ok := d.GetOk("cidr_block"); ok {
164+
cidrBlock = v.(string)
165+
}
166+
167+
if v, ok := d.GetOk("vpc_cidr_block"); ok {
168+
vpcCidrBlock = v.(string)
142169
}
143170

144171
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
@@ -167,10 +194,38 @@ func resourceTencentCloudDasbResourceCreate(d *schema.ResourceData, meta interfa
167194
d.SetId(resourceId)
168195

169196
// deploy resource
197+
deployRequest.ResourceId = helper.String(resourceId)
198+
deployRequest.ApCode = helper.String(deployRegion)
199+
deployRequest.Zone = helper.String(deployZone)
200+
deployRequest.VpcId = helper.String(vpcId)
201+
deployRequest.SubnetId = helper.String(subnetId)
202+
deployRequest.CidrBlock = helper.String(cidrBlock)
203+
deployRequest.VpcCidrBlock = helper.String(vpcCidrBlock)
204+
205+
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
206+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseDasbClient().DeployResource(deployRequest)
207+
if e != nil {
208+
return tccommon.RetryError(e)
209+
} else {
210+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, deployRequest.GetAction(), deployRequest.ToJsonString(), deployRequest.ToJsonString())
211+
}
212+
213+
if result == nil {
214+
e = fmt.Errorf("dasb Resource deploy error")
215+
return resource.NonRetryableError(e)
216+
}
217+
218+
return nil
219+
})
220+
221+
if err != nil {
222+
log.Printf("[CRITAL]%s deploy dasb Resource failed, reason:%+v", logId, err)
223+
return err
224+
}
170225

171226
// wait
172227
describeRequest.ResourceIds = helper.Strings([]string{resourceId})
173-
err = resource.Retry(tccommon.WriteRetryTimeout*4, func() *resource.RetryError {
228+
err = resource.Retry(tccommon.WriteRetryTimeout*6, func() *resource.RetryError {
174229
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseDasbClient().DescribeResources(describeRequest)
175230
if e != nil {
176231
return tccommon.RetryError(e)
@@ -183,6 +238,11 @@ func resourceTencentCloudDasbResourceCreate(d *schema.ResourceData, meta interfa
183238
return resource.NonRetryableError(e)
184239
}
185240

241+
if *result.Response.ResourceSet[0].Status == 4 {
242+
e = fmt.Errorf("dasb Resource deploy error")
243+
return resource.NonRetryableError(e)
244+
}
245+
186246
if *result.Response.ResourceSet[0].Status == 1 {
187247
return nil
188248
}
@@ -195,15 +255,16 @@ func resourceTencentCloudDasbResourceCreate(d *schema.ResourceData, meta interfa
195255
return err
196256
}
197257

258+
// modify
198259
if v, ok := d.GetOkExists("package_bandwidth"); ok {
199260
modifyRequest.PackageBandwidth = helper.IntInt64(v.(int))
200261
}
201262

202-
if v, ok := d.GetOkExists("package_node"); ok {
203-
modifyRequest.PackageNode = helper.IntInt64(v.(int))
204-
}
263+
//if v, ok := d.GetOkExists("package_node"); ok {
264+
// modifyRequest.PackageNode = helper.IntInt64(v.(int))
265+
//}
205266

206-
if modifyRequest.PackageBandwidth != nil || modifyRequest.PackageNode != nil {
267+
if modifyRequest.PackageBandwidth != nil {
207268
modifyRequest.ResourceId = &resourceId
208269
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
209270
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseDasbClient().ModifyResource(modifyRequest)
@@ -284,13 +345,21 @@ func resourceTencentCloudDasbResourceRead(d *schema.ResourceData, meta interface
284345
_ = d.Set("deploy_zone", Resource.Zone)
285346
}
286347

348+
if Resource.CidrBlock != nil {
349+
_ = d.Set("cidr_block", Resource.CidrBlock)
350+
}
351+
352+
if Resource.VpcCidrBlock != nil {
353+
_ = d.Set("vpc_cidr_block", Resource.VpcCidrBlock)
354+
}
355+
287356
if Resource.PackageBandwidth != nil {
288357
_ = d.Set("package_bandwidth", Resource.PackageBandwidth)
289358
}
290359

291-
if Resource.PackageNode != nil {
292-
_ = d.Set("package_node", Resource.PackageNode)
293-
}
360+
//if Resource.PackageNode != nil {
361+
// _ = d.Set("package_node", Resource.PackageNode)
362+
//}
294363

295364
return nil
296365
}
@@ -305,7 +374,7 @@ func resourceTencentCloudDasbResourceUpdate(d *schema.ResourceData, meta interfa
305374
resourceId = d.Id()
306375
)
307376

308-
immutableArgs := []string{"deploy_region", "vpc_id", "subnet_id", "time_unit", "time_span", "pay_mode", "deploy_zone"}
377+
immutableArgs := []string{"deploy_region", "vpc_id", "subnet_id", "time_unit", "time_span", "pay_mode", "deploy_zone", "cidr_block", "vpc_cidr_block"}
309378

310379
for _, v := range immutableArgs {
311380
if d.HasChange(v) {
@@ -338,11 +407,11 @@ func resourceTencentCloudDasbResourceUpdate(d *schema.ResourceData, meta interfa
338407
}
339408
}
340409

341-
if d.HasChange("package_node") {
342-
if v, ok := d.GetOkExists("package_node"); ok {
343-
request.PackageNode = helper.IntInt64(v.(int))
344-
}
345-
}
410+
//if d.HasChange("package_node") {
411+
// if v, ok := d.GetOkExists("package_node"); ok {
412+
// request.PackageNode = helper.IntInt64(v.(int))
413+
// }
414+
//}
346415

347416
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
348417
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseDasbClient().ModifyResource(request)

tencentcloud/services/bh/resource_tc_dasb_resource.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,41 @@ Provides a resource to create a dasb resource
22

33
Example Usage
44

5+
Create a standard version instance
6+
57
```hcl
68
resource "tencentcloud_dasb_resource" "example" {
79
deploy_region = "ap-guangzhou"
10+
deploy_zone = "ap-guangzhou-6"
811
vpc_id = "vpc-fmz6l9nz"
912
subnet_id = "subnet-g7jhwhi2"
13+
vpc_cidr_block = "10.35.0.0/16"
14+
cidr_block = "10.35.20.0/24"
1015
resource_edition = "standard"
1116
resource_node = 50
1217
time_unit = "m"
1318
time_span = 1
1419
auto_renew_flag = 1
20+
package_bandwidth = 1
21+
}
22+
```
23+
24+
Create a professional instance
25+
26+
```hcl
27+
resource "tencentcloud_dasb_resource" "example" {
28+
deploy_region = "ap-guangzhou"
1529
deploy_zone = "ap-guangzhou-6"
16-
package_bandwidth = 10
17-
package_node = 50
30+
vpc_id = "vpc-fmz6l9nz"
31+
subnet_id = "subnet-g7jhwhi2"
32+
vpc_cidr_block = "10.35.0.0/16"
33+
cidr_block = "10.35.20.0/24"
34+
resource_edition = "pro"
35+
resource_node = 50
36+
time_unit = "m"
37+
time_span = 1
38+
auto_renew_flag = 1
39+
package_bandwidth = 1
1840
}
1941
```
2042

@@ -23,5 +45,5 @@ Import
2345
dasb resource can be imported using the id, e.g.
2446

2547
```
26-
terraform import tencentcloud_dasb_resource.example bh-saas-kk5rabk0
27-
```
48+
terraform import tencentcloud_dasb_resource.example bh-saas-kgckynrt
49+
```

0 commit comments

Comments
 (0)