Skip to content

Commit 2aad64e

Browse files
committed
resource tencentcloud_instance add cdh setting
1 parent 65ba36b commit 2aad64e

File tree

6 files changed

+82
-2
lines changed

6 files changed

+82
-2
lines changed

examples/tencentcloud-cdh/main.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
data "tencentcloud_images" "my_favorate_image" {
2+
image_type = ["PUBLIC_IMAGE"]
3+
os_name = var.os_name
4+
}
5+
6+
resource "tencentcloud_cdh_instance" "foo" {
7+
availability_zone = var.availability_zone
8+
host_type = "HC20"
9+
charge_type = "PREPAID"
10+
host_name = "test"
11+
prepaid_renew_flag = "NOTIFY_AND_MANUAL_RENEW"
12+
}
13+
14+
data "tencentcloud_cdh_instances" "list" {
15+
availability_zone = var.availability_zone
16+
host_id = tencentcloud_cdh_instance.foo.id
17+
host_name = "test"
18+
host_state = "RUNNING"
19+
}
20+
21+
resource "tencentcloud_key_pair" "random_key" {
22+
key_name = "tf_example_key6"
23+
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDjd8fTnp7Dcuj4mLaQxf9Zs/ORgUL9fQxRCNKkPgP1paTy1I513maMX126i36Lxxl3+FUB52oVbo/FgwlIfX8hyCnv8MCxqnuSDozf1CD0/wRYHcTWAtgHQHBPCC2nJtod6cVC3kB18KeV4U7zsxmwFeBIxojMOOmcOBuh7+trRw=="
24+
}
25+
26+
resource "tencentcloud_instance" "foo" {
27+
instance_name = var.instance_name
28+
availability_zone = var.availability_zone
29+
image_id = data.tencentcloud_images.my_favorate_image.images.0.image_id
30+
instance_charge_type = "CDHPAID"
31+
cdh_instance_type = "CDH_10C10G"
32+
cdh_host_id = tencentcloud_cdh_instance.foo.id
33+
key_name = tencentcloud_key_pair.random_key.id
34+
system_disk_type = "CLOUD_PREMIUM"
35+
36+
allocate_public_ip = true
37+
internet_max_bandwidth_out = 2
38+
count = 1
39+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "availability_zone" {
2+
default = "ap-guangzhou-3"
3+
}
4+
5+
variable "instance_name" {
6+
default = "terraform-testing"
7+
}
8+
9+
variable "os_name" {
10+
default = "centos"
11+
}

examples/tencentcloud-cdh/version.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = ">= 0.12"
3+
}

tencentcloud/extension_cvm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const (
44
CVM_CHARGE_TYPE_PREPAID = "PREPAID"
55
CVM_CHARGE_TYPE_POSTPAID = "POSTPAID_BY_HOUR"
66
CVM_CHARGE_TYPE_SPOTPAID = "SPOTPAID"
7+
CVM_CHARGE_TYPE_CDHPAID = "CDHPAID"
78

89
CVM_INTERNET_CHARGE_TYPE_BANDWIDTH_PREPAID = "BANDWIDTH_PREPAID"
910
CVM_INTERNET_CHARGE_TYPE_BANDWIDTH_POSTPAID = "BANDWIDTH_POSTPAID_BY_HOUR"
@@ -56,6 +57,7 @@ var CVM_CHARGE_TYPE = []string{
5657
CVM_CHARGE_TYPE_PREPAID,
5758
CVM_CHARGE_TYPE_POSTPAID,
5859
CVM_CHARGE_TYPE_SPOTPAID,
60+
CVM_CHARGE_TYPE_CDHPAID,
5961
}
6062

6163
var CVM_INTERNET_CHARGE_TYPE = []string{

tencentcloud/resource_tc_instance.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func resourceTencentCloudInstance() *schema.Resource {
162162
ForceNew: true,
163163
Default: CVM_CHARGE_TYPE_POSTPAID,
164164
ValidateFunc: validateAllowedStringValue(CVM_CHARGE_TYPE),
165-
Description: "The charge type of instance. Valid values are `PREPAID`, `POSTPAID_BY_HOUR` and `SPOTPAID`. The default is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR`. `PREPAID` instance may not allow to delete before expired. `SPOTPAID` instance must set `spot_instance_type` and `spot_max_price` at the same time.",
165+
Description: "The charge type of instance. Valid values are `PREPAID`, `POSTPAID_BY_HOUR`, `SPOTPAID` and `CDHPAID`. 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`.",
166166
},
167167
"instance_charge_type_prepaid_period": {
168168
Type: schema.TypeInt,
@@ -190,6 +190,17 @@ func resourceTencentCloudInstance() *schema.Resource {
190190
ValidateFunc: validateStringNumber,
191191
Description: "Max price of a spot instance, is the format of decimal string, for example \"0.50\". Note: it only works when instance_charge_type is set to `SPOTPAID`.",
192192
},
193+
"cdh_instance_type": {
194+
Type: schema.TypeString,
195+
Optional: true,
196+
ValidateFunc: validateStringPrefix("CDH_"),
197+
Description: "Type of instance based 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`.",
198+
},
199+
"cdh_host_id": {
200+
Type: schema.TypeString,
201+
Optional: true,
202+
Description: "Id of cdh instance. Note: it only works when instance_charge_type is set to `CDHPAID`.",
203+
},
193204
// network
194205
"internet_charge_type": {
195206
Type: schema.TypeString,
@@ -478,6 +489,18 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
478489
return fmt.Errorf("spot_max_price can not be empty when instance_charge_type is %s", instanceChargeType)
479490
}
480491
}
492+
if instanceChargeType == CVM_CHARGE_TYPE_CDHPAID {
493+
if v, ok := d.GetOk("cdh_instance_type"); ok {
494+
request.InstanceType = helper.String(v.(string))
495+
} else {
496+
return fmt.Errorf("cdh_instance_type can not be empty when instance_charge_type is %s", instanceChargeType)
497+
}
498+
if v, ok := d.GetOk("cdh_host_id"); ok {
499+
request.Placement.HostIds = append(request.Placement.HostIds, helper.String(v.(string)))
500+
} else {
501+
return fmt.Errorf("cdh_host_id can not be empty when instance_charge_type is %s", instanceChargeType)
502+
}
503+
}
481504
}
482505
if v, ok := d.GetOk("placement_group_id"); ok {
483506
request.DisasterRecoverGroupIds = []*string{helper.String(v.(string))}

website/docs/r/instance.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ The following arguments are supported:
8585
* `image_id` - (Required, ForceNew) The image to use for the instance. Changing `image_id` will cause the instance to be destroyed and re-created.
8686
* `allocate_public_ip` - (Optional, ForceNew) Associate a public IP address with an instance in a VPC or Classic. Boolean value, Default is false.
8787
* `cam_role_name` - (Optional, ForceNew) CAM role name authorized to access.
88+
* `cdh_host_id` - (Optional) Id of cdh instance. Note: it only works when instance_charge_type is set to `CDHPAID`.
89+
* `cdh_instance_type` - (Optional) Type of instance based 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`.
8890
* `data_disks` - (Optional, ForceNew) Settings for data disks.
8991
* `disable_monitor_service` - (Optional) Disable enhance service for monitor, it is enabled by default. When this options is set, monitor agent won't be installed.
9092
* `disable_security_service` - (Optional) Disable enhance service for security, it is enabled by default. When this options is set, security agent won't be installed.
9193
* `force_delete` - (Optional) 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.
9294
* `hostname` - (Optional, ForceNew) 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 (-).
9395
* `instance_charge_type_prepaid_period` - (Optional) 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`.
9496
* `instance_charge_type_prepaid_renew_flag` - (Optional) 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`.
95-
* `instance_charge_type` - (Optional, ForceNew) The charge type of instance. Valid values are `PREPAID`, `POSTPAID_BY_HOUR` and `SPOTPAID`. The default is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR`. `PREPAID` instance may not allow to delete before expired. `SPOTPAID` instance must set `spot_instance_type` and `spot_max_price` at the same time.
97+
* `instance_charge_type` - (Optional, ForceNew) The charge type of instance. Valid values are `PREPAID`, `POSTPAID_BY_HOUR`, `SPOTPAID` and `CDHPAID`. 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`.
9698
* `instance_name` - (Optional) The name of the instance. The max length of instance_name is 60, and default value is `Terraform-CVM-Instance`.
9799
* `instance_type` - (Optional) The type of the instance.
98100
* `internet_charge_type` - (Optional, ForceNew) Internet charge type of the instance, Valid values are `BANDWIDTH_PREPAID`, `TRAFFIC_POSTPAID_BY_HOUR`, `BANDWIDTH_POSTPAID_BY_HOUR` and `BANDWIDTH_PACKAGE`. This value does not need to be set when `allocate_public_ip` is false.

0 commit comments

Comments
 (0)