Skip to content

Commit 2a73d21

Browse files
author
mikatong
committed
support cpu_topology
1 parent 131162f commit 2a73d21

File tree

3 files changed

+133
-1
lines changed

3 files changed

+133
-1
lines changed

tencentcloud/services/cvm/resource_tc_instance.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,32 @@ func ResourceTencentCloudInstance() *schema.Resource {
420420
Optional: true,
421421
Description: "CAM role name authorized to access.",
422422
},
423+
"cpu_topology": {
424+
Type: schema.TypeList,
425+
Optional: true,
426+
ForceNew: true,
427+
MaxItems: 1,
428+
Description: "Describes information about the instance CPU topology. If this parameter is not specified, it will be determined based on system resources.",
429+
Elem: &schema.Resource{
430+
Schema: map[string]*schema.Schema{
431+
"core_count": {
432+
Type: schema.TypeInt,
433+
Optional: true,
434+
ForceNew: true,
435+
Description: "Determines the number of CPU physical cores to enable.",
436+
},
437+
"thread_per_core": {
438+
Type: schema.TypeInt,
439+
Optional: true,
440+
ForceNew: true,
441+
Description: "Number of threads per core. This parameter determines whether to turn Hyperthreading on or off.\n" +
442+
" - 1 means turn off hyperthreading,\n" +
443+
" - 2 means turn on hyperthreading,\n" +
444+
"When not set, the instance uses the default hyper-threading policy.",
445+
},
446+
},
447+
},
448+
},
423449
// Computed values.
424450
"instance_status": {
425451
Type: schema.TypeString,
@@ -475,6 +501,20 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
475501
)
476502

477503
request := cvm.NewRunInstancesRequest()
504+
if v, ok := d.GetOk("cpu_topology"); ok {
505+
vList := v.([]interface{})
506+
if len(vList) > 0 {
507+
cpuTopologyMap := vList[0].(map[string]interface{})
508+
cpuTopology := &cvm.CpuTopology{}
509+
if coreCount, coreCountOk := cpuTopologyMap["core_count"].(int); coreCountOk {
510+
cpuTopology.CoreCount = helper.IntInt64(coreCount)
511+
}
512+
if threadPerCore, threadPerCoreOk := cpuTopologyMap["thread_per_core"].(int); threadPerCoreOk {
513+
cpuTopology.ThreadPerCore = helper.IntInt64(threadPerCore)
514+
}
515+
request.CpuTopology = cpuTopology
516+
}
517+
}
478518
request.ImageId = helper.String(d.Get("image_id").(string))
479519
request.Placement = &cvm.Placement{
480520
Zone: helper.String(d.Get("availability_zone").(string)),

tencentcloud/services/cvm/resource_tc_instance_test.go

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,95 @@ func TestAccTencentCloudInstanceResourceBasic(t *testing.T) {
111111
{
112112
ResourceName: "tencentcloud_instance.cvm_basic",
113113
ImportState: true,
114-
ImportStateVerifyIgnore: []string{"disable_monitor_service", "disable_security_service", "disable_automation_service", "hostname", "password", "force_delete"},
114+
ImportStateVerifyIgnore: []string{"disable_monitor_service", "disable_security_service", "disable_automation_service", "hostname", "password", "force_delete", "cpu_topology"},
115115
},
116116
},
117117
})
118118
}
119119

120+
func TestAccTencentCloudInstanceResource_CpuTopology(t *testing.T) {
121+
t.Parallel()
122+
resource.Test(t, resource.TestCase{
123+
PreCheck: func() {
124+
acctest.AccPreCheck(t)
125+
},
126+
Providers: acctest.AccProviders,
127+
Steps: []resource.TestStep{
128+
{
129+
Config: testAccCvmInstanceResource_CpuTopology,
130+
Check: resource.ComposeTestCheckFunc(
131+
testAccCheckCvmInstanceExists("tencentcloud_instance.cvm_cputopology"),
132+
),
133+
},
134+
{
135+
ResourceName: "tencentcloud_instance.cvm_cputopology",
136+
ImportState: true,
137+
ImportStateVerifyIgnore: []string{"disable_monitor_service", "disable_security_service", "disable_automation_service", "hostname", "password", "force_delete", "cpu_topology"},
138+
},
139+
},
140+
})
141+
}
142+
143+
const testAccCvmInstanceResource_CpuTopology = `
144+
145+
data "tencentcloud_availability_zones" "default" {
146+
}
147+
data "tencentcloud_images" "default" {
148+
image_type = ["PUBLIC_IMAGE"]
149+
image_name_regex = "Final"
150+
}
151+
data "tencentcloud_images" "testing" {
152+
image_type = ["PUBLIC_IMAGE"]
153+
}
154+
data "tencentcloud_instance_types" "default" {
155+
memory_size = 2
156+
exclude_sold_out = true
157+
158+
filter {
159+
name = "instance-family"
160+
values = ["S1","S2","S3","S4","S5"]
161+
}
162+
filter {
163+
name = "zone"
164+
values = ["ap-guangzhou-7"]
165+
}
166+
cpu_core_count = 2
167+
}
168+
resource "tencentcloud_vpc" "vpc" {
169+
name = "cvm-basic-vpc"
170+
cidr_block = "10.0.0.0/16"
171+
}
172+
resource "tencentcloud_subnet" "subnet" {
173+
availability_zone = "ap-guangzhou-7"
174+
vpc_id = tencentcloud_vpc.vpc.id
175+
name = "cvm-basic-subnet"
176+
cidr_block = "10.0.0.0/16"
177+
}
178+
resource "tencentcloud_instance" "cvm_cputopology" {
179+
instance_name = "tf-ci-test"
180+
availability_zone = "ap-guangzhou-7"
181+
image_id = data.tencentcloud_images.default.images.0.image_id
182+
vpc_id = tencentcloud_vpc.vpc.id
183+
184+
tags = {
185+
hostname = "tci"
186+
}
187+
188+
lifecycle {
189+
ignore_changes = [instance_type]
190+
}
191+
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
192+
subnet_id = tencentcloud_subnet.subnet.id
193+
system_disk_type = "CLOUD_PREMIUM"
194+
project_id = 0
195+
cpu_topology {
196+
thread_per_core = 1
197+
core_count = 1
198+
}
199+
}
200+
201+
`
202+
120203
func testAccCheckCvmInstanceExists(n string) resource.TestCheckFunc {
121204
return func(s *terraform.State) error {
122205
logId := common.GetLogId(common.ContextNil)

website/docs/r/instance.html.markdown

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ The following arguments are supported:
222222
* `cam_role_name` - (Optional, String) CAM role name authorized to access.
223223
* `cdh_host_id` - (Optional, String, ForceNew) Id of cdh instance. Note: it only works when instance_charge_type is set to `CDHPAID`.
224224
* `cdh_instance_type` - (Optional, String) Type of instance created on cdh, the value of this parameter is in the format of CDH_XCXG based on the number of CPU cores and memory capacity. Note: it only works when instance_charge_type is set to `CDHPAID`.
225+
* `cpu_topology` - (Optional, List, ForceNew) Describes information about the instance CPU topology. If this parameter is not specified, it will be determined based on system resources.
225226
* `data_disks` - (Optional, List, ForceNew) Settings for data disks.
226227
* `dedicated_cluster_id` - (Optional, String, ForceNew) Exclusive cluster id.
227228
* `disable_api_termination` - (Optional, Bool) Whether the termination protection is enabled. Default is `false`. If set true, which means that this instance can not be deleted by an API action.
@@ -262,6 +263,14 @@ The following arguments are supported:
262263
* `user_data` - (Optional, String, ForceNew) The user data to be injected into this instance. Must be base64 encoded and up to 16 KB.
263264
* `vpc_id` - (Optional, String) The ID of a VPC network. If you want to create instances in a VPC network, this parameter must be set.
264265

266+
The `cpu_topology` object supports the following:
267+
268+
* `core_count` - (Optional, Int, ForceNew) Determines the number of CPU physical cores to enable.
269+
* `thread_per_core` - (Optional, Int, ForceNew) Number of threads per core. This parameter determines whether to turn Hyperthreading on or off.
270+
- 1 means turn off hyperthreading,
271+
- 2 means turn on hyperthreading,
272+
When not set, the instance uses the default hyper-threading policy.
273+
265274
The `data_disks` object supports the following:
266275

267276
* `data_disk_size` - (Required, Int) Size of the data disk, and unit is GB.

0 commit comments

Comments
 (0)