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,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"instance_initiated_shutdown_behavior": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
|
||||||
"monitoring": &schema.Schema{
|
"monitoring": &schema.Schema{
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
@ -331,17 +336,18 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
Monitoring: instanceOpts.Monitoring,
|
Monitoring: instanceOpts.Monitoring,
|
||||||
IamInstanceProfile: instanceOpts.IAMInstanceProfile,
|
IamInstanceProfile: instanceOpts.IAMInstanceProfile,
|
||||||
ImageId: instanceOpts.ImageID,
|
ImageId: instanceOpts.ImageID,
|
||||||
InstanceType: instanceOpts.InstanceType,
|
InstanceInitiatedShutdownBehavior: instanceOpts.InstanceInitiatedShutdownBehavior,
|
||||||
KeyName: instanceOpts.KeyName,
|
InstanceType: instanceOpts.InstanceType,
|
||||||
MaxCount: aws.Int64(int64(1)),
|
KeyName: instanceOpts.KeyName,
|
||||||
MinCount: aws.Int64(int64(1)),
|
MaxCount: aws.Int64(int64(1)),
|
||||||
NetworkInterfaces: instanceOpts.NetworkInterfaces,
|
MinCount: aws.Int64(int64(1)),
|
||||||
Placement: instanceOpts.Placement,
|
NetworkInterfaces: instanceOpts.NetworkInterfaces,
|
||||||
PrivateIpAddress: instanceOpts.PrivateIPAddress,
|
Placement: instanceOpts.Placement,
|
||||||
SecurityGroupIds: instanceOpts.SecurityGroupIDs,
|
PrivateIpAddress: instanceOpts.PrivateIPAddress,
|
||||||
SecurityGroups: instanceOpts.SecurityGroups,
|
SecurityGroupIds: instanceOpts.SecurityGroupIDs,
|
||||||
SubnetId: instanceOpts.SubnetID,
|
SecurityGroups: instanceOpts.SecurityGroups,
|
||||||
UserData: instanceOpts.UserData64,
|
SubnetId: instanceOpts.SubnetID,
|
||||||
|
UserData: instanceOpts.UserData64,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the instance
|
// Create the instance
|
||||||
|
@ -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") {
|
if d.HasChange("monitoring") {
|
||||||
var mErr error
|
var mErr error
|
||||||
if d.Get("monitoring").(bool) {
|
if d.Get("monitoring").(bool) {
|
||||||
|
@ -878,22 +897,23 @@ func readBlockDeviceMappingsFromConfig(
|
||||||
}
|
}
|
||||||
|
|
||||||
type awsInstanceOpts struct {
|
type awsInstanceOpts struct {
|
||||||
BlockDeviceMappings []*ec2.BlockDeviceMapping
|
BlockDeviceMappings []*ec2.BlockDeviceMapping
|
||||||
DisableAPITermination *bool
|
DisableAPITermination *bool
|
||||||
EBSOptimized *bool
|
EBSOptimized *bool
|
||||||
Monitoring *ec2.RunInstancesMonitoringEnabled
|
Monitoring *ec2.RunInstancesMonitoringEnabled
|
||||||
IAMInstanceProfile *ec2.IamInstanceProfileSpecification
|
IAMInstanceProfile *ec2.IamInstanceProfileSpecification
|
||||||
ImageID *string
|
ImageID *string
|
||||||
InstanceType *string
|
InstanceInitiatedShutdownBehavior *string
|
||||||
KeyName *string
|
InstanceType *string
|
||||||
NetworkInterfaces []*ec2.InstanceNetworkInterfaceSpecification
|
KeyName *string
|
||||||
Placement *ec2.Placement
|
NetworkInterfaces []*ec2.InstanceNetworkInterfaceSpecification
|
||||||
PrivateIPAddress *string
|
Placement *ec2.Placement
|
||||||
SecurityGroupIDs []*string
|
PrivateIPAddress *string
|
||||||
SecurityGroups []*string
|
SecurityGroupIDs []*string
|
||||||
SpotPlacement *ec2.SpotPlacement
|
SecurityGroups []*string
|
||||||
SubnetID *string
|
SpotPlacement *ec2.SpotPlacement
|
||||||
UserData64 *string
|
SubnetID *string
|
||||||
|
UserData64 *string
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildAwsInstanceOpts(
|
func buildAwsInstanceOpts(
|
||||||
|
@ -907,6 +927,10 @@ func buildAwsInstanceOpts(
|
||||||
InstanceType: aws.String(d.Get("instance_type").(string)),
|
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{
|
opts.Monitoring = &ec2.RunInstancesMonitoringEnabled{
|
||||||
Enabled: aws.Bool(d.Get("monitoring").(bool)),
|
Enabled: aws.Bool(d.Get("monitoring").(bool)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,10 @@ The following arguments are supported:
|
||||||
EBS-optimized.
|
EBS-optimized.
|
||||||
* `disable_api_termination` - (Optional) If true, enables [EC2 Instance
|
* `disable_api_termination` - (Optional) If true, enables [EC2 Instance
|
||||||
Termination Protection](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingDisableAPITermination)
|
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
|
* `instance_type` - (Required) The type of instance to start
|
||||||
* `key_name` - (Optional) The key name to use for the instance.
|
* `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)
|
* `monitoring` - (Optional) If true, the launched EC2 instance will have detailed monitoring enabled. (Available since v0.6.0)
|
||||||
|
|
Loading…
Reference in New Issue