From 290c316a368b013ace6cbebe50d174b37d2f5cac Mon Sep 17 00:00:00 2001 From: Tarun Menon Date: Thu, 5 Sep 2024 12:36:02 +1000 Subject: [PATCH] tagging --- fargate-v2.cfndsl.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/fargate-v2.cfndsl.rb b/fargate-v2.cfndsl.rb index 4629775..63591b9 100644 --- a/fargate-v2.cfndsl.rb +++ b/fargate-v2.cfndsl.rb @@ -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' @@ -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 @@ -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| @@ -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