diff --git a/ecs-schedule-runtasks.cfndsl.rb b/ecs-schedule-runtasks.cfndsl.rb index 8ae32f5..cb13c6c 100644 --- a/ecs-schedule-runtasks.cfndsl.rb +++ b/ecs-schedule-runtasks.cfndsl.rb @@ -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") @@ -50,7 +49,7 @@ } } }, - Input: container_input + Input: container_input.to_json() }] end end diff --git a/spec/multipletasks_spec.rb b/spec/multipletasks_spec.rb index 2965ade..afc7e94 100644 --- a/spec/multipletasks_spec.rb +++ b/spec/multipletasks_spec.rb @@ -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 @@ -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 diff --git a/spec/singletasks_spec.rb b/spec/singletasks_spec.rb index e47dd27..cceb1c0 100644 --- a/spec/singletasks_spec.rb +++ b/spec/singletasks_spec.rb @@ -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 diff --git a/tests/singletask.test.yaml b/tests/singletask.test.yaml index 15cbcb0..a5f0956 100644 --- a/tests/singletask.test.yaml +++ b/tests/singletask.test.yaml @@ -16,8 +16,7 @@ run_tasks: task_definition: mytask command: - echo - - hello - - worrld + - hello world env_vars: - foo: bar schedule: rate(1 hour)