Skip to content

Commit 2ebc873

Browse files
committed
add
1 parent b94fd6e commit 2ebc873

File tree

2 files changed

+110
-3
lines changed

2 files changed

+110
-3
lines changed

tencentcloud/services/cvm/resource_tc_instance.go

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ func ResourceTencentCloudInstance() *schema.Resource {
288288
ForceNew: true,
289289
Description: "Decides whether the disk is deleted with instance(only applied to `CLOUD_BASIC`, `CLOUD_SSD` and `CLOUD_PREMIUM` disk with `POSTPAID_BY_HOUR` instance), default is true.",
290290
},
291+
"delete_with_instance_prepaid": {
292+
Type: schema.TypeBool,
293+
Optional: true,
294+
Default: false,
295+
ForceNew: true,
296+
Description: "Decides whether the disk is deleted with instance(only applied to `CLOUD_BASIC`, `CLOUD_SSD` and `CLOUD_PREMIUM` disk with `PREPAID` instance), default is false.",
297+
},
291298
"encrypt": {
292299
Type: schema.TypeBool,
293300
Optional: true,
@@ -997,7 +1004,12 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
9971004
}
9981005
}
9991006

1000-
for _, disk := range instance.DataDisks {
1007+
tmpDataDisks := make([]interface{}, 0, len(instance.DataDisks))
1008+
if v, ok := d.GetOk("data_disks"); ok {
1009+
tmpDataDisks = v.([]interface{})
1010+
}
1011+
1012+
for index, disk := range instance.DataDisks {
10011013
dataDisk := make(map[string]interface{}, 5)
10021014
dataDisk["data_disk_id"] = disk.DiskId
10031015
if disk.DiskId == nil {
@@ -1006,6 +1018,15 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
10061018
dataDisk["data_disk_size"] = size
10071019
}
10081020

1021+
dataDisk["delete_with_instance_prepaid"] = false
1022+
if len(tmpDataDisks) == len(instance.DataDisks) {
1023+
tmpDataDisk := tmpDataDisks[index].(map[string]interface{})
1024+
if deleteWithInstancePrepaid, ok := tmpDataDisk["delete_with_instance_prepaid"]; ok {
1025+
deleteWithInstancePrepaidBool := deleteWithInstancePrepaid.(bool)
1026+
dataDisk["delete_with_instance_prepaid"] = deleteWithInstancePrepaidBool
1027+
}
1028+
}
1029+
10091030
dataDisk["data_disk_type"] = disk.DiskType
10101031
dataDisk["data_disk_snapshot_id"] = disk.SnapshotId
10111032
dataDisk["delete_with_instance"] = disk.DeleteWithInstance
@@ -1616,8 +1637,8 @@ func resourceTencentCloudInstanceDelete(d *schema.ResourceData, meta interface{}
16161637
for _, d := range dataDisks {
16171638
value := d.(map[string]interface{})
16181639
diskId := value["data_disk_id"].(string)
1619-
deleteWithInstance := value["delete_with_instance"].(bool)
1620-
if deleteWithInstance {
1640+
deleteWithInstancePrepaid := value["delete_with_instance_prepaid"].(bool)
1641+
if deleteWithInstancePrepaid {
16211642
cbsService := svccbs.NewCbsService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
16221643
err := resource.Retry(tccommon.ReadRetryTimeout*2, func() *resource.RetryError {
16231644
diskInfo, e := cbsService.DescribeDiskById(ctx, diskId)
@@ -1759,6 +1780,91 @@ func resourceTencentCloudInstanceDelete(d *schema.ResourceData, meta interface{}
17591780
diskId := value["data_disk_id"].(string)
17601781
deleteWithInstance := value["delete_with_instance"].(bool)
17611782
if deleteWithInstance {
1783+
cbsService := svccbs.NewCbsService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
1784+
err := resource.Retry(tccommon.ReadRetryTimeout*2, func() *resource.RetryError {
1785+
diskInfo, e := cbsService.DescribeDiskById(ctx, diskId)
1786+
if e != nil {
1787+
return tccommon.RetryError(e, tccommon.InternalError)
1788+
}
1789+
1790+
if *diskInfo.DiskState != svccbs.CBS_STORAGE_STATUS_UNATTACHED {
1791+
return resource.RetryableError(fmt.Errorf("cbs storage status is %s", *diskInfo.DiskState))
1792+
}
1793+
1794+
return nil
1795+
})
1796+
1797+
if err != nil {
1798+
log.Printf("[CRITAL]%s delete cbs failed, reason:%s\n ", logId, err.Error())
1799+
return err
1800+
}
1801+
1802+
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
1803+
e := cbsService.DeleteDiskById(ctx, diskId)
1804+
if e != nil {
1805+
return tccommon.RetryError(e, tccommon.InternalError)
1806+
}
1807+
1808+
return nil
1809+
})
1810+
1811+
if err != nil {
1812+
log.Printf("[CRITAL]%s delete cbs failed, reason:%s\n ", logId, err.Error())
1813+
return err
1814+
}
1815+
1816+
err = resource.Retry(tccommon.ReadRetryTimeout*2, func() *resource.RetryError {
1817+
diskInfo, e := cbsService.DescribeDiskById(ctx, diskId)
1818+
if e != nil {
1819+
return tccommon.RetryError(e, tccommon.InternalError)
1820+
}
1821+
1822+
if *diskInfo.DiskState == svccbs.CBS_STORAGE_STATUS_TORECYCLE {
1823+
return resource.RetryableError(fmt.Errorf("cbs storage status is %s", *diskInfo.DiskState))
1824+
}
1825+
1826+
return nil
1827+
})
1828+
1829+
if err != nil {
1830+
log.Printf("[CRITAL]%s read cbs status failed, reason:%s\n ", logId, err.Error())
1831+
return err
1832+
}
1833+
1834+
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
1835+
e := cbsService.DeleteDiskById(ctx, diskId)
1836+
if e != nil {
1837+
return tccommon.RetryError(e, tccommon.InternalError)
1838+
}
1839+
1840+
return nil
1841+
})
1842+
1843+
if err != nil {
1844+
log.Printf("[CRITAL]%s delete cbs failed, reason:%s\n ", logId, err.Error())
1845+
return err
1846+
}
1847+
err = resource.Retry(tccommon.ReadRetryTimeout*2, func() *resource.RetryError {
1848+
diskInfo, e := cbsService.DescribeDiskById(ctx, diskId)
1849+
if e != nil {
1850+
return tccommon.RetryError(e, tccommon.InternalError)
1851+
}
1852+
1853+
if diskInfo != nil {
1854+
return resource.RetryableError(fmt.Errorf("cbs storage status is %s", *diskInfo.DiskState))
1855+
}
1856+
1857+
return nil
1858+
})
1859+
1860+
if err != nil {
1861+
log.Printf("[CRITAL]%s read cbs status failed, reason:%s\n ", logId, err.Error())
1862+
return err
1863+
}
1864+
}
1865+
1866+
deleteWithInstancePrepaid := value["delete_with_instance_prepaid"].(bool)
1867+
if deleteWithInstancePrepaid {
17621868
cbsService := svccbs.NewCbsService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
17631869
err := resource.Retry(tccommon.ReadRetryTimeout*2, func() *resource.RetryError {
17641870
diskInfo, e := cbsService.DescribeDiskById(ctx, diskId)

website/docs/r/instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ The `data_disks` object supports the following:
266266
* `data_disk_type` - (Required, String, ForceNew) Data disk type. For more information about limits on different data disk types, see [Storage Overview](https://intl.cloud.tencent.com/document/product/213/4952). Valid values: LOCAL_BASIC: local disk, LOCAL_SSD: local SSD disk, LOCAL_NVME: local NVME disk, specified in the InstanceType, LOCAL_PRO: local HDD disk, specified in the InstanceType, CLOUD_BASIC: HDD cloud disk, CLOUD_PREMIUM: Premium Cloud Storage, CLOUD_SSD: SSD, CLOUD_HSSD: Enhanced SSD, CLOUD_TSSD: Tremendous SSD, CLOUD_BSSD: Balanced SSD.
267267
* `data_disk_id` - (Optional, String) Data disk ID used to initialize the data disk. When data disk type is `LOCAL_BASIC` and `LOCAL_SSD`, disk id is not supported.
268268
* `data_disk_snapshot_id` - (Optional, String, ForceNew) Snapshot ID of the data disk. The selected data disk snapshot size must be smaller than the data disk size.
269+
* `delete_with_instance_prepaid` - (Optional, Bool, ForceNew) Decides whether the disk is deleted with instance(only applied to `CLOUD_BASIC`, `CLOUD_SSD` and `CLOUD_PREMIUM` disk with `PREPAID` instance), default is false.
269270
* `delete_with_instance` - (Optional, Bool, ForceNew) Decides whether the disk is deleted with instance(only applied to `CLOUD_BASIC`, `CLOUD_SSD` and `CLOUD_PREMIUM` disk with `POSTPAID_BY_HOUR` instance), default is true.
270271
* `encrypt` - (Optional, Bool, ForceNew) Decides whether the disk is encrypted. Default is `false`.
271272
* `throughput_performance` - (Optional, Int, ForceNew) Add extra performance to the data disk. Only works when disk type is `CLOUD_TSSD` or `CLOUD_HSSD`.

0 commit comments

Comments
 (0)