Module: Awspec::Helper::Finder::Vpc

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

Instance Method Summary collapse

Instance Method Details

#find_network_acl(id) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/awspec/helper/finder/vpc.rb', line 32

def find_network_acl(id)
  res = ec2_client.describe_network_acls({
                                           filters: [{ name: 'network-acl-id', values: [id] }]
                                         })
  resource = res.network_acls.single_resource(id)
  return resource if resource

  res = ec2_client.describe_network_acls({
                                           filters: [{ name: 'tag:Name', values: [id] }]
                                         })
  res.network_acls.single_resource(id)
end

#find_route_table(route_table_id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/awspec/helper/finder/vpc.rb', line 19

def find_route_table(route_table_id)
  res = ec2_client.describe_route_tables({
                                           filters: [{ name: 'route-table-id', values: [route_table_id] }]
                                         })
  resource = res.route_tables.single_resource(route_table_id)
  return resource if resource

  res = ec2_client.describe_route_tables({
                                           filters: [{ name: 'tag:Name', values: [route_table_id] }]
                                         })
  res.route_tables.single_resource(route_table_id)
end

#find_vpc(id) ⇒ Object



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

def find_vpc(id)
  res = ec2_client.describe_vpcs({
                                   filters: [{ name: 'vpc-id', values: [id] }]
                                 })
  resource = res.vpcs.single_resource(id)
  return resource if resource

  res = ec2_client.describe_vpcs({
                                   filters: [{ name: 'tag:Name', values: [id] }]
                                 })
  res.vpcs.single_resource(id)
end

#find_vpc_attribute(vpc_id, vpc_attribute) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/awspec/helper/finder/vpc.rb', line 93

def find_vpc_attribute(vpc_id, vpc_attribute)
  res = ec2_client.describe_vpc_attribute({ vpc_id: vpc_id, attribute: vpc_attribute })
  case vpc_attribute
  when 'enableDnsSupport'
    res.enable_dns_support.value
  when 'enableDnsHostnames'
    res.enable_dns_hostnames.value
  end
end

#find_vpc_peering_connection(vpc_peering_connection_id) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/awspec/helper/finder/vpc.rb', line 59

def find_vpc_peering_connection(vpc_peering_connection_id)
  res = ec2_client.describe_vpc_peering_connections({
                                                      filters: [
                                                        {
                                                          name: 'vpc-peering-connection-id',
                                                          values: [vpc_peering_connection_id]
                                                        }
                                                      ]
                                                    })
  resource = res.vpc_peering_connections.single_resource(vpc_peering_connection_id)
  return resource if resource

  res = ec2_client.describe_vpc_peering_connections({
                                                      filters: [
                                                        {
                                                          name: 'tag:Name',
                                                          values: [vpc_peering_connection_id]
                                                        }
                                                      ]
                                                    })
  res.vpc_peering_connections.single_resource(vpc_peering_connection_id)
end

#select_network_acl_by_vpc_id(vpc_id) ⇒ Object



52
53
54
55
56
57
# File 'lib/awspec/helper/finder/vpc.rb', line 52

def select_network_acl_by_vpc_id(vpc_id)
  res = ec2_client.describe_network_acls({
                                           filters: [{ name: 'vpc-id', values: [vpc_id] }]
                                         })
  res.network_acls
end

#select_route_table_by_vpc_id(vpc_id) ⇒ Object



45
46
47
48
49
50
# File 'lib/awspec/helper/finder/vpc.rb', line 45

def select_route_table_by_vpc_id(vpc_id)
  res = ec2_client.describe_route_tables({
                                           filters: [{ name: 'vpc-id', values: [vpc_id] }]
                                         })
  res.route_tables
end

#select_vpc_attribute(vpc_id) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/awspec/helper/finder/vpc.rb', line 103

def select_vpc_attribute(vpc_id)
  attributes = {}
  vpc_attributes = %w[
    enableDnsHostnames enableDnsSupport
  ]
  vpc_attributes.each do |vpc_attribute|
    res = ec2_client.describe_vpc_attribute({ vpc_id: vpc_id, attribute: vpc_attribute })
    attributes[vpc_attribute] = case vpc_attribute
                                when 'enableDnsHostnames'
                                  res.enable_dns_hostnames.value
                                when 'enableDnsSupport'
                                  res.enable_dns_support.value
                                end
  end
  attributes
end

#select_vpc_peering_connection_by_vpc_id(vpc_id, status_code = nil) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/awspec/helper/finder/vpc.rb', line 82

def select_vpc_peering_connection_by_vpc_id(vpc_id, status_code = nil)
  params = {}
  params = { filters: [{ name: 'status-code', values: [status_code] }] } if status_code
  vpc_peering_connections = ec2_client.describe_vpc_peering_connections(params).map do |res|
    res.vpc_peering_connections
  end.flatten
  vpc_peering_connections.select do |conn|
    conn.accepter_vpc_info.vpc_id == vpc_id || conn.requester_vpc_info.vpc_id == vpc_id
  end
end