Skip to content

Commit

Permalink
ecs_service supports load balancer update (ansible-collections#1625)
Browse files Browse the repository at this point in the history
ecs_service supports load balancer update

SUMMARY


ISSUE TYPE


Feature Pull Request

COMPONENT NAME

ecs_service
ADDITIONAL INFORMATION


As aws docs says, aws ecs service now supports load balancer update with UpdateService API if deploymentController type is ECS.
This pull request supports load balancer update.

Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Alina Buzachis <None>
  • Loading branch information
zhoufeng1989 authored and abikouo committed Sep 18, 2023
1 parent 636a46c commit c4f731d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ecs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ def create_service(self, service_name, cluster_name, task_definition, load_balan
def update_service(self, service_name, cluster_name, task_definition, desired_count,
deployment_configuration, placement_constraints, placement_strategy,
network_configuration, health_check_grace_period_seconds,
force_new_deployment, capacity_provider_strategy):
force_new_deployment, capacity_provider_strategy, load_balancers):
params = dict(
cluster=cluster_name,
service=service_name,
Expand All @@ -849,6 +849,9 @@ def update_service(self, service_name, cluster_name, task_definition, desired_co
if desired_count is not None:
params['desiredCount'] = desired_count

if load_balancers:
params['loadBalancers'] = load_balancers

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

Expand Down Expand Up @@ -1027,7 +1030,8 @@ def main():
if 'capacityProviderStrategy' in existing.keys():
module.fail_json(msg="It is not possible to change an existing service from capacity_provider_strategy to launch_type.")
if (existing['loadBalancers'] or []) != loadBalancers:
if existing['deploymentController']['type'] != 'CODE_DEPLOY':
# fails if deployment type is not CODE_DEPLOY or ECS
if existing['deploymentController']['type'] not in ['CODE_DEPLOY', 'ECS']:
module.fail_json(msg="It is not possible to update the load balancers of an existing service")

if existing.get('deploymentController', {}).get('type', None) == 'CODE_DEPLOY':
Expand All @@ -1042,6 +1046,8 @@ def main():
if module.params['tags'] and boto3_tag_list_to_ansible_dict(existing['tags']) != module.params['tags']:
module.fail_json(msg="It is not currently supported to change tags of an existing service")

updatedLoadBalancers = loadBalancers if existing['deploymentController']['type'] == 'ECS' else []

# update required
response = service_mgr.update_service(module.params['name'],
module.params['cluster'],
Expand All @@ -1054,6 +1060,7 @@ def main():
module.params['health_check_grace_period_seconds'],
module.params['force_new_deployment'],
capacityProviders,
updatedLoadBalancers,
)

else:
Expand Down

0 comments on commit c4f731d

Please sign in to comment.