Skip to content

Commit

Permalink
ecs_service - fix validation for placementConstraints (ansible-coll…
Browse files Browse the repository at this point in the history
…ections#1170)

ecs_service - fix validation for `placementConstraints`

SUMMARY
Fixes ansible-collections#1058
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
ecs_service

Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Oleksandr Novak <[email protected]>
Reviewed-by: Alina Buzachis <None>
  • Loading branch information
novak-oleksandr authored May 30, 2022
1 parent 970046e commit 70b6354
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 @@ -113,6 +113,7 @@
type: str
expression:
description: A cluster query language expression to apply to the constraint.
required: false
type: str
placement_strategy:
description:
Expand Down Expand Up @@ -584,7 +585,6 @@ def create_service(self, service_name, cluster_name, task_definition, load_balan
clientToken=client_token,
role=role,
deploymentConfiguration=deployment_configuration,
placementConstraints=placement_constraints,
placementStrategy=placement_strategy
)
if network_configuration:
Expand All @@ -597,6 +597,13 @@ def create_service(self, service_name, cluster_name, task_definition, load_balan
params['healthCheckGracePeriodSeconds'] = health_check_grace_period_seconds
if service_registries:
params['serviceRegistries'] = service_registries

# filter placement_constraint and left only those where value is not None
# use-case: `distinctInstance` type should never contain `expression`, but None will fail `str` type validation
if placement_constraints:
params['placementConstraints'] = [{key: value for key, value in constraint.items() if value is not None}
for constraint in placement_constraints]

# desired count is not required if scheduling strategy is daemon
if desired_count is not None:
params['desiredCount'] = desired_count
Expand Down Expand Up @@ -674,7 +681,7 @@ def main():
elements='dict',
options=dict(
type=dict(type='str'),
expression=dict(type='str')
expression=dict(required=False, type='str')
)
),
placement_strategy=dict(
Expand Down

0 comments on commit 70b6354

Please sign in to comment.