lib/terraforming/resource/security_group.rb in terraforming-0.9.1 vs lib/terraforming/resource/security_group.rb in terraforming-0.10.0

- old
+ new

@@ -73,21 +73,22 @@ Zlib.crc32(group) end def module_name_of(security_group) if security_group.vpc_id.nil? - normalize_module_name("#{security_group.group_name}") + normalize_module_name(security_group.group_name.to_s) else normalize_module_name("#{security_group.vpc_id}-#{security_group.group_name}") end end def permission_attributes_of(security_group, permission, type) hashcode = permission_hashcode_of(security_group, permission) - security_groups = security_groups_in(permission, security_group).reject { |group_name| group_name == security_group.group_name }.reject { |group_id| group_id == security_group.group_id } + security_groups = security_groups_in(permission, security_group).reject do |identifier| + [security_group.group_name, security_group.group_id].include?(identifier) + end - attributes = { "#{type}.#{hashcode}.from_port" => (permission.from_port || 0).to_s, "#{type}.#{hashcode}.to_port" => (permission.to_port || 0).to_s, "#{type}.#{hashcode}.protocol" => permission.ip_protocol, "#{type}.#{hashcode}.cidr_blocks.#" => permission.ip_ranges.length.to_s, @@ -138,11 +139,11 @@ def permission_hashcode_of(security_group, permission) string = "#{permission.from_port || 0}-" << "#{permission.to_port || 0}-" << "#{permission.ip_protocol}-" << - "#{self_referenced_permission?(security_group, permission).to_s}-" + "#{self_referenced_permission?(security_group, permission)}-" permission.ip_ranges.each { |range| string << "#{range.cidr_ip}-" } security_groups_in(permission, security_group).each { |group| string << "#{group}-" } Zlib.crc32(string) @@ -151,25 +152,25 @@ def self_referenced_permission?(security_group, permission) (security_groups_in(permission, security_group) & [security_group.group_id, security_group.group_name]).any? end def security_groups - @client.describe_security_groups.security_groups + @client.describe_security_groups.map(&:security_groups).flatten end def security_groups_in(permission, security_group) - permission.user_id_group_pairs.map { |range| + permission.user_id_group_pairs.map do |range| # EC2-Classic, same account if security_group.owner_id == range.user_id && !range.group_name.nil? range.group_name # VPC elsif security_group.owner_id == range.user_id && range.group_name.nil? range.group_id # EC2-Classic, other account else "#{range.user_id}/#{range.group_name}" end - } + end end def tags_attributes_of(security_group) tags = security_group.tags attributes = { "tags.#" => tags.length.to_s }