Skip to content

Commit def86d8

Browse files
committed
add
1 parent 8793d95 commit def86d8

File tree

3 files changed

+134
-4
lines changed

3 files changed

+134
-4
lines changed

tencentcloud/services/cvm/resource_tc_instance.go

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,14 @@ func ResourceTencentCloudInstance() *schema.Resource {
108108
"placement_group_id": {
109109
Type: schema.TypeString,
110110
Optional: true,
111-
ForceNew: true,
112111
Description: "The ID of a placement group.",
113112
},
113+
"force_replace_placement_group_id": {
114+
Type: schema.TypeBool,
115+
Optional: true,
116+
Computed: true,
117+
Description: "Whether to force the instance host to be replaced. Value range: true: Allows the instance to change the host and restart the instance. Local disk machines do not support specifying this parameter; false: Does not allow the instance to change the host and only join the placement group on the current host. This may cause the placement group to fail to change. Only useful for change `placement_group_id`, Default is false.",
118+
},
114119
// payment
115120
"instance_charge_type": {
116121
Type: schema.TypeString,
@@ -580,6 +585,13 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
580585
request.DisasterRecoverGroupIds = []*string{helper.String(v.(string))}
581586
}
582587

588+
var PgiFlag bool
589+
if v, ok := d.GetOkExists("force_replace_placement_group_id"); ok {
590+
PgiFlag = v.(bool)
591+
}
592+
593+
_ = d.Set("force_replace_placement_group_id", PgiFlag)
594+
583595
// network
584596
request.InternetAccessible = &cvm.InternetAccessible{}
585597
if v, ok := d.GetOk("internet_charge_type"); ok {
@@ -988,6 +1000,17 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
9881000
_ = d.Set("uuid", instance.Uuid)
9891001
}
9901002

1003+
if instance.DisasterRecoverGroupId != nil {
1004+
_ = d.Set("placement_group_id", instance.DisasterRecoverGroupId)
1005+
}
1006+
1007+
var PgiFlag bool
1008+
if v, ok := d.GetOkExists("force_replace_placement_group_id"); ok {
1009+
PgiFlag = v.(bool)
1010+
}
1011+
1012+
_ = d.Set("force_replace_placement_group_id", PgiFlag)
1013+
9911014
if *instance.InstanceChargeType == CVM_CHARGE_TYPE_CDHPAID {
9921015
_ = d.Set("cdh_instance_type", instance.InstanceType)
9931016
}
@@ -2027,6 +2050,7 @@ func resourceTencentCloudInstanceUpdate(d *schema.ResourceData, meta interface{}
20272050
return err
20282051
}
20292052
}
2053+
20302054
if d.HasChange("user_data_raw") {
20312055
userDataRaw := d.Get("user_data_raw").(string)
20322056
userData := base64.StdEncoding.EncodeToString([]byte(userDataRaw))
@@ -2040,6 +2064,47 @@ func resourceTencentCloudInstanceUpdate(d *schema.ResourceData, meta interface{}
20402064
return err
20412065
}
20422066
}
2067+
2068+
if d.HasChange("force_replace_placement_group_id") {
2069+
var PgiFlag bool
2070+
if v, ok := d.GetOkExists("force_replace_placement_group_id"); ok {
2071+
PgiFlag = v.(bool)
2072+
}
2073+
2074+
_ = d.Set("force_replace_placement_group_id", PgiFlag)
2075+
}
2076+
2077+
if d.HasChange("placement_group_id") {
2078+
_, newPGI := d.GetChange("placement_group_id")
2079+
newPGIStr := newPGI.(string)
2080+
if newPGIStr == "" {
2081+
// wait cvm support delete DisasterRecoverGroupId
2082+
return fmt.Errorf("Deleting `placement_group_id` is not currently supported.")
2083+
} else {
2084+
request := cvm.NewModifyInstancesDisasterRecoverGroupRequest()
2085+
if v, ok := d.GetOkExists("force_replace_placement_group_id"); ok {
2086+
request.Force = helper.Bool(v.(bool))
2087+
}
2088+
2089+
request.InstanceIds = helper.Strings([]string{instanceId})
2090+
request.DisasterRecoverGroupId = helper.String(newPGIStr)
2091+
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
2092+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCvmClient().ModifyInstancesDisasterRecoverGroup(request)
2093+
if e != nil {
2094+
return tccommon.RetryError(e, tccommon.InternalError)
2095+
} else {
2096+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
2097+
}
2098+
2099+
return nil
2100+
})
2101+
2102+
if err != nil {
2103+
return err
2104+
}
2105+
}
2106+
}
2107+
20432108
d.Partial(false)
20442109

20452110
return resourceTencentCloudInstanceRead(d, meta)

tencentcloud/services/cvm/resource_tc_instance.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ Provides a CVM instance resource.
22

33
~> **NOTE:** You can launch an CVM instance for a VPC network via specifying parameter `vpc_id`. One instance can only belong to one VPC.
44

5-
~> **NOTE:** At present, 'PREPAID' instance cannot be deleted directly and must wait it to be outdated and released automatically.
5+
~> **NOTE:** At present, `PREPAID` instance cannot be deleted directly and must wait it to be outdated and released automatically.
6+
7+
~> **NOTE:** Currently, the `placement_group_id` field only supports setting and modification, but not deletion.
68

79
Example Usage
810

@@ -200,6 +202,36 @@ resource "tencentcloud_instance" "example" {
200202
}
201203
```
202204

205+
Create CVM instance with placement_group_id
206+
207+
```hcl
208+
resource "tencentcloud_instance" "example" {
209+
instance_name = "tf-example"
210+
availability_zone = "ap-guangzhou-6"
211+
image_id = "img-eb30mz89"
212+
instance_type = "S5.MEDIUM4"
213+
system_disk_size = 50
214+
system_disk_name = "sys_disk_1"
215+
hostname = "user"
216+
project_id = 0
217+
vpc_id = "vpc-i5yyodl9"
218+
subnet_id = "subnet-hhi88a58"
219+
placement_group_id = "ps-ejt4brtz"
220+
force_replace_placement_group_id = false
221+
222+
data_disks {
223+
data_disk_type = "CLOUD_HSSD"
224+
data_disk_size = 100
225+
encrypt = false
226+
data_disk_name = "data_disk_1"
227+
}
228+
229+
tags = {
230+
tagKey = "tagValue"
231+
}
232+
}
233+
```
234+
203235
Import
204236

205237
CVM instance can be imported using the id, e.g.

website/docs/r/instance.html.markdown

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Provides a CVM instance resource.
1313

1414
~> **NOTE:** You can launch an CVM instance for a VPC network via specifying parameter `vpc_id`. One instance can only belong to one VPC.
1515

16-
~> **NOTE:** At present, 'PREPAID' instance cannot be deleted directly and must wait it to be outdated and released automatically.
16+
~> **NOTE:** At present, `PREPAID` instance cannot be deleted directly and must wait it to be outdated and released automatically.
17+
18+
~> **NOTE:** Currently, the `placement_group_id` field only supports setting and modification, but not deletion.
1719

1820
## Example Usage
1921

@@ -211,6 +213,36 @@ resource "tencentcloud_instance" "example" {
211213
}
212214
```
213215

216+
### Create CVM instance with placement_group_id
217+
218+
```hcl
219+
resource "tencentcloud_instance" "example" {
220+
instance_name = "tf-example"
221+
availability_zone = "ap-guangzhou-6"
222+
image_id = "img-eb30mz89"
223+
instance_type = "S5.MEDIUM4"
224+
system_disk_size = 50
225+
system_disk_name = "sys_disk_1"
226+
hostname = "user"
227+
project_id = 0
228+
vpc_id = "vpc-i5yyodl9"
229+
subnet_id = "subnet-hhi88a58"
230+
placement_group_id = "ps-ejt4brtz"
231+
force_replace_placement_group_id = false
232+
233+
data_disks {
234+
data_disk_type = "CLOUD_HSSD"
235+
data_disk_size = 100
236+
encrypt = false
237+
data_disk_name = "data_disk_1"
238+
}
239+
240+
tags = {
241+
tagKey = "tagValue"
242+
}
243+
}
244+
```
245+
214246
## Argument Reference
215247

216248
The following arguments are supported:
@@ -229,6 +261,7 @@ The following arguments are supported:
229261
* `disable_monitor_service` - (Optional, Bool) Disable enhance service for monitor, it is enabled by default. When this options is set, monitor agent won't be installed. Modifications may lead to the reinstallation of the instance's operating system.
230262
* `disable_security_service` - (Optional, Bool) Disable enhance service for security, it is enabled by default. When this options is set, security agent won't be installed. Modifications may lead to the reinstallation of the instance's operating system.
231263
* `force_delete` - (Optional, Bool) Indicate whether to force delete the instance. Default is `false`. If set true, the instance will be permanently deleted instead of being moved into the recycle bin. Note: only works for `PREPAID` instance.
264+
* `force_replace_placement_group_id` - (Optional, Bool) Whether to force the instance host to be replaced. Value range: true: Allows the instance to change the host and restart the instance. Local disk machines do not support specifying this parameter; false: Does not allow the instance to change the host and only join the placement group on the current host. This may cause the placement group to fail to change. Only useful for change `placement_group_id`, Default is false.
232265
* `hostname` - (Optional, String) The hostname of the instance. Windows instance: The name should be a combination of 2 to 15 characters comprised of letters (case insensitive), numbers, and hyphens (-). Period (.) is not supported, and the name cannot be a string of pure numbers. Other types (such as Linux) of instances: The name should be a combination of 2 to 60 characters, supporting multiple periods (.). The piece between two periods is composed of letters (case insensitive), numbers, and hyphens (-). Modifications may lead to the reinstallation of the instance's operating system.
233266
* `hpc_cluster_id` - (Optional, String, ForceNew) High-performance computing cluster ID. If the instance created is a high-performance computing instance, you need to specify the cluster in which the instance is placed, otherwise it cannot be specified.
234267
* `instance_charge_type_prepaid_period` - (Optional, Int) The tenancy (time unit is month) of the prepaid instance, NOTE: it only works when instance_charge_type is set to `PREPAID`. Valid values are `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `24`, `36`, `48`, `60`.
@@ -244,7 +277,7 @@ The following arguments are supported:
244277
* `key_name` - (Optional, String, **Deprecated**) Please use `key_ids` instead. The key pair to use for the instance, it looks like `skey-16jig7tx`. Modifications may lead to the reinstallation of the instance's operating system.
245278
* `orderly_security_groups` - (Optional, List: [`String`]) A list of orderly security group IDs to associate with.
246279
* `password` - (Optional, String) Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change. Modifications may lead to the reinstallation of the instance's operating system.
247-
* `placement_group_id` - (Optional, String, ForceNew) The ID of a placement group.
280+
* `placement_group_id` - (Optional, String) The ID of a placement group.
248281
* `private_ip` - (Optional, String) The private IP to be assigned to this instance, must be in the provided subnet and available.
249282
* `project_id` - (Optional, Int) The project the instance belongs to, default to 0.
250283
* `running_flag` - (Optional, Bool) Set instance to running or stop. Default value is true, the instance will shutdown when this flag is false.

0 commit comments

Comments
 (0)