diff --git a/.changelog/3195.txt b/.changelog/3195.txt new file mode 100644 index 0000000000..c53a398305 --- /dev/null +++ b/.changelog/3195.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_instance: support cpu_topology +``` \ No newline at end of file diff --git a/tencentcloud/services/cvm/resource_tc_instance.go b/tencentcloud/services/cvm/resource_tc_instance.go index 333179d9fd..53731890a7 100644 --- a/tencentcloud/services/cvm/resource_tc_instance.go +++ b/tencentcloud/services/cvm/resource_tc_instance.go @@ -420,6 +420,32 @@ func ResourceTencentCloudInstance() *schema.Resource { Optional: true, Description: "CAM role name authorized to access.", }, + "cpu_topology": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Description: "Describes information about the instance CPU topology. If this parameter is not specified, it will be determined based on system resources.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "core_count": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Description: "Determines the number of CPU physical cores to enable.", + }, + "thread_per_core": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Description: "Number of threads per core. This parameter determines whether to turn Hyperthreading on or off.\n" + + " - 1 means turn off hyperthreading,\n" + + " - 2 means turn on hyperthreading,\n" + + "When not set, the instance uses the default hyper-threading policy.", + }, + }, + }, + }, // Computed values. "instance_status": { Type: schema.TypeString, @@ -475,6 +501,20 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{} ) request := cvm.NewRunInstancesRequest() + if v, ok := d.GetOk("cpu_topology"); ok { + vList := v.([]interface{}) + if len(vList) > 0 { + cpuTopologyMap := vList[0].(map[string]interface{}) + cpuTopology := &cvm.CpuTopology{} + if coreCount, coreCountOk := cpuTopologyMap["core_count"].(int); coreCountOk { + cpuTopology.CoreCount = helper.IntInt64(coreCount) + } + if threadPerCore, threadPerCoreOk := cpuTopologyMap["thread_per_core"].(int); threadPerCoreOk { + cpuTopology.ThreadPerCore = helper.IntInt64(threadPerCore) + } + request.CpuTopology = cpuTopology + } + } request.ImageId = helper.String(d.Get("image_id").(string)) request.Placement = &cvm.Placement{ Zone: helper.String(d.Get("availability_zone").(string)), diff --git a/tencentcloud/services/cvm/resource_tc_instance_test.go b/tencentcloud/services/cvm/resource_tc_instance_test.go index 5039065f3c..ab9c12d688 100644 --- a/tencentcloud/services/cvm/resource_tc_instance_test.go +++ b/tencentcloud/services/cvm/resource_tc_instance_test.go @@ -111,12 +111,95 @@ func TestAccTencentCloudInstanceResourceBasic(t *testing.T) { { ResourceName: "tencentcloud_instance.cvm_basic", ImportState: true, - ImportStateVerifyIgnore: []string{"disable_monitor_service", "disable_security_service", "disable_automation_service", "hostname", "password", "force_delete"}, + ImportStateVerifyIgnore: []string{"disable_monitor_service", "disable_security_service", "disable_automation_service", "hostname", "password", "force_delete", "cpu_topology"}, }, }, }) } +func TestAccTencentCloudInstanceResource_CpuTopology(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + acctest.AccPreCheck(t) + }, + Providers: acctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCvmInstanceResource_CpuTopology, + Check: resource.ComposeTestCheckFunc( + testAccCheckCvmInstanceExists("tencentcloud_instance.cvm_cputopology"), + ), + }, + { + ResourceName: "tencentcloud_instance.cvm_cputopology", + ImportState: true, + ImportStateVerifyIgnore: []string{"disable_monitor_service", "disable_security_service", "disable_automation_service", "hostname", "password", "force_delete", "cpu_topology"}, + }, + }, + }) +} + +const testAccCvmInstanceResource_CpuTopology = ` + +data "tencentcloud_availability_zones" "default" { +} +data "tencentcloud_images" "default" { + image_type = ["PUBLIC_IMAGE"] + image_name_regex = "Final" +} +data "tencentcloud_images" "testing" { + image_type = ["PUBLIC_IMAGE"] +} +data "tencentcloud_instance_types" "default" { + memory_size = 2 + exclude_sold_out = true + + filter { + name = "instance-family" + values = ["S1","S2","S3","S4","S5"] + } + filter { + name = "zone" + values = ["ap-guangzhou-7"] + } + cpu_core_count = 2 +} +resource "tencentcloud_vpc" "vpc" { + name = "cvm-basic-vpc" + cidr_block = "10.0.0.0/16" +} +resource "tencentcloud_subnet" "subnet" { + availability_zone = "ap-guangzhou-7" + vpc_id = tencentcloud_vpc.vpc.id + name = "cvm-basic-subnet" + cidr_block = "10.0.0.0/16" +} +resource "tencentcloud_instance" "cvm_cputopology" { + instance_name = "tf-ci-test" + availability_zone = "ap-guangzhou-7" + image_id = data.tencentcloud_images.default.images.0.image_id + vpc_id = tencentcloud_vpc.vpc.id + + tags = { + hostname = "tci" + } + + lifecycle { + ignore_changes = [instance_type] + } + instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type + subnet_id = tencentcloud_subnet.subnet.id + system_disk_type = "CLOUD_PREMIUM" + project_id = 0 + cpu_topology { + thread_per_core = 1 + core_count = 1 + } +} + +` + func testAccCheckCvmInstanceExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { logId := common.GetLogId(common.ContextNil) diff --git a/website/docs/r/instance.html.markdown b/website/docs/r/instance.html.markdown index e3697046a0..c8470eaf2f 100644 --- a/website/docs/r/instance.html.markdown +++ b/website/docs/r/instance.html.markdown @@ -222,6 +222,7 @@ The following arguments are supported: * `cam_role_name` - (Optional, String) CAM role name authorized to access. * `cdh_host_id` - (Optional, String, ForceNew) Id of cdh instance. Note: it only works when instance_charge_type is set to `CDHPAID`. * `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`. +* `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. * `data_disks` - (Optional, List, ForceNew) Settings for data disks. * `dedicated_cluster_id` - (Optional, String, ForceNew) Exclusive cluster id. * `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: * `user_data` - (Optional, String, ForceNew) The user data to be injected into this instance. Must be base64 encoded and up to 16 KB. * `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. +The `cpu_topology` object supports the following: + +* `core_count` - (Optional, Int, ForceNew) Determines the number of CPU physical cores to enable. +* `thread_per_core` - (Optional, Int, ForceNew) Number of threads per core. This parameter determines whether to turn Hyperthreading on or off. + - 1 means turn off hyperthreading, + - 2 means turn on hyperthreading, +When not set, the instance uses the default hyper-threading policy. + The `data_disks` object supports the following: * `data_disk_size` - (Required, Int) Size of the data disk, and unit is GB.