Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cbs): [119747862] tencentcloud_cbs_storage add auto_mount_configuration params #2954

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2954.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cbs_storage: add `auto_mount_configuration` params
```
71 changes: 70 additions & 1 deletion tencentcloud/services/cbs/resource_tc_cbs_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"time"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag"
Expand Down Expand Up @@ -124,6 +125,34 @@ func ResourceTencentCloudCbsStorage() *schema.Resource {
Computed: true,
Description: "The quota of backup points of cloud disk.",
},
"auto_mount_configuration": {
Type: schema.TypeList,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只支持创建,不支持读取么

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该参数mount_point和file_system_type是无返回的,单纯返回insId意义不大,并且该功能是一次性设置所以我没设置read

Optional: true,
ForceNew: true,
MaxItems: 1,
Description: "Specifies whether to automatically attach and initialize the newly created data disk.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"instance_id": {
Type: schema.TypeSet,
Required: true,
Description: "ID of the instance to which the cloud disk is attached.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"mount_point": {
Type: schema.TypeSet,
Optional: true,
Description: "Mount point in the instance.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"file_system_type": {
Type: schema.TypeString,
Optional: true,
Description: "File system type. Valid values: ext4, xfs.",
},
},
},
},
// computed
"storage_status": {
Type: schema.TypeString,
Expand All @@ -147,6 +176,7 @@ func resourceTencentCloudCbsStorageCreate(d *schema.ResourceData, meta interface
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
cbsService = CbsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
request = cbs.NewCreateDisksRequest()
autoMount bool
)

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

if dMap, ok := helper.InterfacesHeadMap(d, "auto_mount_configuration"); ok {
autoMountConfiguration := cbs.AutoMountConfiguration{}
if v, ok := dMap["instance_id"]; ok {
instanceId := v.(*schema.Set).List()
for i := range instanceId {
insId := instanceId[i].(string)
autoMountConfiguration.InstanceId = append(autoMountConfiguration.InstanceId, helper.String(insId))
}
}

if v, ok := dMap["mount_point"]; ok {
mountPoint := v.(*schema.Set).List()
for i := range mountPoint {
mpId := mountPoint[i].(string)
autoMountConfiguration.MountPoint = append(autoMountConfiguration.MountPoint, helper.String(mpId))
}
}

if v, ok := dMap["file_system_type"]; ok {
autoMountConfiguration.FileSystemType = helper.String(v.(string))
}

request.AutoMountConfiguration = &autoMountConfiguration
autoMount = true
}

if v := helper.GetTags(d, "tags"); len(v) > 0 {
for tagKey, tagValue := range v {
tag := cbs.Tag{
Expand Down Expand Up @@ -246,6 +302,11 @@ func resourceTencentCloudCbsStorageCreate(d *schema.ResourceData, meta interface
}
}

if autoMount {
// Skip the initial UNATTACHED state of the CBS
time.Sleep(10 * time.Second)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep这么久?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自动挂载磁盘操作大概是3、5分钟
sleep10秒是为了100%跳过磁盘刚创建好 默认待挂载的状态
这里是有判断的sleep,整体不会影响挂载的过程

}

// must wait for finishing creating disk
err = resource.Retry(10*tccommon.ReadRetryTimeout, func() *resource.RetryError {
storage, e := cbsService.DescribeDiskById(ctx, storageId)
Expand All @@ -257,7 +318,15 @@ func resourceTencentCloudCbsStorageCreate(d *schema.ResourceData, meta interface
return resource.RetryableError(fmt.Errorf("storage is still creating..."))
}

return nil
if *storage.DiskState == "ATTACHING" {
return resource.RetryableError(fmt.Errorf("storage is still attaching..."))
}

if *storage.DiskState == "ATTACHED" || *storage.DiskState == "UNATTACHED" {
return nil
}

return resource.RetryableError(fmt.Errorf("storage is still creating..."))
})

if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions tencentcloud/services/cbs/resource_tc_cbs_storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ resource "tencentcloud_cbs_storage" "example" {
}
```

Create a CBS storage with auto mount instance

```hcl
resource "tencentcloud_cbs_storage" "example" {
storage_name = "tf-example"
storage_type = "CLOUD_SSD"
storage_size = 100
availability_zone = "ap-guangzhou-4"
project_id = 0
encrypt = false

auto_mount_configuration {
instance_id = ["ins-ett39bv2"]
mount_point = ["/mnt/datadisk0"]
file_system_type = "ext4"
}

tags = {
createBy = "terraform"
}
}
```

Create a dedicated cluster CBS storage

```hcl
Expand Down
30 changes: 30 additions & 0 deletions website/docs/r/cbs_storage.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ resource "tencentcloud_cbs_storage" "example" {
}
```

### Create a CBS storage with auto mount instance

```hcl
resource "tencentcloud_cbs_storage" "example" {
storage_name = "tf-example"
storage_type = "CLOUD_SSD"
storage_size = 100
availability_zone = "ap-guangzhou-4"
project_id = 0
encrypt = false

auto_mount_configuration {
instance_id = ["ins-ett39bv2"]
mount_point = ["/mnt/datadisk0"]
file_system_type = "ext4"
}

tags = {
createBy = "terraform"
}
}
```

### Create a dedicated cluster CBS storage

```hcl
Expand Down Expand Up @@ -57,6 +80,7 @@ The following arguments are supported:
* `storage_name` - (Required, String) Name of CBS. The maximum length can not exceed 60 bytes.
* `storage_size` - (Required, Int) Volume of CBS, and unit is GB.
* `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.
* `auto_mount_configuration` - (Optional, List, ForceNew) Specifies whether to automatically attach and initialize the newly created data disk.
* `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`.
* `dedicated_cluster_id` - (Optional, String, ForceNew) Exclusive cluster id.
* `disk_backup_quota` - (Optional, Int) The quota of backup points of cloud disk.
Expand All @@ -70,6 +94,12 @@ The following arguments are supported:
* `tags` - (Optional, Map) The available tags within this CBS.
* `throughput_performance` - (Optional, Int) Add extra performance to the data disk. Only works when disk type is `CLOUD_TSSD` or `CLOUD_HSSD`.

The `auto_mount_configuration` object supports the following:

* `instance_id` - (Required, Set) ID of the instance to which the cloud disk is attached.
* `file_system_type` - (Optional, String) File system type. Valid values: ext4, xfs.
* `mount_point` - (Optional, Set) Mount point in the instance.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down
Loading