Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 1.44.1 (Unreleased)

ENHANCEMENTS:

* Resource: `tencentcloud_instance` add new argument `keep_image_login` to support keeping image login.

## 1.44.0 (September 25, 2020)

FEATURES:
Expand Down
3 changes: 3 additions & 0 deletions tencentcloud/extension_cvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const (
CVM_SPOT_INSTANCE_TYPE_ONE_TIME = "ONE-TIME"

CVM_MARKET_TYPE_SPOT = "spot"

CVM_IMAGE_LOGIN = "TRUE"
CVM_IMAGE_LOGIN_NOT = "FALSE"
)

var CVM_CHARGE_TYPE = []string{
Expand Down
17 changes: 17 additions & 0 deletions tencentcloud/resource_tc_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ func resourceTencentCloudInstance() *schema.Resource {
Sensitive: true,
Description: "Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change.",
},
"keep_image_login": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
ConflictsWith: []string{"key_name", "password"},
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`.",
},
"user_data": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -554,6 +562,12 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
if v, ok := d.GetOk("password"); ok {
request.LoginSettings.Password = helper.String(v.(string))
}
v := d.Get("keep_image_login").(bool)
if v {
request.LoginSettings.KeepImageLogin = helper.String(CVM_IMAGE_LOGIN)
} else {
request.LoginSettings.KeepImageLogin = helper.String(CVM_IMAGE_LOGIN_NOT)
}

if v, ok := d.GetOk("user_data"); ok {
request.UserData = helper.String(v.(string))
Expand Down Expand Up @@ -778,6 +792,9 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
} else {
_ = d.Set("key_name", "")
}
if instance.LoginSettings.KeepImageLogin != nil {
_ = d.Set("keep_image_login", *instance.LoginSettings.KeepImageLogin == CVM_IMAGE_LOGIN)
}
if *instance.InstanceState == CVM_STATUS_STOPPED {
_ = d.Set("running_flag", false)
} else {
Expand Down
39 changes: 39 additions & 0 deletions tencentcloud/resource_tc_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,29 @@ func TestAccTencentCloudInstanceWithPassword(t *testing.T) {
})
}

func TestAccTencentCloudInstanceWithImageLogin(t *testing.T) {
t.Parallel()

id := "tencentcloud_instance.foo"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: id,
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccTencentCloudInstanceWithImageLogin,
Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID(id),
testAccCheckTencentCloudInstanceExists(id),
resource.TestCheckResourceAttr(id, "instance_status", "RUNNING"),
resource.TestCheckResourceAttr(id, "keep_image_login", "true"),
),
},
},
})
}

func TestAccTencentCloudInstanceWithName(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -659,6 +682,22 @@ resource "tencentcloud_instance" "foo" {
)
}

const testAccTencentCloudInstanceWithImageLogin = defaultInstanceVariable + `
data "tencentcloud_images" "zoo" {
image_type = ["PRIVATE_IMAGE"]
os_name = "centos"
}
resource "tencentcloud_instance" "foo" {
instance_name = var.instance_name
availability_zone = data.tencentcloud_availability_zones.default.zones.0.name
image_id = data.tencentcloud_images.zoo.images.0.image_id
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
internet_max_bandwidth_out = 1
keep_image_login = true
system_disk_type = "CLOUD_PREMIUM"
}
`

func testAccTencentCloudInstanceWithName(instanceName string) string {
return fmt.Sprintf(
defaultInstanceVariable+`
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ The following arguments are supported:
* `instance_type` - (Optional) The type of the instance.
* `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.
* `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.
* `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`.
* `key_name` - (Optional) The key pair to use for the instance, it looks like `skey-16jig7tx`.
* `password` - (Optional) Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change.
* `placement_group_id` - (Optional, ForceNew) The ID of a placement group.
Expand Down