diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index 8a03b607c..4315c25c3 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -32,6 +32,12 @@ func resourceAwsInstance() *schema.Resource { SchemaVersion: 1, 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{ "ami": { Type: schema.TypeString, @@ -524,7 +530,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error { Pending: []string{"pending"}, Target: []string{"running"}, Refresh: InstanceStateRefreshFunc(conn, *instance.InstanceId, "terminated"), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 10 * 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"}, Target: []string{"stopped"}, Refresh: InstanceStateRefreshFunc(conn, d.Id(), ""), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutUpdate), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } @@ -919,7 +925,7 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error { Pending: []string{"pending", "stopped"}, Target: []string{"running"}, Refresh: InstanceStateRefreshFunc(conn, d.Id(), "terminated"), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutUpdate), Delay: 10 * 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 { conn := meta.(*AWSClient).ec2conn - if err := awsTerminateInstance(conn, d.Id()); err != nil { + if err := awsTerminateInstance(conn, d.Id(), d); err != nil { return err } @@ -1573,7 +1579,7 @@ func buildAwsInstanceOpts( 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) req := &ec2.TerminateInstancesInput{ 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"}, Target: []string{"terminated"}, Refresh: InstanceStateRefreshFunc(conn, id, ""), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutDelete), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/aws/resource_aws_spot_instance_request.go b/builtin/providers/aws/resource_aws_spot_instance_request.go index d6caeb428..147c88f6d 100644 --- a/builtin/providers/aws/resource_aws_spot_instance_request.go +++ b/builtin/providers/aws/resource_aws_spot_instance_request.go @@ -19,6 +19,11 @@ func resourceAwsSpotInstanceRequest() *schema.Resource { Delete: resourceAwsSpotInstanceRequestDelete, Update: resourceAwsSpotInstanceRequestUpdate, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + Schema: func() map[string]*schema.Schema { // The Spot Instance Request Schema is based on the AWS Instance schema. s := resourceAwsInstance().Schema @@ -157,7 +162,7 @@ func resourceAwsSpotInstanceRequestCreate(d *schema.ResourceData, meta interface Pending: []string{"start", "pending-evaluation", "pending-fulfillment"}, Target: []string{"fulfilled"}, Refresh: SpotInstanceStateRefreshFunc(conn, sir), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 10 * 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 != "" { 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) } } diff --git a/website/source/docs/providers/aws/r/instance.html.markdown b/website/source/docs/providers/aws/r/instance.html.markdown index fea3c0cdb..b059b1a8d 100644 --- a/website/source/docs/providers/aws/r/instance.html.markdown +++ b/website/source/docs/providers/aws/r/instance.html.markdown @@ -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. * `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 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 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 the network interface is attached at boot-time, replacing/modifying the network interface **WILL** trigger a recreation diff --git a/website/source/docs/providers/aws/r/spot_instance_request.html.markdown b/website/source/docs/providers/aws/r/spot_instance_request.html.markdown index 89e4fb824..52cbb847f 100644 --- a/website/source/docs/providers/aws/r/spot_instance_request.html.markdown +++ b/website/source/docs/providers/aws/r/spot_instance_request.html.markdown @@ -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. 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 The following attributes are exported: