Skip to content

fix(cvm): [120913662]support cpu_topology #3195

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3195.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_instance: support cpu_topology
```
40 changes: 40 additions & 0 deletions tencentcloud/services/cvm/resource_tc_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)),
Expand Down
85 changes: 84 additions & 1 deletion tencentcloud/services/cvm/resource_tc_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading