jets
jets copied to clipboard
Adding common tags to all Jets resources
Summary
Provide an easy way to add AWS tags (or other common properties) to every resource created by Jets.
Motivation
Some users care about keeping all their AWS resources tagged accurately and consistently
- Makes searching for AWS resources in the console easier
- Break down spending by tag in AWS cost reports
Reference-level explanation
I came up with this monkeypatch solution for my own project. Would appreciate ideas on how this could be moved into Jets and exposed to Jets projects.
# config/initializers/resource_tagger.rb
module ResourceTagger
TAGS = [
{ Key: 'Project', Value: 'Demo' },
{ Key: 'Env', Value: ENV['JETS_ENV'] },
]
UNTAGGABLE = /Permission|GemLayer|EventsRule/
def template
hash = super
hash.each do |id, resource|
next if UNTAGGABLE.match?(id)
resource['Properties']['Tags'] ||= []
resource['Properties']['Tags'].concat(TAGS)
end
hash
end
end
Jets::Resource.prepend(ResourceTagger)
Perhaps this could be exposed to Jets project as a config option?
Jets.application.configure do
config.resource_tags = [{Key: 'Foo', Value: 'Bar'}]
...
end
This is pretty neat. Also wondering if tagging the CloudFormation stacks themselves is another approach. Believe that stack tags result in tags propagating to all the resources in the stack. Have to dig into it.
@tongueroo that is correct. CloudFormation stacks propagate tags to the items they create.
@tongueroo Im going to work on this
Fixed in #675
Hello, I am having the same issue with the tags,
Tried with https://github.com/rubyonjets/jets/pull/675 PR, I updated my ruby on jets to last version but adding the tags on application.rb or even be environment in production.rb, the resources are still created without tags. is there something else that is needed?
module MyApp
class Application < Jets::Application
...
config.resource_tags = {
'Product' => 'xcq',
'Name' => "xyz-#{ENV['JETS_ENV']}",
'Project' => 'Application',
'Comment' => 'qwerty',
'test' => 'test'
}
....
end
end
Jets.application.configure do
config.cache_classes = true
config.eager_load = true
config.log_level = :info
config.logging.event = false # can be useful for CloudWatch
config.resource_tags = {
'Product' => 'xcq',
'Name' => "xyz-#{ENV['JETS_ENV']}",
'Project' => 'Application',
'Comment' => 'qwerty',
'test' => 'test'
}
end
None of those worked in my case