Skip to content

Commit

Permalink
fixes container override json encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronwalker committed Jun 28, 2021
1 parent 6dcc9b0 commit 2660f66
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
11 changes: 5 additions & 6 deletions ecs-schedule-runtasks.cfndsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
run_tasks.each do |name, task|
schedule = task['schedule']
task_name = name.gsub("-","").gsub("_","")

container_overrides = {}
container_overrides.merge! name: task.has_key?('container') ? task['container'] : "#{task['task_definition']}"
container_overrides.merge! command: "#{task['command']}" if task.has_key?('command')
container_overrides.merge! environment: "#{task['env_vars']}" if task.has_key?('env_vars')
container_overrides[:name] = task.has_key?('container') ? task['container'] : "#{task['task_definition']}"
container_overrides[:command] = task['command'] if task.has_key?('command')
container_overrides[:environment] = task['env_vars'] if task.has_key?('env_vars')
container_input = {
containerOverrides: [container_overrides]
}

unless schedule.nil?
Events_Rule("#{task_name}Schedule") do
Name FnSub("${EnvironmentName}-#{name}-schedule")
Expand All @@ -50,7 +49,7 @@
}
}
},
Input: container_input
Input: container_input.to_json()
}]
end
end
Expand Down
10 changes: 4 additions & 6 deletions spec/multipletasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"TaskCount"=>1,
"TaskDefinitionArn"=>{"Ref"=>"task1"}},
"Id"=>"task1-dGFzazE",
"Input"=>{"containerOverrides"=>[{"name"=>"task1"}]},
"RoleArn"=>{"Fn::GetAtt"=>["EventBridgeInvokeRole", "Arn"]}}
"Input"=>"{\"containerOverrides\":[{\"name\":\"task1\"}]}",
"RoleArn"=>{"Fn::GetAtt"=>["EventBridgeInvokeRole", "Arn"]}}
])
end

Expand Down Expand Up @@ -74,10 +74,8 @@
"TaskCount"=>1,
"TaskDefinitionArn"=>{"Ref"=>"task2"}},
"Id"=>"task2-dGFzazI",
"Input"=>
{"containerOverrides"=>
[{"command"=>"[\"echo\", \"foo\", \"bar\"]", "name"=>"task2"}]},
"RoleArn"=>{"Fn::GetAtt"=>["EventBridgeInvokeRole", "Arn"]}}
"Input"=>"{\"containerOverrides\":[{\"name\":\"task2\",\"command\":[\"echo\",\"foo\",\"bar\"]}]}",
"RoleArn"=>{"Fn::GetAtt"=>["EventBridgeInvokeRole", "Arn"]}}
])
end

Expand Down
8 changes: 2 additions & 6 deletions spec/singletasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,8 @@
"TaskCount"=>1,
"TaskDefinitionArn"=>{"Ref"=>"mytask"}},
"Id"=>"singletask-c2luZ2xldGFzaw",
"Input"=>
{"containerOverrides"=>
[{"command"=>"[\"echo\", \"hello\", \"worrld\"]",
"environment"=>"[{\"foo\"=>\"bar\"}]",
"name"=>"singletask"}]},
"RoleArn"=>{"Fn::GetAtt"=>["EventBridgeInvokeRole", "Arn"]}}
"Input"=>"{\"containerOverrides\":[{\"name\":\"singletask\",\"command\":[\"echo\",\"hello world\"],\"environment\":[{\"foo\":\"bar\"}]}]}",
"RoleArn"=>{"Fn::GetAtt"=>["EventBridgeInvokeRole", "Arn"]}}
])
end

Expand Down
3 changes: 1 addition & 2 deletions tests/singletask.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ run_tasks:
task_definition: mytask
command:
- echo
- hello
- worrld
- hello world
env_vars:
- foo: bar
schedule: rate(1 hour)
Expand Down

0 comments on commit 2660f66

Please sign in to comment.