From 6e9ec7afeea924b9ede30f0fae1a2d38766be3f2 Mon Sep 17 00:00:00 2001 From: Gareth Rushgrove Date: Wed, 11 Mar 2015 12:07:36 +0000 Subject: [PATCH] (CLOUD-256) Fix blank name tags for all resources This was previously fixed for instances only but this commit generalises the fix to other resources. Tags do not have to contain content, so it's possible for an account to contain resources with a Name tag which is blank. Previously we checked for the presence of name, and not whether it was empty. --- lib/puppet/provider/ec2_instance/v2.rb | 2 +- lib/puppet/provider/ec2_vpc/v2.rb | 2 +- lib/puppet/provider/ec2_vpc_dhcp_options/v2.rb | 2 +- lib/puppet/provider/ec2_vpc_internet_gateway/v2.rb | 2 +- lib/puppet/provider/ec2_vpc_routetable/v2.rb | 2 +- lib/puppet/provider/ec2_vpc_subnet/v2.rb | 2 +- lib/puppet/provider/ec2_vpc_vpn/v2.rb | 2 +- lib/puppet/provider/ec2_vpc_vpn_gateway/v2.rb | 4 +--- lib/puppet_x/puppetlabs/aws.rb | 4 ++++ 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/puppet/provider/ec2_instance/v2.rb b/lib/puppet/provider/ec2_instance/v2.rb index 8a55000a..eb7d91f3 100644 --- a/lib/puppet/provider/ec2_instance/v2.rb +++ b/lib/puppet/provider/ec2_instance/v2.rb @@ -17,7 +17,7 @@ def self.instances response.data.reservations.each do |reservation| reservation.instances.each do |instance| hash = instance_to_hash(region, instance) - instances << new(hash) if (hash[:name] and ! hash[:name].empty?) + instances << new(hash) if has_name?(hash) end end end diff --git a/lib/puppet/provider/ec2_vpc/v2.rb b/lib/puppet/provider/ec2_vpc/v2.rb index 5de8a5b6..2b3785b0 100644 --- a/lib/puppet/provider/ec2_vpc/v2.rb +++ b/lib/puppet/provider/ec2_vpc/v2.rb @@ -13,7 +13,7 @@ def self.instances vpcs = [] response.data.vpcs.each do |vpc| hash = vpc_to_hash(region, vpc) - vpcs << new(hash) if hash[:name] + vpcs << new(hash) if has_name?(hash) end vpcs end.flatten diff --git a/lib/puppet/provider/ec2_vpc_dhcp_options/v2.rb b/lib/puppet/provider/ec2_vpc_dhcp_options/v2.rb index 7c5c6218..f3e0eeaa 100644 --- a/lib/puppet/provider/ec2_vpc_dhcp_options/v2.rb +++ b/lib/puppet/provider/ec2_vpc_dhcp_options/v2.rb @@ -13,7 +13,7 @@ def self.instances ec2_client(region).describe_dhcp_options.collect do |response| response.data.dhcp_options.each do |item| hash = dhcp_option_to_hash(region, item) - options << new(hash) if hash[:name] + options << new(hash) if has_name?(hash) end end options diff --git a/lib/puppet/provider/ec2_vpc_internet_gateway/v2.rb b/lib/puppet/provider/ec2_vpc_internet_gateway/v2.rb index f4728953..3cbc7121 100644 --- a/lib/puppet/provider/ec2_vpc_internet_gateway/v2.rb +++ b/lib/puppet/provider/ec2_vpc_internet_gateway/v2.rb @@ -13,7 +13,7 @@ def self.instances gateways = [] response.data.internet_gateways.each do |gateway| hash = gateway_to_hash(region, gateway) - gateways << new(hash) if hash[:name] + gateways << new(hash) if has_name?(hash) end gateways end.flatten diff --git a/lib/puppet/provider/ec2_vpc_routetable/v2.rb b/lib/puppet/provider/ec2_vpc_routetable/v2.rb index eefa3358..f4a97494 100644 --- a/lib/puppet/provider/ec2_vpc_routetable/v2.rb +++ b/lib/puppet/provider/ec2_vpc_routetable/v2.rb @@ -13,7 +13,7 @@ def self.instances tables = [] response.data.route_tables.each do |table| hash = route_table_to_hash(region, table) - tables << new(hash) if hash[:name] + tables << new(hash) if has_name?(hash) end tables end.flatten diff --git a/lib/puppet/provider/ec2_vpc_subnet/v2.rb b/lib/puppet/provider/ec2_vpc_subnet/v2.rb index f11b82be..2368b68f 100644 --- a/lib/puppet/provider/ec2_vpc_subnet/v2.rb +++ b/lib/puppet/provider/ec2_vpc_subnet/v2.rb @@ -13,7 +13,7 @@ def self.instances subnets = [] response.data.subnets.each do |subnet| hash = subnet_to_hash(region, subnet) - subnets << new(hash) if hash[:name] + subnets << new(hash) if has_name?(hash) end subnets end.flatten diff --git a/lib/puppet/provider/ec2_vpc_vpn/v2.rb b/lib/puppet/provider/ec2_vpc_vpn/v2.rb index 33e00928..2a834970 100644 --- a/lib/puppet/provider/ec2_vpc_vpn/v2.rb +++ b/lib/puppet/provider/ec2_vpc_vpn/v2.rb @@ -15,7 +15,7 @@ def self.instances() ]).each do |response| response.data.vpn_connections.each do |connection| hash = connection_to_hash(region, connection) - connections << new(hash) if hash[:name] + connections << new(hash) if has_name?(hash) end end connections diff --git a/lib/puppet/provider/ec2_vpc_vpn_gateway/v2.rb b/lib/puppet/provider/ec2_vpc_vpn_gateway/v2.rb index ba12f5df..23eab9e3 100644 --- a/lib/puppet/provider/ec2_vpc_vpn_gateway/v2.rb +++ b/lib/puppet/provider/ec2_vpc_vpn_gateway/v2.rb @@ -15,9 +15,7 @@ def self.instances() ]).each do |response| response.data.vpn_gateways.each do |gateway| hash = gateway_to_hash(region, gateway) - if hash[:name] - gateways << new(hash) - end + gateways << new(hash) if has_name?(hash) end end gateways diff --git a/lib/puppet_x/puppetlabs/aws.rb b/lib/puppet_x/puppetlabs/aws.rb index 56d4be00..7d3c329d 100644 --- a/lib/puppet_x/puppetlabs/aws.rb +++ b/lib/puppet_x/puppetlabs/aws.rb @@ -112,6 +112,10 @@ def tags=(value) ) unless missing_tags.empty? end + def self.has_name?(hash) + !hash[:name].nil? && !hash[:name].empty? + end + end end end