Skip to content

Commit d6b21d5

Browse files
authored
Merge pull request #527 from gailwang/master
add keep_image_login with resource CVM
2 parents 8ce54b8 + cf2a638 commit d6b21d5

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
## 1.44.1 (Unreleased)
2+
3+
ENHANCEMENTS:
4+
5+
* Resource: `tencentcloud_instance` add new argument `keep_image_login` to support keeping image login.
6+
27
## 1.44.0 (September 25, 2020)
38

49
FEATURES:

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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,14 @@ func resourceTencentCloudInstance() *schema.Resource {
338338
Sensitive: true,
339339
Description: "Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change.",
340340
},
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`.",
348+
},
341349
"user_data": {
342350
Type: schema.TypeString,
343351
Optional: true,
@@ -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+`

website/docs/r/instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ The following arguments are supported:
9595
* `instance_type` - (Optional) The type of the instance.
9696
* `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.
9797
* `internet_max_bandwidth_out` - (Optional) 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.
98+
* `keep_image_login` - (Optional, ForceNew) 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`.
9899
* `key_name` - (Optional) The key pair to use for the instance, it looks like `skey-16jig7tx`.
99100
* `password` - (Optional) Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change.
100101
* `placement_group_id` - (Optional, ForceNew) The ID of a placement group.

0 commit comments

Comments
 (0)