Merge pull request #2887 from hashicorp/f-aws-pr-2779
provider/aws/aws_instance: add instance_initiated_shutdown_behavior (supersedes 2779)
This commit is contained in:
commit
79bd3a318d
|
@ -147,6 +147,11 @@ func resourceAwsInstance() *schema.Resource {
|
|||
Optional: true,
|
||||
},
|
||||
|
||||
"instance_initiated_shutdown_behavior": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"monitoring": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
|
@ -331,6 +336,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
Monitoring: instanceOpts.Monitoring,
|
||||
IamInstanceProfile: instanceOpts.IAMInstanceProfile,
|
||||
ImageId: instanceOpts.ImageID,
|
||||
InstanceInitiatedShutdownBehavior: instanceOpts.InstanceInitiatedShutdownBehavior,
|
||||
InstanceType: instanceOpts.InstanceType,
|
||||
KeyName: instanceOpts.KeyName,
|
||||
MaxCount: aws.Int64(int64(1)),
|
||||
|
@ -578,6 +584,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
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("monitoring") {
|
||||
var mErr error
|
||||
if d.Get("monitoring").(bool) {
|
||||
|
@ -884,6 +903,7 @@ type awsInstanceOpts struct {
|
|||
Monitoring *ec2.RunInstancesMonitoringEnabled
|
||||
IAMInstanceProfile *ec2.IamInstanceProfileSpecification
|
||||
ImageID *string
|
||||
InstanceInitiatedShutdownBehavior *string
|
||||
InstanceType *string
|
||||
KeyName *string
|
||||
NetworkInterfaces []*ec2.InstanceNetworkInterfaceSpecification
|
||||
|
@ -907,6 +927,10 @@ func buildAwsInstanceOpts(
|
|||
InstanceType: aws.String(d.Get("instance_type").(string)),
|
||||
}
|
||||
|
||||
if v := d.Get("instance_initiated_shutdown_behavior").(string); v != "" {
|
||||
opts.InstanceInitiatedShutdownBehavior = aws.String(v)
|
||||
}
|
||||
|
||||
opts.Monitoring = &ec2.RunInstancesMonitoringEnabled{
|
||||
Enabled: aws.Bool(d.Get("monitoring").(bool)),
|
||||
}
|
||||
|
|
|
@ -36,6 +36,10 @@ 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 for the
|
||||
instance. Amazon defaults this to `stop` for EBS-backed instances and
|
||||
`terminate` for instance-store instances. Cannot be set on instance-store
|
||||
instances. See [Shutdown Behavior](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingInstanceInitiatedShutdownBehavior) for more information.
|
||||
* `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)
|
||||
|
|
Loading…
Reference in New Issue