provider/aws: Configurable timeouts for EC2 instance + spot instance (#14711)
This commit is contained in:
parent
a8d3971c20
commit
600e587430
|
@ -32,6 +32,12 @@ func resourceAwsInstance() *schema.Resource {
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
MigrateState: resourceAwsInstanceMigrateState,
|
MigrateState: resourceAwsInstanceMigrateState,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Create: schema.DefaultTimeout(10 * time.Minute),
|
||||||
|
Update: schema.DefaultTimeout(10 * time.Minute),
|
||||||
|
Delete: schema.DefaultTimeout(10 * time.Minute),
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"ami": {
|
"ami": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
@ -524,7 +530,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
Pending: []string{"pending"},
|
Pending: []string{"pending"},
|
||||||
Target: []string{"running"},
|
Target: []string{"running"},
|
||||||
Refresh: InstanceStateRefreshFunc(conn, *instance.InstanceId, "terminated"),
|
Refresh: InstanceStateRefreshFunc(conn, *instance.InstanceId, "terminated"),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutCreate),
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
}
|
}
|
||||||
|
@ -888,7 +894,7 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
Pending: []string{"pending", "running", "shutting-down", "stopped", "stopping"},
|
Pending: []string{"pending", "running", "shutting-down", "stopped", "stopping"},
|
||||||
Target: []string{"stopped"},
|
Target: []string{"stopped"},
|
||||||
Refresh: InstanceStateRefreshFunc(conn, d.Id(), ""),
|
Refresh: InstanceStateRefreshFunc(conn, d.Id(), ""),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutUpdate),
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
}
|
}
|
||||||
|
@ -919,7 +925,7 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
Pending: []string{"pending", "stopped"},
|
Pending: []string{"pending", "stopped"},
|
||||||
Target: []string{"running"},
|
Target: []string{"running"},
|
||||||
Refresh: InstanceStateRefreshFunc(conn, d.Id(), "terminated"),
|
Refresh: InstanceStateRefreshFunc(conn, d.Id(), "terminated"),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutUpdate),
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
}
|
}
|
||||||
|
@ -986,7 +992,7 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
func resourceAwsInstanceDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsInstanceDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
conn := meta.(*AWSClient).ec2conn
|
conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
if err := awsTerminateInstance(conn, d.Id()); err != nil {
|
if err := awsTerminateInstance(conn, d.Id(), d); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1573,7 +1579,7 @@ func buildAwsInstanceOpts(
|
||||||
return opts, nil
|
return opts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func awsTerminateInstance(conn *ec2.EC2, id string) error {
|
func awsTerminateInstance(conn *ec2.EC2, id string, d *schema.ResourceData) error {
|
||||||
log.Printf("[INFO] Terminating instance: %s", id)
|
log.Printf("[INFO] Terminating instance: %s", id)
|
||||||
req := &ec2.TerminateInstancesInput{
|
req := &ec2.TerminateInstancesInput{
|
||||||
InstanceIds: []*string{aws.String(id)},
|
InstanceIds: []*string{aws.String(id)},
|
||||||
|
@ -1588,7 +1594,7 @@ func awsTerminateInstance(conn *ec2.EC2, id string) error {
|
||||||
Pending: []string{"pending", "running", "shutting-down", "stopped", "stopping"},
|
Pending: []string{"pending", "running", "shutting-down", "stopped", "stopping"},
|
||||||
Target: []string{"terminated"},
|
Target: []string{"terminated"},
|
||||||
Refresh: InstanceStateRefreshFunc(conn, id, ""),
|
Refresh: InstanceStateRefreshFunc(conn, id, ""),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutDelete),
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,11 @@ func resourceAwsSpotInstanceRequest() *schema.Resource {
|
||||||
Delete: resourceAwsSpotInstanceRequestDelete,
|
Delete: resourceAwsSpotInstanceRequestDelete,
|
||||||
Update: resourceAwsSpotInstanceRequestUpdate,
|
Update: resourceAwsSpotInstanceRequestUpdate,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Create: schema.DefaultTimeout(10 * time.Minute),
|
||||||
|
Delete: schema.DefaultTimeout(10 * time.Minute),
|
||||||
|
},
|
||||||
|
|
||||||
Schema: func() map[string]*schema.Schema {
|
Schema: func() map[string]*schema.Schema {
|
||||||
// The Spot Instance Request Schema is based on the AWS Instance schema.
|
// The Spot Instance Request Schema is based on the AWS Instance schema.
|
||||||
s := resourceAwsInstance().Schema
|
s := resourceAwsInstance().Schema
|
||||||
|
@ -157,7 +162,7 @@ func resourceAwsSpotInstanceRequestCreate(d *schema.ResourceData, meta interface
|
||||||
Pending: []string{"start", "pending-evaluation", "pending-fulfillment"},
|
Pending: []string{"start", "pending-evaluation", "pending-fulfillment"},
|
||||||
Target: []string{"fulfilled"},
|
Target: []string{"fulfilled"},
|
||||||
Refresh: SpotInstanceStateRefreshFunc(conn, sir),
|
Refresh: SpotInstanceStateRefreshFunc(conn, sir),
|
||||||
Timeout: 10 * time.Minute,
|
Timeout: d.Timeout(schema.TimeoutCreate),
|
||||||
Delay: 10 * time.Second,
|
Delay: 10 * time.Second,
|
||||||
MinTimeout: 3 * time.Second,
|
MinTimeout: 3 * time.Second,
|
||||||
}
|
}
|
||||||
|
@ -328,7 +333,7 @@ func resourceAwsSpotInstanceRequestDelete(d *schema.ResourceData, meta interface
|
||||||
|
|
||||||
if instanceId := d.Get("spot_instance_id").(string); instanceId != "" {
|
if instanceId := d.Get("spot_instance_id").(string); instanceId != "" {
|
||||||
log.Printf("[INFO] Terminating instance: %s", instanceId)
|
log.Printf("[INFO] Terminating instance: %s", instanceId)
|
||||||
if err := awsTerminateInstance(conn, instanceId); err != nil {
|
if err := awsTerminateInstance(conn, instanceId, d); err != nil {
|
||||||
return fmt.Errorf("Error terminating spot instance: %s", err)
|
return fmt.Errorf("Error terminating spot instance: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,8 +89,15 @@ instances. See [Shutdown Behavior](https://docs.aws.amazon.com/AWSEC2/latest/Use
|
||||||
"Instance Store") volumes on the instance. See [Block Devices](#block-devices) below for details.
|
"Instance Store") volumes on the instance. See [Block Devices](#block-devices) below for details.
|
||||||
* `network_interface` - (Optional) Customize network interfaces to be attached at instance boot time. See [Network Interfaces](#network-interfaces) below for more details.
|
* `network_interface` - (Optional) Customize network interfaces to be attached at instance boot time. See [Network Interfaces](#network-interfaces) below for more details.
|
||||||
|
|
||||||
|
### Timeouts
|
||||||
|
|
||||||
## Block devices
|
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
|
||||||
|
|
||||||
|
* `create` - (Defaults to 10 mins) Used when launching the instance (until it reaches the initial `running` state)
|
||||||
|
* `update` - (Defaults to 10 mins) Used when stopping and starting the instance when necessary during update - e.g. when changing instance type
|
||||||
|
* `delete` - (Defaults to 10 mins) Used when terminating the instance
|
||||||
|
|
||||||
|
### Block devices
|
||||||
|
|
||||||
Each of the `*_block_device` attributes controls a portion of the AWS
|
Each of the `*_block_device` attributes controls a portion of the AWS
|
||||||
Instance's "Block Device Mapping". It's a good idea to familiarize yourself with [AWS's Block Device
|
Instance's "Block Device Mapping". It's a good idea to familiarize yourself with [AWS's Block Device
|
||||||
|
@ -151,7 +158,7 @@ resources cannot be automatically detected by Terraform. After making updates
|
||||||
to block device configuration, resource recreation can be manually triggered by
|
to block device configuration, resource recreation can be manually triggered by
|
||||||
using the [`taint` command](/docs/commands/taint.html).
|
using the [`taint` command](/docs/commands/taint.html).
|
||||||
|
|
||||||
## Network Interfaces
|
### Network Interfaces
|
||||||
|
|
||||||
Each of the `network_interface` blocks attach a network interface to an EC2 Instance during boot time. However, because
|
Each of the `network_interface` blocks attach a network interface to an EC2 Instance during boot time. However, because
|
||||||
the network interface is attached at boot-time, replacing/modifying the network interface **WILL** trigger a recreation
|
the network interface is attached at boot-time, replacing/modifying the network interface **WILL** trigger a recreation
|
||||||
|
|
|
@ -59,6 +59,13 @@ Spot Instance Requests support all the same arguments as
|
||||||
The duration period starts as soon as your Spot instance receives its instance ID. At the end of the duration period, Amazon EC2 marks the Spot instance for termination and provides a Spot instance termination notice, which gives the instance a two-minute warning before it terminates.
|
The duration period starts as soon as your Spot instance receives its instance ID. At the end of the duration period, Amazon EC2 marks the Spot instance for termination and provides a Spot instance termination notice, which gives the instance a two-minute warning before it terminates.
|
||||||
Note that you can't specify an Availability Zone group or a launch group if you specify a duration.
|
Note that you can't specify an Availability Zone group or a launch group if you specify a duration.
|
||||||
|
|
||||||
|
### Timeouts
|
||||||
|
|
||||||
|
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
|
||||||
|
|
||||||
|
* `create` - (Defaults to 10 mins) Used when requesting the spot instance (only valid if `wait_for_fulfillment = true`)
|
||||||
|
* `delete` - (Defaults to 10 mins) Used when terminating all instances launched via the given spot instance request
|
||||||
|
|
||||||
## Attributes Reference
|
## Attributes Reference
|
||||||
|
|
||||||
The following attributes are exported:
|
The following attributes are exported:
|
||||||
|
|
Loading…
Reference in New Issue