Class: VPC::SimpleVpc

Inherits:
Vpc
  • Object
show all
Defined in:
lib/etude_for_aws/vpc/simple_vpc.rb

Direct Known Subclasses

SimpleVpcStub

Instance Attribute Summary

Attributes inherited from Vpc

#config, #gateway, #internet_gateway, #private_route_tables, #private_subnets, #public_route_tables, #public_subnets, #route_tables, #subnets, #vpc_id, #vpn

Instance Method Summary collapse

Methods inherited from Vpc

#create_internet_gateway, #create_vpc, #delete_internet_gateway, #delete_route_tables, #delete_subnets, #delete_vpc, #get_subnet_infos, #get_vpc_id

Methods included from EC2::VpcInterface

#get_subnet_infos, #get_vpc_id

Constructor Details

#initializeSimpleVpc

Returns a new instance of SimpleVpc.



3
4
5
# File 'lib/etude_for_aws/vpc/simple_vpc.rb', line 3

def initialize
  super
end

Instance Method Details

#create_route_tableObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/etude_for_aws/vpc/simple_vpc.rb', line 26

def create_route_table
  @public_subnets.each do |subnet|
    @config.public_route_tables.each do |v|
      destination_cidr_block = v['CONFIG']['DESTINATION_CIDR_BLOCK'].first
      name = v['CONFIG']['ROUTE_TABLE_TAGS'].first['NAME']['VALUE']
      key = v['CONFIG']['ROUTE_TABLE_TAGS'].first['NAME']['KEY']
      route_tables = @gateway.select_route_tables_by_name(name)
      if route_tables.empty?
        route_table = VPC::RouteTable.new
        route_table.create(self)
        route_table.create_public_route(self,destination_cidr_block,@internet_gateway.internet_gateway_id)
        route_table.associate_route_table(self,route_table.route_table_id,subnet.subnet_id)

        resources = [route_table.route_table_id]
        vpc_subnet_name_tag = {key: key, value: name}
        tags = [vpc_subnet_name_tag,@config.vpc_group_tag]
        @gateway.create_tags(resources,tags)
        @public_route_tables << route_table
      end
    end
  end
end

#create_subnetsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/etude_for_aws/vpc/simple_vpc.rb', line 7

def create_subnets
  @config.public_subnets.each do |v|
    subnet_cidr_block = v['CONFIG']['SUBNET_CIDR_BLOCK'].first
    az = v['CONFIG']['AZ'].first
    name = v['CONFIG']['SUBNET_TAGS'].first['NAME']['VALUE']
    key = v['CONFIG']['SUBNET_TAGS'].first['NAME']['KEY']
    subnets = @gateway.select_subnets_by_name(name)
    if subnets.empty?
      subnet = VPC::Subnet.new
      subnet.create(self,subnet_cidr_block,az)
      resources = [subnet.subnet_id]
      vpc_subnet_name_tag = {key: key, value: name}
      tags = [vpc_subnet_name_tag,@config.vpc_group_tag]
      @gateway.create_tags(resources,tags)
      @public_subnets << subnet
    end
  end
end