Created
April 2, 2015 23:32
-
-
Save nanki/980ae2b15253baef1a59 to your computer and use it in GitHub Desktop.
tag EBS volumes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aws-sdk-core' | |
require 'aws-sdk-resources' | |
require 'yaml' | |
config = YAML.load_file('config.yml')[:tag] | |
Aws.config.update( | |
region: 'ap-northeast-1', | |
credentials: Aws::Credentials.new(config[:access_key_id], config[:secret_access_key]) | |
) | |
ec2 = Aws::EC2::Resource.new | |
ec2.vpcs.each do |vpc| | |
tags = vpc.tags.select{|tag|["Product", "Environment"].include? tag.key} | |
next unless tags.count == 2 | |
vpc.instances.each do |i| | |
i.volumes.each do |volume| | |
volume.create_tags tags: tags if volume.tags.empty? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment