Skip to content

Commit b4291c1

Browse files
authored
Merge branch 'master' into fix-clb
2 parents 93a03f2 + d6b21d5 commit b4291c1

File tree

5 files changed

+107
-46
lines changed

5 files changed

+107
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
ENHANCEMENTS:
44

55
* Resource: `tencentcloud_clb_listener_rule` add new argument `forward_type` to support backend protocol([#522](https://github.com/tencentcloudstack/terraform-provider-tencentcloud/issues/522))
6+
* Resource: `tencentcloud_instance` add new argument `keep_image_login` to support keeping image login.
67

78
## 1.44.0 (September 25, 2020)
89

tencentcloud/extension_cvm.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ const (
4444
CVM_SPOT_INSTANCE_TYPE_ONE_TIME = "ONE-TIME"
4545

4646
CVM_MARKET_TYPE_SPOT = "spot"
47+
48+
CVM_IMAGE_LOGIN = "TRUE"
49+
CVM_IMAGE_LOGIN_NOT = "FALSE"
4750
)
4851

4952
var CVM_CHARGE_TYPE = []string{

tencentcloud/resource_tc_instance.go

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,51 +107,51 @@ func resourceTencentCloudInstance() *schema.Resource {
107107
Type: schema.TypeString,
108108
Required: true,
109109
ForceNew: true,
110-
Description: "The Image to use for the instance. Change 'image_id' will case instance destroy and re-created.",
110+
Description: "The image to use for the instance. Changing `image_id` will cause the instance to be destroyed and re-created.",
111111
},
112112
"availability_zone": {
113113
Type: schema.TypeString,
114114
Required: true,
115115
ForceNew: true,
116-
Description: "The available zone that the CVM instance locates at.",
116+
Description: "The available zone for the CVM instance.",
117117
},
118118
"instance_name": {
119119
Type: schema.TypeString,
120120
Optional: true,
121121
Default: "Terraform-CVM-Instance",
122122
ValidateFunc: validateStringLengthInRange(2, 128),
123-
Description: "The name of the CVM. The max length of instance_name is 60, and default value is `Terraform-CVM-Instance`.",
123+
Description: "The name of the instance. The max length of instance_name is 60, and default value is `Terraform-CVM-Instance`.",
124124
},
125125
"instance_type": {
126126
Type: schema.TypeString,
127127
Optional: true,
128128
Computed: true,
129129
ValidateFunc: validateInstanceType,
130-
Description: "The type of instance to start.",
130+
Description: "The type of the instance.",
131131
},
132132
"hostname": {
133133
Type: schema.TypeString,
134134
Optional: true,
135135
ForceNew: true,
136-
Description: "The hostname of CVM. 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 (-).",
136+
Description: "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 (-).",
137137
},
138138
"project_id": {
139139
Type: schema.TypeInt,
140140
Optional: true,
141141
Default: 0,
142-
Description: "The project CVM belongs to, default to 0.",
142+
Description: "The project the instance belongs to, default to 0.",
143143
},
144144
"running_flag": {
145145
Type: schema.TypeBool,
146146
Optional: true,
147147
Default: true,
148-
Description: "Set instance to running or stop. Default value is true, the instance will shutdown when flag is false.",
148+
Description: "Set instance to running or stop. Default value is true, the instance will shutdown when this flag is false.",
149149
},
150150
"placement_group_id": {
151151
Type: schema.TypeString,
152152
Optional: true,
153153
ForceNew: true,
154-
Description: "The id of a placement group.",
154+
Description: "The ID of a placement group.",
155155
},
156156
// payment
157157
"instance_charge_type": {
@@ -186,7 +186,7 @@ func resourceTencentCloudInstance() *schema.Resource {
186186
Optional: true,
187187
ForceNew: true,
188188
ValidateFunc: validateStringNumber,
189-
Description: "Max price of spot instance, is the format of decimal string, for example \"0.50\". Note: it only works when instance_charge_type is set to `SPOTPAID`.",
189+
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`.",
190190
},
191191
// network
192192
"internet_charge_type": {
@@ -201,41 +201,41 @@ func resourceTencentCloudInstance() *schema.Resource {
201201
Type: schema.TypeInt,
202202
Optional: true,
203203
Computed: true,
204-
Description: "Maximum outgoing bandwidth to the public network, measured in Mbps (Mega bit per second). This value does not need to be set when `allocate_public_ip` is false.",
204+
Description: "Maximum outgoing bandwidth to the public network, measured in Mbps (Mega bits per second). This value does not need to be set when `allocate_public_ip` is false.",
205205
},
206206
"allocate_public_ip": {
207207
Type: schema.TypeBool,
208208
Optional: true,
209209
Default: false,
210210
ForceNew: true,
211-
Description: "Associate a public ip address with an instance in a VPC or Classic. Boolean value, Default is false.",
211+
Description: "Associate a public IP address with an instance in a VPC or Classic. Boolean value, Default is false.",
212212
},
213213
// vpc
214214
"vpc_id": {
215215
Type: schema.TypeString,
216216
Optional: true,
217217
Computed: true,
218-
Description: "The id of a VPC network. If you want to create instances in VPC network, this parameter must be set.",
218+
Description: "The ID of a VPC network. If you want to create instances in a VPC network, this parameter must be set.",
219219
},
220220
"subnet_id": {
221221
Type: schema.TypeString,
222222
Optional: true,
223223
Computed: true,
224-
Description: "The id of a VPC subnetwork. If you want to create instances in VPC network, this parameter must be set.",
224+
Description: "The ID of a VPC subnet. If you want to create instances in a VPC network, this parameter must be set.",
225225
},
226226
"private_ip": {
227227
Type: schema.TypeString,
228228
Optional: true,
229229
Computed: true,
230-
Description: "The private ip to be assigned to this instance, must be in the provided subnet and available.",
230+
Description: "The private IP to be assigned to this instance, must be in the provided subnet and available.",
231231
},
232232
// security group
233233
"security_groups": {
234234
Type: schema.TypeSet,
235235
Elem: &schema.Schema{Type: schema.TypeString},
236236
Optional: true,
237237
Computed: true,
238-
Description: "A list of security group ids to associate with.",
238+
Description: "A list of security group IDs to associate with.",
239239
},
240240
// storage
241241
"system_disk_type": {
@@ -252,7 +252,7 @@ func resourceTencentCloudInstance() *schema.Resource {
252252
Default: 50,
253253
ForceNew: true,
254254
ValidateFunc: validateIntegerInRange(50, 1000),
255-
Description: "Size of the system disk. Value range: [50, 1000], and unit is GB. Default is 50GB.",
255+
Description: "Size of the system disk. Value range: [50, 1000], and the unit is GB. Default is 50GB.",
256256
},
257257
"system_disk_id": {
258258
Type: schema.TypeString,
@@ -266,7 +266,7 @@ func resourceTencentCloudInstance() *schema.Resource {
266266
Optional: true,
267267
Computed: true,
268268
ForceNew: true,
269-
Description: "Settings for data disk.",
269+
Description: "Settings for data disks.",
270270
Elem: &schema.Resource{
271271
Schema: map[string]*schema.Schema{
272272
"data_disk_type": {
@@ -330,27 +330,35 @@ func resourceTencentCloudInstance() *schema.Resource {
330330
Type: schema.TypeString,
331331
Optional: true,
332332
Computed: true,
333-
Description: "The key pair to use for the instance, it looks like skey-16jig7tx.",
333+
Description: "The key pair to use for the instance, it looks like `skey-16jig7tx`.",
334334
},
335335
"password": {
336336
Type: schema.TypeString,
337337
Optional: true,
338338
Sensitive: true,
339-
Description: "Password to an instance. In order to take effect new password, the instance will be restarted after modifying the password.",
339+
Description: "Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change.",
340+
},
341+
"keep_image_login": {
342+
Type: schema.TypeBool,
343+
Optional: true,
344+
Default: false,
345+
ForceNew: true,
346+
ConflictsWith: []string{"key_name", "password"},
347+
Description: "Whether to keep image login or not, default is `false`. When the image type is private or shared or imported, this parameter can be set `true`.",
340348
},
341349
"user_data": {
342350
Type: schema.TypeString,
343351
Optional: true,
344352
ForceNew: true,
345353
ConflictsWith: []string{"user_data_raw"},
346-
Description: "The user data to be specified into this instance. Must be encrypted in base64 format and limited in 16 KB.",
354+
Description: "The user data to be injected into this instance. Must be base64 encoded and up to 16 KB.",
347355
},
348356
"user_data_raw": {
349357
Type: schema.TypeString,
350358
Optional: true,
351359
ForceNew: true,
352360
ConflictsWith: []string{"user_data"},
353-
Description: "The user data to be specified into this instance, plain text. Conflicts with `user_data`. Limited in 16 KB after encrypted in base64 format.",
361+
Description: "The user data to be injected into this instance, in plain text. Conflicts with `user_data`. Up to 16 KB after base64 encoded.",
354362
},
355363
"tags": {
356364
Type: schema.TypeMap,
@@ -361,7 +369,7 @@ func resourceTencentCloudInstance() *schema.Resource {
361369
Type: schema.TypeBool,
362370
Optional: true,
363371
Default: false,
364-
Description: "Indicate whether to delete instance directly or not. Default is false. If set true, the instance will be permanently deleted instead of staying in recycle bin. Note: only works for `PREPAID` instance.",
372+
Description: "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.",
365373
},
366374
// Computed values.
367375
"instance_status": {
@@ -372,7 +380,7 @@ func resourceTencentCloudInstance() *schema.Resource {
372380
"public_ip": {
373381
Type: schema.TypeString,
374382
Computed: true,
375-
Description: "Public ip of the instance.",
383+
Description: "Public IP of the instance.",
376384
},
377385
"create_time": {
378386
Type: schema.TypeString,
@@ -554,6 +562,12 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
554562
if v, ok := d.GetOk("password"); ok {
555563
request.LoginSettings.Password = helper.String(v.(string))
556564
}
565+
v := d.Get("keep_image_login").(bool)
566+
if v {
567+
request.LoginSettings.KeepImageLogin = helper.String(CVM_IMAGE_LOGIN)
568+
} else {
569+
request.LoginSettings.KeepImageLogin = helper.String(CVM_IMAGE_LOGIN_NOT)
570+
}
557571

558572
if v, ok := d.GetOk("user_data"); ok {
559573
request.UserData = helper.String(v.(string))
@@ -778,6 +792,9 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
778792
} else {
779793
_ = d.Set("key_name", "")
780794
}
795+
if instance.LoginSettings.KeepImageLogin != nil {
796+
_ = d.Set("keep_image_login", *instance.LoginSettings.KeepImageLogin == CVM_IMAGE_LOGIN)
797+
}
781798
if *instance.InstanceState == CVM_STATUS_STOPPED {
782799
_ = d.Set("running_flag", false)
783800
} else {

tencentcloud/resource_tc_instance_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,29 @@ func TestAccTencentCloudInstanceWithPassword(t *testing.T) {
241241
})
242242
}
243243

244+
func TestAccTencentCloudInstanceWithImageLogin(t *testing.T) {
245+
t.Parallel()
246+
247+
id := "tencentcloud_instance.foo"
248+
resource.Test(t, resource.TestCase{
249+
PreCheck: func() { testAccPreCheck(t) },
250+
IDRefreshName: id,
251+
Providers: testAccProviders,
252+
CheckDestroy: testAccCheckInstanceDestroy,
253+
Steps: []resource.TestStep{
254+
{
255+
Config: testAccTencentCloudInstanceWithImageLogin,
256+
Check: resource.ComposeTestCheckFunc(
257+
testAccCheckTencentCloudDataSourceID(id),
258+
testAccCheckTencentCloudInstanceExists(id),
259+
resource.TestCheckResourceAttr(id, "instance_status", "RUNNING"),
260+
resource.TestCheckResourceAttr(id, "keep_image_login", "true"),
261+
),
262+
},
263+
},
264+
})
265+
}
266+
244267
func TestAccTencentCloudInstanceWithName(t *testing.T) {
245268
t.Parallel()
246269

@@ -659,6 +682,22 @@ resource "tencentcloud_instance" "foo" {
659682
)
660683
}
661684

685+
const testAccTencentCloudInstanceWithImageLogin = defaultInstanceVariable + `
686+
data "tencentcloud_images" "zoo" {
687+
image_type = ["PRIVATE_IMAGE"]
688+
os_name = "centos"
689+
}
690+
resource "tencentcloud_instance" "foo" {
691+
instance_name = var.instance_name
692+
availability_zone = data.tencentcloud_availability_zones.default.zones.0.name
693+
image_id = data.tencentcloud_images.zoo.images.0.image_id
694+
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
695+
internet_max_bandwidth_out = 1
696+
keep_image_login = true
697+
system_disk_type = "CLOUD_PREMIUM"
698+
}
699+
`
700+
662701
func testAccTencentCloudInstanceWithName(instanceName string) string {
663702
return fmt.Sprintf(
664703
defaultInstanceVariable+`

0 commit comments

Comments
 (0)