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



32
33
34
# File 'lib/awspec/helper/finder/security_group.rb', line 32

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

#find_security_group(sg_id) ⇒ Object



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

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



20
21
22
# File 'lib/awspec/helper/finder/security_group.rb', line 20

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



24
25
26
# File 'lib/awspec/helper/finder/security_group.rb', line 24

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



28
29
30
# File 'lib/awspec/helper/finder/security_group.rb', line 28

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



16
17
18
# File 'lib/awspec/helper/finder/security_group.rb', line 16

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