Skip to content

Commit

Permalink
Feature/optional parameters (#12)
Browse files Browse the repository at this point in the history
* optional params

* move optional params

* renaming

* tagging

* fix ecs task component

* removw name tag

* propogate tags to task

* lock ecs task version

* revert ecs task version for now.

* relock version
  • Loading branch information
tarunmenon95 authored Sep 5, 2024
1 parent 8b6155f commit 95aa935
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
8 changes: 7 additions & 1 deletion fargate-v2.cfhighlander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@
if defined? service_discovery
ComponentParam 'NamespaceId'
end

end

#Pass the all the config from the parent component to the inlined component
Component template: 'ecs-task@0.5.10', name: "#{component_name.gsub('-','').gsub('_','')}Task", render: Inline, config: @config do
Component template: 'ecs-task@0.5.11', name: "#{component_name.gsub('-','').gsub('_','')}Task", render: Inline, config: @config do
parameter name: 'DnsDomain', value: Ref('DnsDomain')

additional_parameters.each do |parameter_name|
parameter name: parameter_name, value: Ref(parameter_name)
end if defined? additional_parameters

end

unless service_namespace.nil?
Expand Down
19 changes: 13 additions & 6 deletions fargate-v2.cfndsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

export = external_parameters.fetch(:export_name, external_parameters[:component_name])

fargate_tags = []
fargate_tags << { Key: "Environment", Value: Ref("EnvironmentName") }
fargate_tags << { Key: "EnvironmentType", Value: Ref("EnvironmentType") }

tags = external_parameters.fetch(:tags, {})
tags.each do |key, value|
fargate_tags << { Key: FnSub(key), Value: FnSub(value)}
end

task_definition = external_parameters.fetch(:task_definition, nil)
if task_definition.nil?
raise 'you must define a task_definition'
Expand Down Expand Up @@ -68,12 +77,8 @@
attributes << { Key: key, Value: value }
end if targetgroup.has_key?('attributes')

tags = []
tags << { Key: "Environment", Value: Ref("EnvironmentName") }
tags << { Key: "EnvironmentType", Value: Ref("EnvironmentType") }

targetgroup['tags'].each do |key,value|
tags << { Key: key, Value: value }
fargate_tags << { Key: key, Value: value }
end if targetgroup.has_key?('tags')

ElasticLoadBalancingV2_TargetGroup(targetgroup['resource_name']) do
Expand All @@ -96,7 +101,7 @@
TargetType targetgroup['type'] if targetgroup.has_key?('type')
TargetGroupAttributes attributes if attributes.any?

Tags tags if tags.any?
Tags fargate_tags if fargate_tags.any?
end

targetgroup['rules'].each_with_index do |rule, index|
Expand Down Expand Up @@ -225,6 +230,8 @@
TaskDefinition "Ref" => "Task" #Hack to work referencing child component resource
HealthCheckGracePeriodSeconds health_check_grace_period unless health_check_grace_period.nil?
LaunchType "FARGATE"
Tags fargate_tags if fargate_tags.any?
PropagateTags 'SERVICE'

if service_loadbalancer.any?
LoadBalancers service_loadbalancer
Expand Down

0 comments on commit 95aa935

Please sign in to comment.