-
Notifications
You must be signed in to change notification settings - Fork 136
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
SevenEarth
wants to merge
2
commits into
master
Choose a base branch
from
fix/cbs_attach
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sleep这么久? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 自动挂载磁盘操作大概是3、5分钟 |
||
} | ||
|
||
// 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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只支持创建,不支持读取么
There was a problem hiding this comment.
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