Skip to content

Commit

Permalink
Merge pull request #1 from base2Services/feature/rule-paths-and-prior…
Browse files Browse the repository at this point in the history
…ities

Allow for multiple paths in same rule and dynamic priority
  • Loading branch information
Guslington authored Aug 3, 2020
2 parents 0f41bad + 12ea942 commit d87d596
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
14 changes: 11 additions & 3 deletions fargate-v2.cfndsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
targetgroup['rules'].each_with_index do |rule, index|
listener_conditions = []
if rule.key?("path")
listener_conditions << { Field: "path-pattern", Values: [ rule["path"] ] }
listener_conditions << { Field: "path-pattern", Values: [ rule["path"] ].flatten() }
end
if rule.key?("host")
hosts = []
Expand All @@ -96,11 +96,19 @@
listener_conditions << { Field: "host-header", Values: hosts }
end

ElasticLoadBalancingV2_ListenerRule("TargetRule#{rule['priority']}") do
if rule.key?("name")
rule_name = rule['name']
elsif rule['priority'].is_a? Integer
rule_name = "TargetRule#{rule['priority']}"
else
rule_name = "TargetRule#{index}"
end

ElasticLoadBalancingV2_ListenerRule(rule_name) do
Actions [{ Type: "forward", TargetGroupArn: Ref('TaskTargetGroup') }]
Conditions listener_conditions
ListenerArn Ref("Listener")
Priority rule['priority'].to_i
Priority rule['priority']
end

end
Expand Down
24 changes: 24 additions & 0 deletions tests/dynamic_priorities.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

test_metadata:
type: config
name: dynamic_priorities
description: Set a rule priority with a Ref

task_definition:
proxy:
image: nginx
ports:
- 80

targetgroup:
name: web
type: ip
container: nginx
port: 80
protocol: http
listener: http
rules:
-
host: www.*
priority:
Ref: MinimumHealthyPercent # a valid Ref to pass test
26 changes: 26 additions & 0 deletions tests/multi_path_rules.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

test_metadata:
type: config
name: multi_path_rules
description: Create a rule with multiple paths

task_definition:
proxy:
image: nginx
ports:
- 80

targetgroup:
name: web
type: ip
container: nginx
port: 80
protocol: http
listener: http
rules:
-
host: www.*
priority: 10
path:
- /v1
- /v1/*
24 changes: 24 additions & 0 deletions tests/single_path_rules.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

test_metadata:
type: config
name: single_path_rules
description: Create a rule with multiple paths

task_definition:
proxy:
image: nginx
ports:
- 80

targetgroup:
name: web
type: ip
container: nginx
port: 80
protocol: http
listener: http
rules:
-
host: www.*
priority: 10
path: /v1

0 comments on commit d87d596

Please sign in to comment.