diff --git a/fargate-v2.cfndsl.rb b/fargate-v2.cfndsl.rb index fcf9983..acbca38 100644 --- a/fargate-v2.cfndsl.rb +++ b/fargate-v2.cfndsl.rb @@ -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 = [] @@ -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 diff --git a/tests/dynamic_priorities.test.yaml b/tests/dynamic_priorities.test.yaml new file mode 100644 index 0000000..2799f26 --- /dev/null +++ b/tests/dynamic_priorities.test.yaml @@ -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 diff --git a/tests/multi_path_rules.test.yaml b/tests/multi_path_rules.test.yaml new file mode 100644 index 0000000..700bffe --- /dev/null +++ b/tests/multi_path_rules.test.yaml @@ -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/* diff --git a/tests/single_path_rules.test.yaml b/tests/single_path_rules.test.yaml new file mode 100644 index 0000000..edf338a --- /dev/null +++ b/tests/single_path_rules.test.yaml @@ -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