Skip to content

Commit

Permalink
Refactored cognito to conditonal
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunmenon95 committed Mar 6, 2023
1 parent a8aad85 commit ea145fb
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions ecs-service.cfndsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

Condition('IsScalingEnabled', FnEquals(Ref('EnableScaling'), 'true'))
Condition('NoDesiredCount', FnEquals(Ref('DesiredCount'), '-1'))
Condition(:EnableCognito, FnNot(FnEquals(Ref(:UserPoolClientId), '')))

log_retention = external_parameters.fetch(:log_retention, 7)
loggroup_name = external_parameters.fetch(:loggroup_name, Ref('AWS::StackName'))
Expand Down Expand Up @@ -402,17 +403,11 @@
end
rule_names << rule_name

actions = []
actions << { Type: "forward", Order: 5000, TargetGroupArn: Ref(targetgroup['resource_name']) }

if targetgroup.has_key?('cognito')
if targetgroup['cognito'] == true
actions << cognito(self)
end
end
actions = [{ Type: "forward", Order: 5000, TargetGroupArn: Ref(targetgroup['resource_name'])}]
actions_with_cognito = actions + [cognito(Ref(:UserPoolId), Ref(:UserPoolClientId), Ref(:UserPoolDomainName))]

ElasticLoadBalancingV2_ListenerRule(rule_name) do
Actions actions
Actions FnIf(:EnableCognito, actions_with_cognito, actions)
Conditions listener_conditions
ListenerArn Ref(targetgroup['listener_resource'])
Priority rule['priority']
Expand Down

0 comments on commit ea145fb

Please sign in to comment.