provider/aws/aws_instance: add new argument `instance_initiated_shutdown_behavior`,

accepts string values of 'stop' or 'terminate'.

Signed-off-by: Marc Tamsky <tamsky@users.noreply.github.com>
This commit is contained in:
Marc Tamsky 2015-07-18 09:45:34 -07:00
parent 009dba178f
commit 521451db4d
2 changed files with 24 additions and 0 deletions

View File

@ -148,6 +148,12 @@ func resourceAwsInstance() *schema.Resource {
Optional: true,
},
"instance_initiated_shutdown_behavior": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "stop",
},
"monitoring": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
@ -333,6 +339,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
IAMInstanceProfile: instanceOpts.IAMInstanceProfile,
ImageID: instanceOpts.ImageID,
InstanceType: instanceOpts.InstanceType,
InstanceInitiatedShutdownBehavior: instanceOpts.InstanceInitiatedShutdownBehavior,
KeyName: instanceOpts.KeyName,
MaxCount: aws.Long(int64(1)),
MinCount: aws.Long(int64(1)),
@ -579,6 +586,19 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
}
}
if d.HasChange("instance_initiated_shutdown_behavior") {
log.Printf("[INFO] Modifying instance %s", d.Id())
_, err := conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
InstanceID: aws.String(d.Id()),
InstanceInitiatedShutdownBehavior: &ec2.AttributeValue{
Value: aws.String(d.Get("instance_initiated_shutdown_behavior").(string)),
},
})
if err != nil {
return err
}
}
// TODO(mitchellh): wait for the attributes we modified to
// persist the change...
@ -864,6 +884,7 @@ type awsInstanceOpts struct {
IAMInstanceProfile *ec2.IAMInstanceProfileSpecification
ImageID *string
InstanceType *string
InstanceInitiatedShutdownBehavior *string
KeyName *string
NetworkInterfaces []*ec2.InstanceNetworkInterfaceSpecification
Placement *ec2.Placement
@ -884,6 +905,7 @@ func buildAwsInstanceOpts(
EBSOptimized: aws.Boolean(d.Get("ebs_optimized").(bool)),
ImageID: aws.String(d.Get("ami").(string)),
InstanceType: aws.String(d.Get("instance_type").(string)),
InstanceInitiatedShutdownBehavior: aws.String(d.Get("instance_initiated_shutdown_behavior").(string)),
}
opts.Monitoring = &ec2.RunInstancesMonitoringEnabled{

View File

@ -36,6 +36,8 @@ The following arguments are supported:
EBS-optimized.
* `disable_api_termination` - (Optional) If true, enables [EC2 Instance
Termination Protection](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingDisableAPITermination)
* `instance_initiated_shutdown_behavior` - (Optional) [Shutdown Behavior](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingInstanceInitiatedShutdownBehavior) Can be `"stop"`
or `"terminate"`. (Default: `"stop"`)
* `instance_type` - (Required) The type of instance to start
* `key_name` - (Optional) The key name to use for the instance.
* `monitoring` - (Optional) If true, the launched EC2 instance will have detailed monitoring enabled. (Available since v0.6.0)