Add parameter to `ec2` module to control instance shutdown behavior (stop|terminate)

reviewable/pr18780/r1
Richard Adams 9 years ago committed by Ryan S. Brown
parent 2f26352e49
commit c8ca1a6211

@ -206,6 +206,13 @@ options:
required: false
default: no
choices: [ "yes", "no" ]
instance_initiated_shutdown_behavior:
version_added: "2.2"
description:
- Set whether AWS will Stop or Terminate an instance on shutdown
required: false
default: 'stop'
choices: [ "stop", "terminate" ]
state:
version_added: "1.3"
description:
@ -892,6 +899,7 @@ def create_instances(module, ec2, vpc, override_count=None):
termination_protection = module.boolean(module.params.get('termination_protection'))
network_interfaces = module.params.get('network_interfaces')
spot_launch_group = module.params.get('spot_launch_group')
instance_initiated_shutdown_behavior = module.params.get('instance_initiated_shutdown_behavior')
# group_id and group_name are exclusive of each other
if group_id and group_name:
@ -1043,6 +1051,9 @@ def create_instances(module, ec2, vpc, override_count=None):
private_ip_address = private_ip,
))
# Spot instances do not support start/stop thereby not having the option to change shutdown behavior
params['instance_initiated_shutdown_behavior'] = instance_initiated_shutdown_behavior
res = ec2.run_instances(**params)
instids = [ i.id for i in res.instances ]
while True:
@ -1077,6 +1088,12 @@ def create_instances(module, ec2, vpc, override_count=None):
module.fail_json(
msg="placement_group parameter requires Boto version 2.3.0 or higher.")
if boto_supports_param_in_spot_request(ec2, 'instance_initiated_shutdown_behavior'):
params['instance_initiated_shutdown_behavior'] = instance_initiated_shutdown_behavior
elif instance_initiated_shutdown_behavior:
module.fail_json(
msg="instance_initiated_shutdown_behavior parameter is not supported by your Boto version.")
if spot_launch_group and isinstance(spot_launch_group, basestring):
params['launch_group'] = spot_launch_group
@ -1438,6 +1455,7 @@ def main():
source_dest_check = dict(type='bool', default=True),
termination_protection = dict(type='bool', default=False),
state = dict(default='present', choices=['present', 'absent', 'running', 'restarted', 'stopped']),
instance_initiated_shutdown_behavior=dict(default='stop', choices=['stop', 'terminate']),
exact_count = dict(type='int', default=None),
count_tag = dict(),
volumes = dict(type='list'),

Loading…
Cancel
Save