From 269366d2ad3e51188762b2ba38d3e43dd8ac8cac Mon Sep 17 00:00:00 2001 From: Peter Postma Date: Tue, 5 Nov 2024 10:05:49 +0100 Subject: [PATCH] Allow adding custom tags to an AMI. --- lib/capistrano/asg/rolling/tags.rb | 7 ++++++- spec/capistrano/asg/rolling/tags_spec.rb | 10 ++++++++++ spec/spec_helper.rb | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/capistrano/asg/rolling/tags.rb b/lib/capistrano/asg/rolling/tags.rb index 69c2434..cd370fc 100644 --- a/lib/capistrano/asg/rolling/tags.rb +++ b/lib/capistrano/asg/rolling/tags.rb @@ -9,7 +9,7 @@ module Tags # The tags to add to an AMI. def ami_tags - application_tags.merge(deployment_tags).merge(gem_tags) + application_tags.merge(deployment_tags).merge(gem_tags).merge(custom_tags) end # Tags related to the current application / stage. @@ -36,6 +36,11 @@ def gem_tags 'capistrano-asg-rolling:gem-version' => Capistrano::ASG::Rolling::VERSION } end + + # Custom added tags. + def custom_tags + fetch(:asg_rolling_ami_tags) || {} + end end end end diff --git a/spec/capistrano/asg/rolling/tags_spec.rb b/spec/capistrano/asg/rolling/tags_spec.rb index f1c4ef7..fe5494d 100644 --- a/spec/capistrano/asg/rolling/tags_spec.rb +++ b/spec/capistrano/asg/rolling/tags_spec.rb @@ -48,4 +48,14 @@ ) end end + + describe '#custom_tags' do + before { Capistrano::ASG::Rolling::Configuration.set(:asg_rolling_ami_tags, { 'custom-tag' => 'foobar' }) } + + it 'returns a hash with custom tags' do + expect(described_class.custom_tags).to eq( + 'custom-tag' => 'foobar' + ) + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5217864..5fe9a97 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,6 +29,7 @@ Capistrano::ASG::Rolling::Configuration.instance_variable_set(:@instances, nil) Capistrano::ASG::Rolling::Configuration.instance_variable_set(:@launch_templates, nil) + Capistrano::ASG::Rolling::Configuration.set(:asg_rolling_ami_tags, nil) Capistrano::ASG::Rolling::Configuration.set(:asg_rolling_group_name, nil) Capistrano::ASG::Rolling::Configuration.set(:asg_rolling_use_private_ip_address, true)