Skip to content

Commit

Permalink
tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunmenon95 committed Sep 5, 2024
1 parent f23bc9e commit 290c316
Showing 1 changed file with 13 additions and 6 deletions.
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,16 @@

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

fargate_tags = []
fargate_tags << { Key: 'Name', Value: FnSub("${EnvironmentName}-#{export}") }
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 +78,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 +102,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 +231,7 @@
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?

if service_loadbalancer.any?
LoadBalancers service_loadbalancer
Expand Down

0 comments on commit 290c316

Please sign in to comment.