Module: Awspec::Helper::Finder::SecurityGroup

Included in:
Awspec::Helper::Finder
Defined in:
lib/awspec/helper/finder/security_group.rb

Instance Method Summary collapse

Instance Method Details

#describe_security_groups(param) ⇒ Object



30
31
32
# File 'lib/awspec/helper/finder/security_group.rb', line 30

def describe_security_groups(param)
  ec2_client.describe_security_groups(param).security_groups
end

#find_security_group(sg_id) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/awspec/helper/finder/security_group.rb', line 4

def find_security_group(sg_id)
  resource = select_security_group_by_group_id([sg_id]).single_resource(sg_id)
  return resource if resource

  resource = select_security_group_by_group_name([sg_id]).single_resource(sg_id)
  return resource if resource

  select_security_group_by_tag_name([sg_id]).single_resource(sg_id)
end

#select_security_group_by_group_id(ids) ⇒ Object



18
19
20
# File 'lib/awspec/helper/finder/security_group.rb', line 18

def select_security_group_by_group_id(ids)
  describe_security_groups({ filters: [{ name: 'group-id', values: ids }] })
end

#select_security_group_by_group_name(names) ⇒ Object



22
23
24
# File 'lib/awspec/helper/finder/security_group.rb', line 22

def select_security_group_by_group_name(names)
  describe_security_groups({ filters: [{ name: 'group-name', values: names }] })
end

#select_security_group_by_tag_name(names) ⇒ Object



26
27
28
# File 'lib/awspec/helper/finder/security_group.rb', line 26

def select_security_group_by_tag_name(names)
  describe_security_groups({ filters: [{ name: 'tag:Name', values: names }] })
end

#select_security_group_by_vpc_id(vpc_id) ⇒ Object



14
15
16
# File 'lib/awspec/helper/finder/security_group.rb', line 14

def select_security_group_by_vpc_id(vpc_id)
  describe_security_groups({ filters: [{ name: 'vpc-id', values: [vpc_id] }] })
end