Skip to content

Commit 5fb0cac

Browse files
committed
add
1 parent 4f1317c commit 5fb0cac

File tree

2 files changed

+291
-75
lines changed

2 files changed

+291
-75
lines changed

tencentcloud/services/cvm/resource_tc_instance.md

Lines changed: 150 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,87 +6,195 @@ Provides a CVM instance resource.
66

77
Example Usage
88

9+
Create a general POSTPAID_BY_HOUR CVM instance
10+
911
```hcl
10-
data "tencentcloud_images" "my_favorite_image" {
11-
image_type = ["PUBLIC_IMAGE"]
12-
image_name_regex = "Final"
12+
variable "availability_zone" {
13+
default = "ap-guangzhou-4"
14+
}
15+
16+
data "tencentcloud_images" "images" {
17+
image_type = ["PUBLIC_IMAGE"]
18+
image_name_regex = "OpenCloudOS Server"
1319
}
1420
15-
data "tencentcloud_instance_types" "my_favorite_instance_types" {
21+
data "tencentcloud_instance_types" "types" {
1622
filter {
1723
name = "instance-family"
1824
values = ["S1", "S2", "S3", "S4", "S5"]
1925
}
2026
21-
cpu_core_count = 2
27+
cpu_core_count = 2
2228
exclude_sold_out = true
2329
}
2430
25-
data "tencentcloud_availability_zones" "my_favorite_zones" {
26-
}
27-
28-
// Create VPC resource
29-
resource "tencentcloud_vpc" "app" {
31+
// create vpc
32+
resource "tencentcloud_vpc" "vpc" {
3033
cidr_block = "10.0.0.0/16"
31-
name = "awesome_app_vpc"
34+
name = "vpc"
3235
}
3336
34-
resource "tencentcloud_subnet" "app" {
35-
vpc_id = tencentcloud_vpc.app.id
36-
availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name
37-
name = "awesome_app_subnet"
37+
// create subnet
38+
resource "tencentcloud_subnet" "subnet" {
39+
vpc_id = tencentcloud_vpc.vpc.id
40+
availability_zone = var.availability_zone
41+
name = "subnet"
3842
cidr_block = "10.0.1.0/24"
3943
}
4044
41-
// Create a POSTPAID_BY_HOUR CVM instance
42-
resource "tencentcloud_instance" "cvm_postpaid" {
43-
instance_name = "cvm_postpaid"
44-
availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name
45-
image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id
46-
instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type
47-
system_disk_type = "CLOUD_PREMIUM"
48-
system_disk_size = 50
49-
hostname = "user"
50-
project_id = 0
51-
vpc_id = tencentcloud_vpc.app.id
52-
subnet_id = tencentcloud_subnet.app.id
45+
// create CVM instance
46+
resource "tencentcloud_instance" "example" {
47+
instance_name = "tf-example"
48+
availability_zone = var.availability_zone
49+
image_id = data.tencentcloud_images.images.images.0.image_id
50+
instance_type = data.tencentcloud_instance_types.types.instance_types.0.instance_type
51+
system_disk_type = "CLOUD_PREMIUM"
52+
system_disk_size = 50
53+
hostname = "user"
54+
project_id = 0
55+
vpc_id = tencentcloud_vpc.vpc.id
56+
subnet_id = tencentcloud_subnet.subnet.id
5357
5458
data_disks {
5559
data_disk_type = "CLOUD_PREMIUM"
5660
data_disk_size = 50
57-
encrypt = false
61+
encrypt = false
5862
}
5963
6064
tags = {
6165
tagKey = "tagValue"
6266
}
6367
}
68+
```
6469

65-
// Create a PREPAID CVM instance
66-
resource "tencentcloud_instance" "cvm_prepaid" {
67-
timeouts {
68-
create = "30m"
70+
Create a general PREPAID CVM instance
71+
72+
```hcl
73+
variable "availability_zone" {
74+
default = "ap-guangzhou-4"
75+
}
76+
77+
data "tencentcloud_images" "images" {
78+
image_type = ["PUBLIC_IMAGE"]
79+
image_name_regex = "OpenCloudOS Server"
80+
}
81+
82+
data "tencentcloud_instance_types" "types" {
83+
filter {
84+
name = "instance-family"
85+
values = ["S1", "S2", "S3", "S4", "S5"]
6986
}
70-
instance_name = "cvm_prepaid"
71-
availability_zone = data.tencentcloud_availability_zones.my_favorite_zones.zones.0.name
72-
image_id = data.tencentcloud_images.my_favorite_image.images.0.image_id
73-
instance_type = data.tencentcloud_instance_types.my_favorite_instance_types.instance_types.0.instance_type
87+
88+
cpu_core_count = 2
89+
exclude_sold_out = true
90+
}
91+
92+
// create vpc
93+
resource "tencentcloud_vpc" "vpc" {
94+
cidr_block = "10.0.0.0/16"
95+
name = "vpc"
96+
}
97+
98+
// create subnet
99+
resource "tencentcloud_subnet" "subnet" {
100+
vpc_id = tencentcloud_vpc.vpc.id
101+
availability_zone = var.availability_zone
102+
name = "subnet"
103+
cidr_block = "10.0.1.0/24"
104+
}
105+
106+
// create CVM instance
107+
resource "tencentcloud_instance" "example" {
108+
instance_name = "tf-example"
109+
availability_zone = var.availability_zone
110+
image_id = data.tencentcloud_images.images.images.0.image_id
111+
instance_type = data.tencentcloud_instance_types.types.instance_types.0.instance_type
74112
system_disk_type = "CLOUD_PREMIUM"
75113
system_disk_size = 50
76114
hostname = "user"
77115
project_id = 0
78-
vpc_id = tencentcloud_vpc.app.id
79-
subnet_id = tencentcloud_subnet.app.id
116+
vpc_id = tencentcloud_vpc.vpc.id
117+
subnet_id = tencentcloud_subnet.subnet.id
80118
instance_charge_type = "PREPAID"
81119
instance_charge_type_prepaid_period = 1
82120
instance_charge_type_prepaid_renew_flag = "NOTIFY_AND_MANUAL_RENEW"
121+
force_delete = true
122+
data_disks {
123+
data_disk_type = "CLOUD_PREMIUM"
124+
data_disk_size = 50
125+
encrypt = false
126+
}
127+
128+
tags = {
129+
tagKey = "tagValue"
130+
}
131+
132+
timeouts {
133+
create = "30m"
134+
}
135+
}
136+
```
137+
138+
Create a dedicated cluster CVM instance
139+
140+
```hcl
141+
variable "availability_zone" {
142+
default = "ap-guangzhou-4"
143+
}
144+
145+
data "tencentcloud_images" "images" {
146+
image_type = ["PUBLIC_IMAGE"]
147+
image_name_regex = "OpenCloudOS Server"
148+
}
149+
150+
data "tencentcloud_instance_types" "types" {
151+
filter {
152+
name = "instance-family"
153+
values = ["S1", "S2", "S3", "S4", "S5"]
154+
}
155+
156+
cpu_core_count = 2
157+
exclude_sold_out = true
158+
}
159+
160+
// create vpc
161+
resource "tencentcloud_vpc" "vpc" {
162+
cidr_block = "10.0.0.0/16"
163+
name = "vpc"
164+
}
165+
166+
// create subnet
167+
resource "tencentcloud_subnet" "subnet" {
168+
vpc_id = tencentcloud_vpc.vpc.id
169+
availability_zone = var.availability_zone
170+
name = "subnet"
171+
cidr_block = "10.0.1.0/24"
172+
cdc_id = "cluster-lchwgxhs"
173+
is_multicast = false
174+
}
175+
176+
// create CVM instance
177+
resource "tencentcloud_instance" "example" {
178+
instance_name = "tf-example"
179+
availability_zone = var.availability_zone
180+
image_id = data.tencentcloud_images.images.images.0.image_id
181+
instance_type = data.tencentcloud_instance_types.types.instance_types.0.instance_type
182+
dedicated_cluster_id = "cluster-lchwgxhs"
183+
instance_charge_type = "CDCPAID"
184+
system_disk_type = "CLOUD_PREMIUM"
185+
system_disk_size = 50
186+
hostname = "user"
187+
project_id = 0
188+
vpc_id = tencentcloud_vpc.vpc.id
189+
subnet_id = tencentcloud_subnet.subnet.id
190+
83191
data_disks {
84192
data_disk_type = "CLOUD_PREMIUM"
85193
data_disk_size = 50
86194
encrypt = false
87195
}
88-
force_delete = true
89-
tags = {
196+
197+
tags = {
90198
tagKey = "tagValue"
91199
}
92200
}
@@ -97,5 +205,5 @@ Import
97205
CVM instance can be imported using the id, e.g.
98206

99207
```
100-
terraform import tencentcloud_instance.foo ins-2qol3a80
101-
```
208+
terraform import tencentcloud_instance.example ins-2qol3a80
209+
```

0 commit comments

Comments
 (0)