From 97ce92cb47470165f5801b057fc686c28b354932 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 12 Nov 2024 19:37:50 +0800 Subject: [PATCH 1/2] add --- .../services/cbs/resource_tc_cbs_storage.go | 71 ++++++++++++++++++- .../services/cbs/resource_tc_cbs_storage.md | 23 ++++++ website/docs/r/cbs_storage.html.markdown | 30 ++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/tencentcloud/services/cbs/resource_tc_cbs_storage.go b/tencentcloud/services/cbs/resource_tc_cbs_storage.go index 1cce1a47aa..632341f5d0 100644 --- a/tencentcloud/services/cbs/resource_tc_cbs_storage.go +++ b/tencentcloud/services/cbs/resource_tc_cbs_storage.go @@ -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" @@ -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, + 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, @@ -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)) @@ -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{ @@ -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) + } + // must wait for finishing creating disk err = resource.Retry(10*tccommon.ReadRetryTimeout, func() *resource.RetryError { storage, e := cbsService.DescribeDiskById(ctx, storageId) @@ -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 { diff --git a/tencentcloud/services/cbs/resource_tc_cbs_storage.md b/tencentcloud/services/cbs/resource_tc_cbs_storage.md index be1731cfbe..d46064d7ab 100644 --- a/tencentcloud/services/cbs/resource_tc_cbs_storage.md +++ b/tencentcloud/services/cbs/resource_tc_cbs_storage.md @@ -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 diff --git a/website/docs/r/cbs_storage.html.markdown b/website/docs/r/cbs_storage.html.markdown index 2f860a0205..02cea8a393 100644 --- a/website/docs/r/cbs_storage.html.markdown +++ b/website/docs/r/cbs_storage.html.markdown @@ -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 @@ -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. @@ -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: From 022277ada250a540861a9893427fb3f3a68eee32 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 12 Nov 2024 19:39:35 +0800 Subject: [PATCH 2/2] add --- .changelog/2954.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2954.txt diff --git a/.changelog/2954.txt b/.changelog/2954.txt new file mode 100644 index 0000000000..dca6c86e39 --- /dev/null +++ b/.changelog/2954.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_cbs_storage: add `auto_mount_configuration` params +``` \ No newline at end of file
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: