Skip to content

Commit 97ce92c

Browse files
committed
add
1 parent 52ce1d6 commit 97ce92c

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

tencentcloud/services/cbs/resource_tc_cbs_storage.go

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"time"
78

89
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
910
svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag"
@@ -124,6 +125,34 @@ func ResourceTencentCloudCbsStorage() *schema.Resource {
124125
Computed: true,
125126
Description: "The quota of backup points of cloud disk.",
126127
},
128+
"auto_mount_configuration": {
129+
Type: schema.TypeList,
130+
Optional: true,
131+
ForceNew: true,
132+
MaxItems: 1,
133+
Description: "Specifies whether to automatically attach and initialize the newly created data disk.",
134+
Elem: &schema.Resource{
135+
Schema: map[string]*schema.Schema{
136+
"instance_id": {
137+
Type: schema.TypeSet,
138+
Required: true,
139+
Description: "ID of the instance to which the cloud disk is attached.",
140+
Elem: &schema.Schema{Type: schema.TypeString},
141+
},
142+
"mount_point": {
143+
Type: schema.TypeSet,
144+
Optional: true,
145+
Description: "Mount point in the instance.",
146+
Elem: &schema.Schema{Type: schema.TypeString},
147+
},
148+
"file_system_type": {
149+
Type: schema.TypeString,
150+
Optional: true,
151+
Description: "File system type. Valid values: ext4, xfs.",
152+
},
153+
},
154+
},
155+
},
127156
// computed
128157
"storage_status": {
129158
Type: schema.TypeString,
@@ -147,6 +176,7 @@ func resourceTencentCloudCbsStorageCreate(d *schema.ResourceData, meta interface
147176
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
148177
cbsService = CbsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
149178
request = cbs.NewCreateDisksRequest()
179+
autoMount bool
150180
)
151181

152182
request.DiskName = helper.String(d.Get("storage_name").(string))
@@ -195,6 +225,32 @@ func resourceTencentCloudCbsStorageCreate(d *schema.ResourceData, meta interface
195225
}
196226
}
197227

228+
if dMap, ok := helper.InterfacesHeadMap(d, "auto_mount_configuration"); ok {
229+
autoMountConfiguration := cbs.AutoMountConfiguration{}
230+
if v, ok := dMap["instance_id"]; ok {
231+
instanceId := v.(*schema.Set).List()
232+
for i := range instanceId {
233+
insId := instanceId[i].(string)
234+
autoMountConfiguration.InstanceId = append(autoMountConfiguration.InstanceId, helper.String(insId))
235+
}
236+
}
237+
238+
if v, ok := dMap["mount_point"]; ok {
239+
mountPoint := v.(*schema.Set).List()
240+
for i := range mountPoint {
241+
mpId := mountPoint[i].(string)
242+
autoMountConfiguration.MountPoint = append(autoMountConfiguration.MountPoint, helper.String(mpId))
243+
}
244+
}
245+
246+
if v, ok := dMap["file_system_type"]; ok {
247+
autoMountConfiguration.FileSystemType = helper.String(v.(string))
248+
}
249+
250+
request.AutoMountConfiguration = &autoMountConfiguration
251+
autoMount = true
252+
}
253+
198254
if v := helper.GetTags(d, "tags"); len(v) > 0 {
199255
for tagKey, tagValue := range v {
200256
tag := cbs.Tag{
@@ -246,6 +302,11 @@ func resourceTencentCloudCbsStorageCreate(d *schema.ResourceData, meta interface
246302
}
247303
}
248304

305+
if autoMount {
306+
// Skip the initial UNATTACHED state of the CBS
307+
time.Sleep(10 * time.Second)
308+
}
309+
249310
// must wait for finishing creating disk
250311
err = resource.Retry(10*tccommon.ReadRetryTimeout, func() *resource.RetryError {
251312
storage, e := cbsService.DescribeDiskById(ctx, storageId)
@@ -257,7 +318,15 @@ func resourceTencentCloudCbsStorageCreate(d *schema.ResourceData, meta interface
257318
return resource.RetryableError(fmt.Errorf("storage is still creating..."))
258319
}
259320

260-
return nil
321+
if *storage.DiskState == "ATTACHING" {
322+
return resource.RetryableError(fmt.Errorf("storage is still attaching..."))
323+
}
324+
325+
if *storage.DiskState == "ATTACHED" || *storage.DiskState == "UNATTACHED" {
326+
return nil
327+
}
328+
329+
return resource.RetryableError(fmt.Errorf("storage is still creating..."))
261330
})
262331

263332
if err != nil {

tencentcloud/services/cbs/resource_tc_cbs_storage.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ resource "tencentcloud_cbs_storage" "example" {
1919
}
2020
```
2121

22+
Create a CBS storage with auto mount instance
23+
24+
```hcl
25+
resource "tencentcloud_cbs_storage" "example" {
26+
storage_name = "tf-example"
27+
storage_type = "CLOUD_SSD"
28+
storage_size = 100
29+
availability_zone = "ap-guangzhou-4"
30+
project_id = 0
31+
encrypt = false
32+
33+
auto_mount_configuration {
34+
instance_id = ["ins-ett39bv2"]
35+
mount_point = ["/mnt/datadisk0"]
36+
file_system_type = "ext4"
37+
}
38+
39+
tags = {
40+
createBy = "terraform"
41+
}
42+
}
43+
```
44+
2245
Create a dedicated cluster CBS storage
2346

2447
```hcl

website/docs/r/cbs_storage.html.markdown

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ resource "tencentcloud_cbs_storage" "example" {
3030
}
3131
```
3232

33+
### Create a CBS storage with auto mount instance
34+
35+
```hcl
36+
resource "tencentcloud_cbs_storage" "example" {
37+
storage_name = "tf-example"
38+
storage_type = "CLOUD_SSD"
39+
storage_size = 100
40+
availability_zone = "ap-guangzhou-4"
41+
project_id = 0
42+
encrypt = false
43+
44+
auto_mount_configuration {
45+
instance_id = ["ins-ett39bv2"]
46+
mount_point = ["/mnt/datadisk0"]
47+
file_system_type = "ext4"
48+
}
49+
50+
tags = {
51+
createBy = "terraform"
52+
}
53+
}
54+
```
55+
3356
### Create a dedicated cluster CBS storage
3457

3558
```hcl
@@ -57,6 +80,7 @@ The following arguments are supported:
5780
* `storage_name` - (Required, String) Name of CBS. The maximum length can not exceed 60 bytes.
5881
* `storage_size` - (Required, Int) Volume of CBS, and unit is GB.
5982
* `storage_type` - (Required, String, ForceNew) Type of CBS medium. Valid values: CLOUD_BASIC: HDD cloud disk, CLOUD_PREMIUM: Premium Cloud Storage, CLOUD_BSSD: General Purpose SSD, CLOUD_SSD: SSD, CLOUD_HSSD: Enhanced SSD, CLOUD_TSSD: Tremendous SSD.
83+
* `auto_mount_configuration` - (Optional, List, ForceNew) Specifies whether to automatically attach and initialize the newly created data disk.
6084
* `charge_type` - (Optional, String) The charge type of CBS instance. Valid values are `PREPAID`, `POSTPAID_BY_HOUR`, `CDCPAID` and `DEDICATED_CLUSTER_PAID`. The default is `POSTPAID_BY_HOUR`.
6185
* `dedicated_cluster_id` - (Optional, String, ForceNew) Exclusive cluster id.
6286
* `disk_backup_quota` - (Optional, Int) The quota of backup points of cloud disk.
@@ -70,6 +94,12 @@ The following arguments are supported:
7094
* `tags` - (Optional, Map) The available tags within this CBS.
7195
* `throughput_performance` - (Optional, Int) Add extra performance to the data disk. Only works when disk type is `CLOUD_TSSD` or `CLOUD_HSSD`.
7296

97+
The `auto_mount_configuration` object supports the following:
98+
99+
* `instance_id` - (Required, Set) ID of the instance to which the cloud disk is attached.
100+
* `file_system_type` - (Optional, String) File system type. Valid values: ext4, xfs.
101+
* `mount_point` - (Optional, Set) Mount point in the instance.
102+
73103
## Attributes Reference
74104

75105
In addition to all arguments above, the following attributes are exported:

0 commit comments

Comments
 (0)