etude_for_aws 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +103 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.yardopts +10 -0
- data/Dockerfile +17 -0
- data/Dockerfile-dev +20 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +89 -0
- data/Guardfile +22 -0
- data/Jenkinsfile +11 -0
- data/README.md +26 -0
- data/Rakefile +12 -0
- data/Vagrantfile +15 -0
- data/bin/aws_console.rb +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/circle.yml +22 -0
- data/config.yml +124 -0
- data/docker-compose.yml +9 -0
- data/docs/README.md +54 -0
- data/docs/_config.yml +6 -0
- data/docs/dev/cfm/cfm.md +9 -0
- data/docs/dev/cfm/images/vpc_core_model.png +0 -0
- data/docs/dev/cfm/images/vpc_type1.png +0 -0
- data/docs/dev/cfm/images/vpc_type2.png +0 -0
- data/docs/dev/cfm/images/vpc_type3.png +0 -0
- data/docs/dev/cfm/images/vpc_type4.png +0 -0
- data/docs/dev/cfm/images/vpc_type5.png +0 -0
- data/docs/dev/cfm/images/vpc_type6.png +0 -0
- data/docs/dev/cfm/images/vpc_type7.png +0 -0
- data/docs/dev/cfm/vpc/core_model.puml +35 -0
- data/docs/dev/cfm/vpc/vpc.md +39 -0
- data/docs/dev/cfm/vpc/vpc_type1.puml +17 -0
- data/docs/dev/cfm/vpc/vpc_type2.puml +23 -0
- data/docs/dev/cfm/vpc/vpc_type3.puml +24 -0
- data/docs/dev/cfm/vpc/vpc_type4.puml +23 -0
- data/docs/dev/cfm/vpc/vpc_type5.puml +25 -0
- data/docs/dev/cfm/vpc/vpc_type6.puml +26 -0
- data/docs/dev/cfm/vpc/vpc_type7.puml +39 -0
- data/docs/dev/ec2/core_model.puml +43 -0
- data/docs/dev/ec2/ec2.md +36 -0
- data/docs/dev/ec2/ec2_type1.puml +27 -0
- data/docs/dev/ec2/ec2_type2.puml +43 -0
- data/docs/dev/ec2/ec2_type3.puml +44 -0
- data/docs/dev/ec2/ec2_type4.puml +43 -0
- data/docs/dev/ec2/ec2_type5.puml +45 -0
- data/docs/dev/ec2/ec2_type6.puml +46 -0
- data/docs/dev/ec2/ec2_type7.puml +79 -0
- data/docs/dev/ec2/images/.keep +0 -0
- data/docs/dev/ec2/images/ec2_core_model.png +0 -0
- data/docs/dev/ec2/images/ec2_type1.png +0 -0
- data/docs/dev/ec2/images/ec2_type2.png +0 -0
- data/docs/dev/ec2/images/ec2_type3.png +0 -0
- data/docs/dev/ec2/images/ec2_type4.png +0 -0
- data/docs/dev/ec2/images/ec2_type5.png +0 -0
- data/docs/dev/ec2/images/ec2_type6.png +0 -0
- data/docs/dev/ec2/images/ec2_type7.png +0 -0
- data/docs/dev/vpc/core_model.puml +49 -0
- data/docs/dev/vpc/images/core_model.png +0 -0
- data/docs/dev/vpc/images/simple.png +0 -0
- data/docs/dev/vpc/images/standard.png +0 -0
- data/docs/dev/vpc/simple.puml +17 -0
- data/docs/dev/vpc/standard.puml +24 -0
- data/docs/dev/vpc/vpc.md +19 -0
- data/docs/ops/build_aws_sdk_repl.md +19 -0
- data/docs/ops/images/.keep +0 -0
- data/docs/ops/run_rake_task.md +89 -0
- data/docs/ops/ship_circleci.md +9 -0
- data/docs/ops/ship_jenkins.md +20 -0
- data/docs/ops/ship_ruby_gem.md +26 -0
- data/docs/template_catalog.md +6 -0
- data/docs/template_pattern.md +13 -0
- data/docs/template_recipe.md +6 -0
- data/docs/template_spec.md +8 -0
- data/etude_for_aws.gemspec +41 -0
- data/etude_for_aws.iml +42 -0
- data/exe/etude_for_aws +3 -0
- data/lib/etude_for_aws.rb +38 -0
- data/lib/etude_for_aws/cfm/configuration.rb +39 -0
- data/lib/etude_for_aws/cfm/vpc/cfm_templates/vpc-1az-1subnet-pub.template +529 -0
- data/lib/etude_for_aws/cfm/vpc/cfm_templates/vpc-1az-2subnet-pub-pri.template +790 -0
- data/lib/etude_for_aws/cfm/vpc/cfm_templates/vpc-1az-2subnet-pub.template +634 -0
- data/lib/etude_for_aws/cfm/vpc/cfm_templates/vpc-2az-2subnet-pri.template +645 -0
- data/lib/etude_for_aws/cfm/vpc/cfm_templates/vpc-2az-2subnet-pub-pri.template +611 -0
- data/lib/etude_for_aws/cfm/vpc/cfm_templates/vpc-2az-2subnet-pub.template +646 -0
- data/lib/etude_for_aws/cfm/vpc/cfm_templates/vpc-2az-4subnet-pub-pri.template +1010 -0
- data/lib/etude_for_aws/cfm/vpc/null_vpc.rb +13 -0
- data/lib/etude_for_aws/cfm/vpc/one_az_one_public_subnet_vpc.rb +45 -0
- data/lib/etude_for_aws/cfm/vpc/one_az_two_public_and_private_subnet_vpc.rb +47 -0
- data/lib/etude_for_aws/cfm/vpc/one_az_two_public_subnet_vpc.rb +47 -0
- data/lib/etude_for_aws/cfm/vpc/two_az_one_public_subnet_and_private_subnet_vpc.rb +52 -0
- data/lib/etude_for_aws/cfm/vpc/two_az_two_private_subnet_vpc.rb +38 -0
- data/lib/etude_for_aws/cfm/vpc/two_az_two_public_subnet_and_private_subnet_vpc.rb +38 -0
- data/lib/etude_for_aws/cfm/vpc/two_az_two_public_subnet_vpc.rb +38 -0
- data/lib/etude_for_aws/cfm/vpc/vpc.rb +104 -0
- data/lib/etude_for_aws/ec2/configuration.rb +66 -0
- data/lib/etude_for_aws/ec2/ec2.rb +218 -0
- data/lib/etude_for_aws/ec2/ec2_api_gateway.rb +127 -0
- data/lib/etude_for_aws/ec2/ec2_instance.rb +107 -0
- data/lib/etude_for_aws/ec2/key_pair.rb +46 -0
- data/lib/etude_for_aws/ec2/security_group.rb +75 -0
- data/lib/etude_for_aws/ec2/vpc_interface.rb +11 -0
- data/lib/etude_for_aws/helpers/certification_helper.rb +16 -0
- data/lib/etude_for_aws/helpers/configuration_helper.rb +103 -0
- data/lib/etude_for_aws/tasks/cfm.rake +73 -0
- data/lib/etude_for_aws/tasks/ec2.rake +210 -0
- data/lib/etude_for_aws/tasks/vpc.rake +47 -0
- data/lib/etude_for_aws/version.rb +3 -0
- data/lib/etude_for_aws/vpc/configuration.rb +77 -0
- data/lib/etude_for_aws/vpc/customer_gateway.rb +28 -0
- data/lib/etude_for_aws/vpc/internet_gateway.rb +15 -0
- data/lib/etude_for_aws/vpc/route_table.rb +42 -0
- data/lib/etude_for_aws/vpc/simple_vpc.rb +57 -0
- data/lib/etude_for_aws/vpc/standard_vpc.rb +94 -0
- data/lib/etude_for_aws/vpc/subnet.rb +22 -0
- data/lib/etude_for_aws/vpc/vpc.rb +147 -0
- data/lib/etude_for_aws/vpc/vpc_api_gateway.rb +277 -0
- data/lib/etude_for_aws/vpc/vpc_director.rb +43 -0
- data/lib/etude_for_aws/vpc/vpn.rb +244 -0
- data/lib/etude_for_aws/vpc/vpn_connection.rb +28 -0
- data/lib/etude_for_aws/vpc/vpn_director.rb +47 -0
- data/lib/etude_for_aws/vpc/vpn_gateway.rb +36 -0
- metadata +280 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'etude_for_aws'
|
2
|
+
|
3
|
+
namespace :VPC do
|
4
|
+
desc 'シンプルなVPCを作成する'
|
5
|
+
task :create_simple_vpc do
|
6
|
+
vpc_director = VPC::VpcDirector.new(VPC::SimpleVpc.new)
|
7
|
+
vpc_director.create
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'シンプルなVPCを削除する'
|
11
|
+
task :destroy_simple_vpc do
|
12
|
+
vpc_director = VPC::VpcDirector.new(VPC::SimpleVpc.new)
|
13
|
+
vpc_director.destroy
|
14
|
+
end
|
15
|
+
|
16
|
+
desc '標準的なVPCを作成する'
|
17
|
+
task :create_standard_vpc do
|
18
|
+
vpc_director = VPC::VpcDirector.new(VPC::StandardVpc.new)
|
19
|
+
vpc_director.create
|
20
|
+
end
|
21
|
+
|
22
|
+
desc '標準的なVPCを削除する'
|
23
|
+
task :destroy_standard_vpc do
|
24
|
+
vpc_director = VPC::VpcDirector.new(VPC::StandardVpc.new)
|
25
|
+
vpc_director.destroy
|
26
|
+
end
|
27
|
+
|
28
|
+
desc '標準的なVPNを作成する'
|
29
|
+
task :create_standard_vpn do
|
30
|
+
vpc_director = VPC::VpcDirector.new(VPC::StandardVpc.new)
|
31
|
+
vpc_director.create
|
32
|
+
vpc = vpc_director.builder
|
33
|
+
vpn_director = VPC::VpnDirector.new(VPC::Vpn.new(vpc))
|
34
|
+
vpn_director.create
|
35
|
+
end
|
36
|
+
|
37
|
+
desc '標準的なVPNを削除する'
|
38
|
+
task :destroy_standard_vpn do
|
39
|
+
vpc_director = VPC::VpcDirector.new(VPC::StandardVpc.new)
|
40
|
+
vpc = vpc_director.builder
|
41
|
+
vpn_director = VPC::VpnDirector.new(VPC::Vpn.new(vpc))
|
42
|
+
vpn_director.destroy
|
43
|
+
vpc_director.destroy
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module VPC
|
2
|
+
class Configuration
|
3
|
+
include ConfigurationHelper
|
4
|
+
|
5
|
+
attr_reader :vpc_name,
|
6
|
+
:vpc_cidr_block,
|
7
|
+
:subnet_names,
|
8
|
+
:route_table_names,
|
9
|
+
:public_subnets,
|
10
|
+
:private_subnets,
|
11
|
+
:public_route_tables,
|
12
|
+
:private_route_tables,
|
13
|
+
:internet_gateway,
|
14
|
+
:vpc_name_tag,
|
15
|
+
:vpc_group_tag,
|
16
|
+
:vpn_info
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
vpc_tags = get_yaml_vpc_tags
|
20
|
+
@vpc_name = vpc_tags['NAME']['VALUE']
|
21
|
+
@vpc_group_name = vpc_tags['GROUP']['VALUE']
|
22
|
+
@vpc_cidr_block = get_yaml_vpc_cidr_block
|
23
|
+
|
24
|
+
vpc_subnets = get_yaml_vpc_subnets
|
25
|
+
@subnet_names = []
|
26
|
+
vpc_subnets['PUBLIC'].each do |v|
|
27
|
+
@subnet_names << v['CONFIG']['SUBNET_TAGS'].first['NAME']['VALUE']
|
28
|
+
end
|
29
|
+
vpc_subnets['PRIVATE'].each do |v|
|
30
|
+
@subnet_names << v['CONFIG']['SUBNET_TAGS'].first['NAME']['VALUE']
|
31
|
+
end
|
32
|
+
@public_subnets = vpc_subnets['PUBLIC']
|
33
|
+
@private_subnets = vpc_subnets['PRIVATE']
|
34
|
+
|
35
|
+
vpc_route_tables = get_yaml_vpc_route_tables
|
36
|
+
@route_table_names = []
|
37
|
+
vpc_route_tables['PUBLIC'].each do |v|
|
38
|
+
@route_table_names << v['CONFIG']['ROUTE_TABLE_TAGS'].first['NAME']['VALUE']
|
39
|
+
end
|
40
|
+
vpc_route_tables['PRIVATE'].each do |v|
|
41
|
+
@route_table_names << v['CONFIG']['ROUTE_TABLE_TAGS'].first['NAME']['VALUE']
|
42
|
+
end
|
43
|
+
@public_route_tables = vpc_route_tables['PUBLIC']
|
44
|
+
@private_route_tables = vpc_route_tables['PRIVATE']
|
45
|
+
|
46
|
+
@internet_gateway = get_yaml_internet_gateway
|
47
|
+
|
48
|
+
@vpc_name_tag = {key: vpc_tags['NAME']['KEY'], value: @vpc_name}
|
49
|
+
@vpc_group_tag = {key: vpc_tags['GROUP']['KEY'], value: @vpc_group_name}
|
50
|
+
|
51
|
+
@vpn_info = get_yaml_vpn_info
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_internet_gateway_name
|
55
|
+
internet_gateway['IG_TAGS']['NAME']['VALUE']
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_vpn_customer_gateways
|
59
|
+
vpn_info['CUSTOMER_GATEWAYS']
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_vpn_gateway
|
63
|
+
vpn_info['VPN_GATEWAY']
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_vpn_connections
|
67
|
+
vpn_info['VPN_CONNECTIONS']
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
class ConfigurationStub < Configuration
|
73
|
+
def initialize
|
74
|
+
super
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module VPC
|
2
|
+
class CustomerGateway
|
3
|
+
attr_reader :customer_gateway_id
|
4
|
+
|
5
|
+
def initialize(config,gateway,customer_gateway_id=nil)
|
6
|
+
@config = config
|
7
|
+
@gateway = gateway
|
8
|
+
@customer_gateway_id = customer_gateway_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(customer_gateway_info)
|
12
|
+
bgp_asn = customer_gateway_info['BGP_ASN']
|
13
|
+
public_ip = customer_gateway_info['PUBLIC_IP']
|
14
|
+
type = customer_gateway_info['TYPE']
|
15
|
+
customer_gateway = @gateway.create_customer_gateway(bgp_asn, public_ip, type)
|
16
|
+
@customer_gateway_id = customer_gateway[0].customer_gateway_id
|
17
|
+
resources = [@customer_gateway_id]
|
18
|
+
customer_gateway_tags = customer_gateway_info['TAGS']
|
19
|
+
tag = {key: customer_gateway_tags['NAME']['KEY'], value: customer_gateway_tags['NAME']['VALUE']}
|
20
|
+
tags = [tag, @config.vpc_group_tag]
|
21
|
+
@gateway.create_tags(resources, tags)
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete
|
25
|
+
@gateway.delete_customer_gateway(@customer_gateway_id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module VPC
|
2
|
+
class InternetGateway
|
3
|
+
attr_accessor :internet_gateway_id
|
4
|
+
|
5
|
+
def create(vpc)
|
6
|
+
@internet_gateway_id = vpc.gateway.create_internet_gateway
|
7
|
+
vpc.gateway.attach_internet_gateway(@internet_gateway_id, vpc.vpc_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
def delete(vpc)
|
11
|
+
vpc.gateway.detach_internet_gateway(vpc.vpc_id,@internet_gateway_id)
|
12
|
+
vpc.gateway.delete_internet_gateway(@internet_gateway_id)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module VPC
|
2
|
+
class RouteTable
|
3
|
+
attr_reader :route_table_id,
|
4
|
+
:associate_route_table_ids
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@associate_route_table_ids = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup(id,vpc)
|
11
|
+
@route_table_id = id
|
12
|
+
@associate_route_table_ids = vpc.gateway.select_associate_route_table_ids_by_route_table_id(@route_table_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(vpc)
|
16
|
+
@route_table_id = vpc.gateway.create_route_table(vpc.vpc_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_private_route(vpc)
|
20
|
+
vpc.gateway.create_route_private(@route_table_id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_public_route(vpc,destination_cidr_block,internet_gateway_id)
|
24
|
+
vpc.gateway.create_route_public(destination_cidr_block,internet_gateway_id,@route_table_id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_vpn_route(vpc,destination_cidr_block,vpn_gateway_id)
|
28
|
+
vpc.gateway.create_route_vpn(destination_cidr_block,vpn_gateway_id,@route_table_id)
|
29
|
+
end
|
30
|
+
|
31
|
+
def associate_route_table(vpc,route_table_id,subnet_id)
|
32
|
+
@associate_route_table_ids << vpc.gateway.associate_route_table(route_table_id,subnet_id)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(vpc)
|
36
|
+
@associate_route_table_ids.each do |id|
|
37
|
+
vpc.gateway.disassociate_route_table(id)
|
38
|
+
end
|
39
|
+
vpc.gateway.delete_route_table(route_table_id)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module VPC
|
2
|
+
class SimpleVpc < Vpc
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
end
|
6
|
+
|
7
|
+
def create_subnets
|
8
|
+
@config.public_subnets.each do |v|
|
9
|
+
subnet_cidr_block = v['CONFIG']['SUBNET_CIDR_BLOCK'].first
|
10
|
+
az = v['CONFIG']['AZ'].first
|
11
|
+
name = v['CONFIG']['SUBNET_TAGS'].first['NAME']['VALUE']
|
12
|
+
key = v['CONFIG']['SUBNET_TAGS'].first['NAME']['KEY']
|
13
|
+
subnets = @gateway.select_subnets_by_name(name)
|
14
|
+
if subnets.empty?
|
15
|
+
subnet = VPC::Subnet.new
|
16
|
+
subnet.create(self,subnet_cidr_block,az)
|
17
|
+
resources = [subnet.subnet_id]
|
18
|
+
vpc_subnet_name_tag = {key: key, value: name}
|
19
|
+
tags = [vpc_subnet_name_tag,@config.vpc_group_tag]
|
20
|
+
@gateway.create_tags(resources,tags)
|
21
|
+
@public_subnets << subnet
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_route_table
|
27
|
+
@public_subnets.each do |subnet|
|
28
|
+
@config.public_route_tables.each do |v|
|
29
|
+
destination_cidr_block = v['CONFIG']['DESTINATION_CIDR_BLOCK'].first
|
30
|
+
name = v['CONFIG']['ROUTE_TABLE_TAGS'].first['NAME']['VALUE']
|
31
|
+
key = v['CONFIG']['ROUTE_TABLE_TAGS'].first['NAME']['KEY']
|
32
|
+
route_tables = @gateway.select_route_tables_by_name(name)
|
33
|
+
if route_tables.empty?
|
34
|
+
route_table = VPC::RouteTable.new
|
35
|
+
route_table.create(self)
|
36
|
+
route_table.create_public_route(self,destination_cidr_block,@internet_gateway.internet_gateway_id)
|
37
|
+
route_table.associate_route_table(self,route_table.route_table_id,subnet.subnet_id)
|
38
|
+
|
39
|
+
resources = [route_table.route_table_id]
|
40
|
+
vpc_subnet_name_tag = {key: key, value: name}
|
41
|
+
tags = [vpc_subnet_name_tag,@config.vpc_group_tag]
|
42
|
+
@gateway.create_tags(resources,tags)
|
43
|
+
@public_route_tables << route_table
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class SimpleVpcStub < SimpleVpc
|
51
|
+
def initialize
|
52
|
+
super
|
53
|
+
@config = VPC::ConfigurationStub.new
|
54
|
+
@gateway = VPC::VpcApiGatewayStub.new
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module VPC
|
2
|
+
class StandardVpc < Vpc
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
end
|
6
|
+
|
7
|
+
def create_subnets
|
8
|
+
@config.public_subnets.each do |v|
|
9
|
+
subnet_cidr_block = v['CONFIG']['SUBNET_CIDR_BLOCK'].first
|
10
|
+
az = v['CONFIG']['AZ'].first
|
11
|
+
name = v['CONFIG']['SUBNET_TAGS'].first['NAME']['VALUE']
|
12
|
+
key = v['CONFIG']['SUBNET_TAGS'].first['NAME']['KEY']
|
13
|
+
subnets = @gateway.select_subnets_by_name(name)
|
14
|
+
if subnets.empty?
|
15
|
+
subnet = VPC::Subnet.new
|
16
|
+
subnet.create(self,subnet_cidr_block,az)
|
17
|
+
resources = [subnet.subnet_id]
|
18
|
+
vpc_subnet_name_tag = {key: key, value: name}
|
19
|
+
tags = [vpc_subnet_name_tag,@config.vpc_group_tag]
|
20
|
+
@gateway.create_tags(resources,tags)
|
21
|
+
@public_subnets << subnet
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
@config.private_subnets.each do |v|
|
26
|
+
subnet_cidr_block = v['CONFIG']['SUBNET_CIDR_BLOCK'].first
|
27
|
+
az = v['CONFIG']['AZ'].first
|
28
|
+
name = v['CONFIG']['SUBNET_TAGS'].first['NAME']['VALUE']
|
29
|
+
key = v['CONFIG']['SUBNET_TAGS'].first['NAME']['KEY']
|
30
|
+
subnets = @gateway.select_subnets_by_name(name)
|
31
|
+
if subnets.empty?
|
32
|
+
subnet = VPC::Subnet.new
|
33
|
+
subnet.create(self,subnet_cidr_block,az)
|
34
|
+
resources = [subnet.subnet_id]
|
35
|
+
vpc_subnet_name_tag = {key: key, value: name}
|
36
|
+
tags = [vpc_subnet_name_tag,@config.vpc_group_tag]
|
37
|
+
@gateway.create_tags(resources,tags)
|
38
|
+
@private_subnets << subnet
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_route_table
|
44
|
+
@public_subnets.each do |subnet|
|
45
|
+
@config.public_route_tables.each do |v|
|
46
|
+
destination_cidr_block = v['CONFIG']['DESTINATION_CIDR_BLOCK'].first
|
47
|
+
name = v['CONFIG']['ROUTE_TABLE_TAGS'].first['NAME']['VALUE']
|
48
|
+
key = v['CONFIG']['ROUTE_TABLE_TAGS'].first['NAME']['KEY']
|
49
|
+
route_tables = @gateway.select_route_tables_by_name(name)
|
50
|
+
if route_tables.empty?
|
51
|
+
route_table = VPC::RouteTable.new
|
52
|
+
route_table.create(self)
|
53
|
+
route_table.create_public_route(self,destination_cidr_block,@internet_gateway.internet_gateway_id)
|
54
|
+
route_table.associate_route_table(self,route_table.route_table_id,subnet.subnet_id)
|
55
|
+
|
56
|
+
resources = [route_table.route_table_id]
|
57
|
+
vpc_subnet_name_tag = {key: key, value: name}
|
58
|
+
tags = [vpc_subnet_name_tag,@config.vpc_group_tag]
|
59
|
+
@gateway.create_tags(resources,tags)
|
60
|
+
@route_tables << route_table
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
@private_subnets.each do |subnet|
|
66
|
+
@config.private_route_tables.each do |v|
|
67
|
+
destination_cidr_block = v['CONFIG']['DESTINATION_CIDR_BLOCK'].first
|
68
|
+
name = v['CONFIG']['ROUTE_TABLE_TAGS'].first['NAME']['VALUE']
|
69
|
+
key = v['CONFIG']['ROUTE_TABLE_TAGS'].first['NAME']['KEY']
|
70
|
+
route_tables = @gateway.select_route_tables_by_name(name)
|
71
|
+
if route_tables.empty?
|
72
|
+
route_table = VPC::RouteTable.new
|
73
|
+
route_table.create(self)
|
74
|
+
route_table.associate_route_table(self,route_table.route_table_id,subnet.subnet_id)
|
75
|
+
|
76
|
+
resources = [route_table.route_table_id]
|
77
|
+
vpc_subnet_name_tag = {key: key, value: name}
|
78
|
+
tags = [vpc_subnet_name_tag,@config.vpc_group_tag]
|
79
|
+
@gateway.create_tags(resources,tags)
|
80
|
+
@route_tables << route_table
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class StandardVpcStub < StandardVpc
|
88
|
+
def initialize
|
89
|
+
super
|
90
|
+
@config = VPC::ConfigurationStub.new
|
91
|
+
@gateway = VPC::VpcApiGatewayStub.new
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module VPC
|
2
|
+
class Subnet
|
3
|
+
attr_accessor :subnet_id,:az
|
4
|
+
|
5
|
+
def create(vpc,subnet_cidr_block,az)
|
6
|
+
@az = az
|
7
|
+
@subnet_id = vpc.gateway.create_subnet(subnet_cidr_block,vpc.vpc_id,az)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_private(vpc)
|
11
|
+
@subnet_id = vpc.gateway.create_subnet(vpc.config.subnet_cidr_block_private,vpc.vpc_id,vpc.config.vpc_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_public(vpc)
|
15
|
+
@subnet_id = vpc.gateway.create_subnet(vpc.config.subnet_cidr_block_public,vpc.vpc_id,vpc.config.vpc_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(vpc)
|
19
|
+
vpc.gateway.delete_subnet(@subnet_id)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module VPC
|
2
|
+
class Vpc
|
3
|
+
include EC2::VpcInterface
|
4
|
+
|
5
|
+
attr_reader :config,
|
6
|
+
:gateway,
|
7
|
+
:vpc_id,
|
8
|
+
:vpn
|
9
|
+
|
10
|
+
attr_accessor :subnets,
|
11
|
+
:public_subnets,
|
12
|
+
:private_subnets,
|
13
|
+
:public_route_tables,
|
14
|
+
:private_route_tables,
|
15
|
+
:route_tables,
|
16
|
+
:internet_gateway
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@config = VPC::Configuration.new
|
20
|
+
@gateway = VPC::VpcApiGateway.new
|
21
|
+
|
22
|
+
@public_subnets = []
|
23
|
+
@private_subnets = []
|
24
|
+
@public_route_tables = []
|
25
|
+
@private_route_tables = []
|
26
|
+
|
27
|
+
@gateway.select_vpcs_by_name(@config.vpc_name).each do |vpc|
|
28
|
+
@vpc_id = vpc.vpc_id
|
29
|
+
end
|
30
|
+
|
31
|
+
@subnets = []
|
32
|
+
@config.subnet_names.each do |name|
|
33
|
+
@gateway.select_subnets_by_name(name).each do |v|
|
34
|
+
subnet = VPC::Subnet.new
|
35
|
+
subnet.subnet_id = v.subnet_id
|
36
|
+
@subnets << subnet
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
name = @config.internet_gateway['IG_TAGS']['NAME']['VALUE']
|
41
|
+
@gateway.select_internet_gateways_by_name(name).each do |v|
|
42
|
+
@internet_gateway = VPC::InternetGateway.new
|
43
|
+
@internet_gateway.internet_gateway_id = v.internet_gateway_id
|
44
|
+
end
|
45
|
+
|
46
|
+
@route_tables = []
|
47
|
+
@config.route_table_names.each do |name|
|
48
|
+
@gateway.select_route_tables_by_name(name).each do |v|
|
49
|
+
route_table = VPC::RouteTable.new
|
50
|
+
route_table.setup(v.route_table_id,self)
|
51
|
+
@route_tables << route_table
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_vpc
|
57
|
+
if @gateway.select_vpcs_by_name(@config.vpc_name).empty?
|
58
|
+
@vpc_id = @gateway.create_vpc(@config.vpc_name,@config.vpc_cidr_block)
|
59
|
+
resources = [@vpc_id]
|
60
|
+
tags = [@config.vpc_name_tag,@config.vpc_group_tag]
|
61
|
+
@gateway.create_tags(resources,tags)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete_vpc
|
66
|
+
@gateway.delete_vpc(@vpc_id) unless @vpc_id.nil?
|
67
|
+
@vpc_id = nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_subnets
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete_subnets
|
74
|
+
@subnets.each do |subnet|
|
75
|
+
subnet.delete(self)
|
76
|
+
end
|
77
|
+
@subnets = []
|
78
|
+
@private_subnets = []
|
79
|
+
@public_subnets = []
|
80
|
+
end
|
81
|
+
|
82
|
+
def create_internet_gateway
|
83
|
+
internet_gateways = @gateway.select_internet_gateways_by_name(@config.vpc_name)
|
84
|
+
if internet_gateways.empty?
|
85
|
+
@internet_gateway = VPC::InternetGateway.new
|
86
|
+
@internet_gateway.create(self)
|
87
|
+
key = @config.internet_gateway['IG_TAGS']['NAME']['KEY']
|
88
|
+
name = @config.internet_gateway['IG_TAGS']['NAME']['VALUE']
|
89
|
+
resources = [@internet_gateway.internet_gateway_id]
|
90
|
+
vpc_subnet_name_tag = {key: key, value: name}
|
91
|
+
tags = [vpc_subnet_name_tag,@config.vpc_group_tag]
|
92
|
+
@gateway.create_tags(resources,tags)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def delete_internet_gateway
|
97
|
+
@internet_gateway.delete(self) unless @internet_gateway.nil?
|
98
|
+
@internet_gateway = nil
|
99
|
+
end
|
100
|
+
|
101
|
+
def create_route_table
|
102
|
+
end
|
103
|
+
|
104
|
+
def delete_route_tables
|
105
|
+
@route_tables.each do |route_table|
|
106
|
+
route_table.delete(self)
|
107
|
+
end
|
108
|
+
@route_tables = []
|
109
|
+
@private_route_tables = []
|
110
|
+
@public_route_tables = []
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_vpc_id
|
114
|
+
@vpc_id
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_subnet_infos
|
118
|
+
infos = []
|
119
|
+
|
120
|
+
@public_subnets.each do |public|
|
121
|
+
info = {}
|
122
|
+
info[:subnet_id] = public.subnet_id
|
123
|
+
info[:network] = 'Public'
|
124
|
+
info[:az] = public.az
|
125
|
+
infos << info
|
126
|
+
end
|
127
|
+
|
128
|
+
@private_subnets.each do |private|
|
129
|
+
info = {}
|
130
|
+
info[:subnet_id] = private.subnet_id
|
131
|
+
info[:network] = 'Private'
|
132
|
+
info[:az] = private.az
|
133
|
+
infos << info
|
134
|
+
end
|
135
|
+
|
136
|
+
infos
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class VpcStub < Vpc
|
141
|
+
def initialize
|
142
|
+
super
|
143
|
+
@config = VPC::ConfigurationStub.new
|
144
|
+
@gateway = VPC::VpcApiGatewayStub.new
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|