@@ -6,87 +6,195 @@ Provides a CVM instance resource.
6
6
7
7
Example Usage
8
8
9
+ Create a general POSTPAID_BY_HOUR CVM instance
10
+
9
11
``` 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"
13
19
}
14
20
15
- data "tencentcloud_instance_types" "my_favorite_instance_types " {
21
+ data "tencentcloud_instance_types" "types " {
16
22
filter {
17
23
name = "instance-family"
18
24
values = ["S1", "S2", "S3", "S4", "S5"]
19
25
}
20
26
21
- cpu_core_count = 2
27
+ cpu_core_count = 2
22
28
exclude_sold_out = true
23
29
}
24
30
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" {
30
33
cidr_block = "10.0.0.0/16"
31
- name = "awesome_app_vpc "
34
+ name = "vpc "
32
35
}
33
36
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"
38
42
cidr_block = "10.0.1.0/24"
39
43
}
40
44
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
53
57
54
58
data_disks {
55
59
data_disk_type = "CLOUD_PREMIUM"
56
60
data_disk_size = 50
57
- encrypt = false
61
+ encrypt = false
58
62
}
59
63
60
64
tags = {
61
65
tagKey = "tagValue"
62
66
}
63
67
}
68
+ ```
64
69
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"]
69
86
}
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
74
112
system_disk_type = "CLOUD_PREMIUM"
75
113
system_disk_size = 50
76
114
hostname = "user"
77
115
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
80
118
instance_charge_type = "PREPAID"
81
119
instance_charge_type_prepaid_period = 1
82
120
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
+
83
191
data_disks {
84
192
data_disk_type = "CLOUD_PREMIUM"
85
193
data_disk_size = 50
86
194
encrypt = false
87
195
}
88
- force_delete = true
89
- tags = {
196
+
197
+ tags = {
90
198
tagKey = "tagValue"
91
199
}
92
200
}
@@ -97,5 +205,5 @@ Import
97
205
CVM instance can be imported using the id, e.g.
98
206
99
207
```
100
- terraform import tencentcloud_instance.foo ins-2qol3a80
101
- ```
208
+ terraform import tencentcloud_instance.example ins-2qol3a80
209
+ ```
0 commit comments