Skip to content

Commit 7a2c201

Browse files
tongyimingmikatong
and
mikatong
authored
fix(cvm): [123481747]support hpc_cluster_id (#3312)
* support hpc_cluster_id * add changelog * add test case --------- Co-authored-by: mikatong <[email protected]>
1 parent 0d20e79 commit 7a2c201

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

.changelog/3312.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_instance: support hpc_cluster_id
3+
```

tencentcloud/services/cvm/resource_tc_instance.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,13 @@ func ResourceTencentCloudInstance() *schema.Resource {
420420
Optional: true,
421421
Description: "CAM role name authorized to access.",
422422
},
423+
"hpc_cluster_id": {
424+
Type: schema.TypeString,
425+
Optional: true,
426+
Computed: true,
427+
ForceNew: true,
428+
Description: "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.",
429+
},
423430
// Computed values.
424431
"instance_status": {
425432
Type: schema.TypeString,
@@ -509,6 +516,10 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
509516
request.CamRoleName = helper.String(v.(string))
510517
}
511518

519+
if v, ok := d.GetOk("hpc_cluster_id"); ok {
520+
request.HpcClusterId = helper.String(v.(string))
521+
}
522+
512523
if v, ok := d.GetOk("instance_charge_type"); ok {
513524
instanceChargeType := v.(string)
514525
request.InstanceChargeType = &instanceChargeType
@@ -959,6 +970,7 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
959970
_ = d.Set("cpu", instance.CPU)
960971
_ = d.Set("memory", instance.Memory)
961972
_ = d.Set("os_name", instance.OsName)
973+
_ = d.Set("hpc_cluster_id", instance.HpcClusterId)
962974

963975
if instance.Uuid != nil {
964976
_ = d.Set("uuid", instance.Uuid)

tencentcloud/services/cvm/resource_tc_instance_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,3 +2931,67 @@ resource "tencentcloud_instance" "cvm_with_orderly_sg" {
29312931
orderly_security_groups = ["sg-cm7fbbf3", "sg-kensue7b", "sg-05f7wnhn"]
29322932
}
29332933
`
2934+
2935+
func TestAccTencentCloudInstanceResourceHPC(t *testing.T) {
2936+
t.Parallel()
2937+
resource.Test(t, resource.TestCase{
2938+
PreCheck: func() {
2939+
acctest.AccPreCheck(t)
2940+
},
2941+
Providers: acctest.AccProviders,
2942+
CheckDestroy: testAccCheckCvmInstanceDestroy,
2943+
Steps: []resource.TestStep{
2944+
{
2945+
Config: testAccTencentCloudInstanceHPC,
2946+
Check: resource.ComposeTestCheckFunc(
2947+
testAccCheckCvmInstanceExists("tencentcloud_instance.hpc"),
2948+
resource.TestCheckResourceAttr("tencentcloud_instance.hpc", "instance_status", "RUNNING"),
2949+
resource.TestCheckResourceAttrSet("tencentcloud_instance.hpc", "hpc_cluster_id"),
2950+
),
2951+
},
2952+
},
2953+
})
2954+
}
2955+
2956+
const testAccTencentCloudInstanceHPC = `
2957+
locals {
2958+
availability_zone = "ap-shanghai-5"
2959+
instance_type = "HCCS5.24XLARGE384"
2960+
}
2961+
2962+
resource "tencentcloud_cvm_hpc_cluster" "hpc_cluster" {
2963+
zone = local.availability_zone
2964+
name = "terraform-test"
2965+
remark = "create for test"
2966+
}
2967+
2968+
data "tencentcloud_images" "default" {
2969+
instance_type = local.instance_type
2970+
}
2971+
2972+
resource "tencentcloud_vpc" "vpc" {
2973+
cidr_block = "10.0.0.0/16"
2974+
name = "vpc"
2975+
}
2976+
2977+
resource "tencentcloud_subnet" "subnet" {
2978+
vpc_id = tencentcloud_vpc.vpc.id
2979+
availability_zone = local.availability_zone
2980+
name = "subnet"
2981+
cidr_block = "10.0.1.0/24"
2982+
}
2983+
2984+
resource "tencentcloud_instance" "hpc" {
2985+
instance_name = "tf-example"
2986+
availability_zone = local.availability_zone
2987+
image_id = data.tencentcloud_images.default.images.0.image_id
2988+
instance_type = local.instance_type
2989+
system_disk_type = "LOCAL_BASIC"
2990+
system_disk_size = 440
2991+
hostname = "user"
2992+
project_id = 0
2993+
vpc_id = tencentcloud_vpc.vpc.id
2994+
subnet_id = tencentcloud_subnet.subnet.id
2995+
hpc_cluster_id = tencentcloud_cvm_hpc_cluster.hpc_cluster.id
2996+
}
2997+
`

website/docs/r/instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ The following arguments are supported:
230230
* `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.
231231
* `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.
232232
* `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.
233+
* `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.
233234
* `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`.
234235
* `instance_charge_type_prepaid_renew_flag` - (Optional, String) Auto renewal flag. Valid values: `NOTIFY_AND_AUTO_RENEW`: notify upon expiration and renew automatically, `NOTIFY_AND_MANUAL_RENEW`: notify upon expiration but do not renew automatically, `DISABLE_NOTIFY_AND_MANUAL_RENEW`: neither notify upon expiration nor renew automatically. Default value: `NOTIFY_AND_MANUAL_RENEW`. If this parameter is specified as `NOTIFY_AND_AUTO_RENEW`, the instance will be automatically renewed on a monthly basis if the account balance is sufficient. NOTE: it only works when instance_charge_type is set to `PREPAID`.
235236
* `instance_charge_type` - (Optional, String) The charge type of instance. Valid values are `PREPAID`, `POSTPAID_BY_HOUR`, `SPOTPAID`, `CDHPAID` and `CDCPAID`. The default is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR` and `CDHPAID`. `PREPAID` instance may not allow to delete before expired. `SPOTPAID` instance must set `spot_instance_type` and `spot_max_price` at the same time. `CDHPAID` instance must set `cdh_instance_type` and `cdh_host_id`.

0 commit comments

Comments
 (0)