Skip to content

Commit

Permalink
Support new enableExecuteCommand options for ECS service
Browse files Browse the repository at this point in the history
  • Loading branch information
Surgo authored and tremble committed Jul 8, 2022
1 parent d7f3862 commit 972c55a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions plugins/modules/ecs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@
type: dict
required: false
version_added: 4.1.0
enable_execute_command:
description:
- Whether or not to enable the execute command functionality for the containers in this task.
- If `true`, this enables execute command functionality on all containers in the task.
- This option requires botocore >= 1.20.28
required: false
type: bool
default: false
extends_documentation_fragment:
- amazon.aws.aws
- amazon.aws.ec2
Expand Down Expand Up @@ -758,7 +766,8 @@ def create_service(self, service_name, cluster_name, task_definition, load_balan
desired_count, client_token, role, deployment_controller, deployment_configuration,
placement_constraints, placement_strategy, health_check_grace_period_seconds,
network_configuration, service_registries, launch_type, platform_version,
scheduling_strategy, capacity_provider_strategy, tags, propagate_tags):
scheduling_strategy, capacity_provider_strategy, tags, propagate_tags,
enable_execute_command):

params = dict(
cluster=cluster_name,
Expand Down Expand Up @@ -804,12 +813,16 @@ def create_service(self, service_name, cluster_name, task_definition, load_balan

if scheduling_strategy:
params['schedulingStrategy'] = scheduling_strategy
if enable_execute_command:
params['enableExecuteCommand'] = enable_execute_command

response = self.ecs.create_service(**params)
return self.jsonize(response['service'])

def update_service(self, service_name, cluster_name, task_definition,
desired_count, deployment_configuration, network_configuration,
health_check_grace_period_seconds, force_new_deployment, capacity_provider_strategy):
health_check_grace_period_seconds, force_new_deployment,
capacity_provider_strategy, enable_execute_command):
params = dict(
cluster=cluster_name,
service=service_name,
Expand All @@ -826,6 +839,8 @@ def update_service(self, service_name, cluster_name, task_definition,
# desired count is not required if scheduling strategy is daemon
if desired_count is not None:
params['desiredCount'] = desired_count
if enable_execute_command:
params['enableExecuteCommand'] = enable_execute_command

response = self.ecs.update_service(**params)
return self.jsonize(response['service'])
Expand Down Expand Up @@ -915,6 +930,7 @@ def main():
),
propagate_tags=dict(required=False, choices=['TASK_DEFINITION', 'SERVICE']),
tags=dict(required=False, type='dict'),
enable_execute_command=dict(required=False, default=False, type='bool'),
)

module = AnsibleAWSModule(argument_spec=argument_spec,
Expand Down Expand Up @@ -958,6 +974,10 @@ def main():

results = dict(changed=False)

if module.params['enable_execute_command']:
if not module.botocore_at_least('1.20.28'):
module.fail_json(msg='botocore needs to be version 1.20.28 or higher to use enable_execute_command')

if module.params['state'] == 'present':

matching = False
Expand Down Expand Up @@ -1030,6 +1050,7 @@ def main():
module.params['health_check_grace_period_seconds'],
module.params['force_new_deployment'],
capacityProviders,
module.params['enable_execute_command']),
)

else:
Expand All @@ -1055,6 +1076,7 @@ def main():
capacityProviders,
module.params['tags'],
module.params['propagate_tags'],
module.params['enable_execute_command'],
)
except botocore.exceptions.ClientError as e:
module.fail_json_aws(e, msg="Couldn't create service")
Expand Down

0 comments on commit 972c55a

Please sign in to comment.