Skip to content

Commit

Permalink
resource/alicloud_instance: Added the field password_inherit, create_…
Browse files Browse the repository at this point in the history
…time, start_time, expired_time
  • Loading branch information
MrWolong authored and ChenHanZhang committed Oct 17, 2024
1 parent fc33ccb commit 5de90e5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
26 changes: 26 additions & 0 deletions alicloud/resource_alicloud_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func resourceAliCloudInstance() *schema.Resource {
},
Elem: schema.TypeString,
},
"password_inherit": {
Type: schema.TypeBool,
Optional: true,
},
"io_optimized": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -667,6 +671,18 @@ func resourceAliCloudInstance() *schema.Resource {
Optional: true,
Computed: true,
},
"create_time": {
Type: schema.TypeString,
Computed: true,
},
"start_time": {
Type: schema.TypeString,
Computed: true,
},
"expired_time": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -796,6 +812,10 @@ func resourceAliCloudInstanceCreate(d *schema.ResourceData, meta interface{}) er
request["Password"] = decryptResp
}

if v, ok := d.GetOkExists("password_inherit"); ok {
request["PasswordInherit"] = v
}

vswitchValue := d.Get("vswitch_id")
if vswitchValue == "" {
vswitchValue = d.Get("subnet_id")
Expand Down Expand Up @@ -1198,6 +1218,9 @@ func resourceAliCloudInstanceRead(d *schema.ResourceData, meta interface{}) erro
d.Set("os_name", instance.OSName)
d.Set("os_type", instance.OSType)
d.Set("dedicated_host_id", instance.DedicatedHostAttribute.DedicatedHostId)
d.Set("create_time", instance.CreationTime)
d.Set("start_time", instance.StartTime)
d.Set("expired_time", instance.ExpiredTime)

if len(instance.VpcAttributes.PrivateIpAddress.IpAddress) > 0 {
d.Set("private_ip", instance.VpcAttributes.PrivateIpAddress.IpAddress[0])
Expand Down Expand Up @@ -2155,6 +2178,9 @@ func modifyInstanceImage(d *schema.ResourceData, meta interface{}, run bool) (bo
if v, ok := d.GetOk("password"); ok {
request.Password = v.(string)
}
if v, ok := d.GetOkExists("password_inherit"); ok {
request.PasswordInherit = requests.NewBoolean(v.(bool))
}
if v, ok := d.GetOk("system_disk_kms_key_id"); ok {
request.KMSKeyId = v.(string)
}
Expand Down
6 changes: 5 additions & 1 deletion alicloud/resource_alicloud_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,7 @@ func TestAccAliCloudECSInstanceIpv6Addresses(t *testing.T) {
"security_enhancement_strategy": "Active",
"user_data": "I_am_user_data",
"vswitch_id": "${alicloud_vswitch.vswitch.id}",
"password_inherit": "true",
"ipv6_addresses": []string{"${cidrhost(alicloud_vswitch.vswitch.ipv6_cidr_block, 64)}"},
}),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -2534,7 +2535,7 @@ func TestAccAliCloudECSInstanceIpv6Addresses(t *testing.T) {
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"security_enhancement_strategy", "dry_run"},
ImportStateVerifyIgnore: []string{"security_enhancement_strategy", "password_inherit", "dry_run"},
},
},
})
Expand Down Expand Up @@ -3144,6 +3145,9 @@ var testAccInstanceCheckMap = map[string]string{
"include_data_disks": NOSET,
"dry_run": "false",
"system_disk_id": CHECKSET,
"create_time": CHECKSET,
"start_time": CHECKSET,
"expired_time": CHECKSET,
}

func TestAccAliCloudECSInstance_OperatorType(t *testing.T) {
Expand Down
9 changes: 7 additions & 2 deletions website/docs/r/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ The following arguments are supported:
- `HighPerformance`: Uses the remote direct memory access (RDMA) communication mode with Elastic RDMA Interface (ERI) enabled.
* `network_card_index` - (Optional, ForceNew, Int, Available since v1.227.1) The index of the network card for Primary ENI.
* `queue_pair_number` - (Optional, ForceNew, Int, Available since v1.227.1) The number of queues supported by the ERI.
* `password_inherit` - (Optional, Bool, Available since v1.231.1) Specifies whether to use the password preset in the image. Default value: `false`. Valid values:
- `true`: Uses the preset password.
- `false`: Does not use the preset password.
-> **NOTE:** If you set `password_inherit` to `true`, make sure that you have not specified `password` or `kms_encrypted_password` and the selected image has a preset password.

-> **NOTE:** System disk category `cloud` has been outdated and it only can be used none I/O Optimized ECS instances. Recommend `cloud_efficiency` and `cloud_ssd` disk.

Expand Down Expand Up @@ -315,6 +319,9 @@ The following attributes are exported:
* `system_disk_id` - (Available since v1.210.0) The ID of system disk.
* `primary_ip_address` - The primary private IP address of the ENI.
* `deployment_set_group_no` - The group number of the instance in a deployment set when the deployment set is use.
* `create_time` - (Available since v1.231.1) The time when the instance was created.
* `start_time` - (Available since v1.231.1) The time when the instance was last started.
* `expired_time` - (Available since v1.231.1) The expiration time of the instance.

## Timeouts

Expand All @@ -327,8 +334,6 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d
* `update` - (Defaults to 10 mins) Used when stopping and starting the instance when necessary during update - e.g. when changing instance type, password, image, vswitch and private IP.
* `delete` - (Defaults to 20 mins) Used when terminating the instance. `Note`: There are extra at most 5 minutes used to retry to avoid some needless API errors, and it is not in the timeouts configure.



## Import

Instance can be imported using the id, e.g.
Expand Down

0 comments on commit 5de90e5

Please sign in to comment.