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,45 @@
|
|
1
|
+
module CFM
|
2
|
+
class OneAzOnePublicSubnetVpc < Vpc
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
template_file = @config.get_template_file(CFM::Vpc::TYPE.fetch(1))
|
6
|
+
file = get_template_full_path(template_file)
|
7
|
+
@config.template = File.read(file)
|
8
|
+
@config.parameters = [
|
9
|
+
{
|
10
|
+
parameter_key: "AZ1",
|
11
|
+
parameter_value: @config.azs[0],
|
12
|
+
use_previous_value: false,
|
13
|
+
},
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_subnet_info(logical_resource_id)
|
18
|
+
info = {}
|
19
|
+
info[:subnet_id] = @cfm.describe_stack_resource({stack_name: @config.stack_name, logical_resource_id: logical_resource_id}).stack_resource_detail.physical_resource_id
|
20
|
+
info[:az] = @config.azs[0]
|
21
|
+
info
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_subnet_infos
|
25
|
+
infos = []
|
26
|
+
infos << get_subnet_info('Subnet')
|
27
|
+
infos
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class OneAzOnePublicSubnetVpcStub < VpcStub
|
32
|
+
def get_subnet_info
|
33
|
+
info = {}
|
34
|
+
info[:subnet_id] = 'DUMMY_SUBNET_ID'
|
35
|
+
info[:az] = 'DUMMY_AZ'
|
36
|
+
info
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_subnet_infos
|
40
|
+
infos = []
|
41
|
+
infos << get_subnet_info
|
42
|
+
infos
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module CFM
|
2
|
+
class OneAzTwoPublicAndPrivateSubnetVpc < Vpc
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
template_file = @config.get_template_file(CFM::Vpc::TYPE.fetch(3))
|
6
|
+
file = get_template_full_path(template_file)
|
7
|
+
@config.template = File.read(file)
|
8
|
+
@config.parameters = [
|
9
|
+
{
|
10
|
+
parameter_key: "AZ1",
|
11
|
+
parameter_value: @config.azs[0],
|
12
|
+
use_previous_value: false,
|
13
|
+
},
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_subnet_info(logical_resource_id)
|
18
|
+
info = {}
|
19
|
+
info[:subnet_id] = @cfm.describe_stack_resource({stack_name: @config.stack_name, logical_resource_id: logical_resource_id}).stack_resource_detail.physical_resource_id
|
20
|
+
info[:az] = @config.azs[0]
|
21
|
+
info
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_subnet_infos
|
25
|
+
infos = []
|
26
|
+
infos << get_subnet_info('PublicSubnet')
|
27
|
+
infos << get_subnet_info('PrivateSubnet')
|
28
|
+
infos
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class OneAzTwoPublicAndPrivateSubnetVpcStub < VpcStub
|
33
|
+
def get_subnet_info
|
34
|
+
info = {}
|
35
|
+
info[:subnet_id] = 'DUMMY_SUBNET_ID'
|
36
|
+
info[:az] = 'DUMMY_AZ'
|
37
|
+
info
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_subnet_infos
|
41
|
+
infos = []
|
42
|
+
infos << get_subnet_info
|
43
|
+
infos << get_subnet_info
|
44
|
+
infos
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module CFM
|
2
|
+
class OneAzTwoPublicSubnetVpc < Vpc
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
template_file = @config.get_template_file(CFM::Vpc::TYPE.fetch(2))
|
6
|
+
file = get_template_full_path(template_file)
|
7
|
+
@config.template = File.read(file)
|
8
|
+
@config.parameters = [
|
9
|
+
{
|
10
|
+
parameter_key: "AZ1",
|
11
|
+
parameter_value: @config.azs[0],
|
12
|
+
use_previous_value: false,
|
13
|
+
},
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_subnet_info(logical_resource_id)
|
18
|
+
info = {}
|
19
|
+
info[:subnet_id] = @cfm.describe_stack_resource({stack_name: @config.stack_name, logical_resource_id: logical_resource_id}).stack_resource_detail.physical_resource_id
|
20
|
+
info[:az] = @config.azs[0]
|
21
|
+
info
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_subnet_infos
|
25
|
+
infos = []
|
26
|
+
infos << get_subnet_info('PublicSubnet1a')
|
27
|
+
infos << get_subnet_info('PublicSubnet2a')
|
28
|
+
infos
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class OneAzTwoPublicSubnetVpcStub < VpcStub
|
33
|
+
def get_subnet_info
|
34
|
+
info = {}
|
35
|
+
info[:subnet_id] = 'DUMMY_SUBNET_ID'
|
36
|
+
info[:az] = 'DUMMY_AZ'
|
37
|
+
info
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_subnet_infos
|
41
|
+
infos = []
|
42
|
+
infos << get_subnet_info
|
43
|
+
infos << get_subnet_info
|
44
|
+
infos
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module CFM
|
2
|
+
class TwoAzOnePublicSubnetAndPrivateSubnetVpc < Vpc
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
template_file = @config.get_template_file(CFM::Vpc::TYPE.fetch(6))
|
6
|
+
file = get_template_full_path(template_file)
|
7
|
+
@config.template = File.read(file)
|
8
|
+
@config.parameters = [
|
9
|
+
{
|
10
|
+
parameter_key: "AZ1",
|
11
|
+
parameter_value: @config.azs[0],
|
12
|
+
use_previous_value: false,
|
13
|
+
},
|
14
|
+
{
|
15
|
+
parameter_key: "AZ2",
|
16
|
+
parameter_value: @config.azs[1],
|
17
|
+
use_previous_value: false,
|
18
|
+
},
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_subnet_info(logical_resource_id,az)
|
23
|
+
info = {}
|
24
|
+
info[:subnet_id] = @cfm.describe_stack_resource({stack_name: @config.stack_name, logical_resource_id: logical_resource_id}).stack_resource_detail.physical_resource_id
|
25
|
+
info[:az] = az
|
26
|
+
info
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_subnet_infos
|
30
|
+
infos = []
|
31
|
+
infos << get_subnet_info('PublicSubnet1a',@config.azs[0])
|
32
|
+
infos << get_subnet_info('PrivateSubnet1c',@config.azs[1])
|
33
|
+
infos
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class TwoAzOnePublicSubnetAndPrivateSubnetVpcStub < VpcStub
|
38
|
+
def get_subnet_info
|
39
|
+
info = {}
|
40
|
+
info[:subnet_id] = 'DUMMY_SUBNET_ID'
|
41
|
+
info[:az] = 'DUMMY_AZ'
|
42
|
+
info
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_subnet_infos
|
46
|
+
infos = []
|
47
|
+
infos << get_subnet_info
|
48
|
+
infos << get_subnet_info
|
49
|
+
infos
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CFM
|
2
|
+
class TwoAzTwoPrivateSubnetVpc < Vpc
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
template_file = @config.get_template_file(CFM::Vpc::TYPE.fetch(4))
|
6
|
+
file = get_template_full_path(template_file)
|
7
|
+
@config.template = File.read(file)
|
8
|
+
@config.parameters = [
|
9
|
+
{
|
10
|
+
parameter_key: "AZ1",
|
11
|
+
parameter_value: @config.azs[0],
|
12
|
+
use_previous_value: false,
|
13
|
+
},
|
14
|
+
{
|
15
|
+
parameter_key: "AZ2",
|
16
|
+
parameter_value: @config.azs[1],
|
17
|
+
use_previous_value: false,
|
18
|
+
},
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class TwoAzTwoPrivateSubnetVpcStub < VpcStub
|
24
|
+
def get_subnet_info
|
25
|
+
info = {}
|
26
|
+
info[:subnet_id] = 'DUMMY_SUBNET_ID'
|
27
|
+
info[:az] = 'DUMMY_AZ'
|
28
|
+
info
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_subnet_infos
|
32
|
+
infos = []
|
33
|
+
infos << get_subnet_info
|
34
|
+
infos << get_subnet_info
|
35
|
+
infos
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CFM
|
2
|
+
class TwoAzTwoPublicSubnetAndPrivateSubnetVpc < Vpc
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
template_file = @config.get_template_file(CFM::Vpc::TYPE.fetch(7))
|
6
|
+
file = get_template_full_path(template_file)
|
7
|
+
@config.template = File.read(file)
|
8
|
+
@config.parameters = [
|
9
|
+
{
|
10
|
+
parameter_key: "AZ1",
|
11
|
+
parameter_value: @config.azs[0],
|
12
|
+
use_previous_value: false,
|
13
|
+
},
|
14
|
+
{
|
15
|
+
parameter_key: "AZ2",
|
16
|
+
parameter_value: @config.azs[1],
|
17
|
+
use_previous_value: false,
|
18
|
+
},
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class TwoAzTwoPublicSubnetAndPrivateSubnetVpcStub < VpcStub
|
24
|
+
def get_subnet_info
|
25
|
+
info = {}
|
26
|
+
info[:subnet_id] = 'DUMMY_SUBNET_ID'
|
27
|
+
info[:az] = 'DUMMY_AZ'
|
28
|
+
info
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_subnet_infos
|
32
|
+
infos = []
|
33
|
+
infos << get_subnet_info
|
34
|
+
infos << get_subnet_info
|
35
|
+
infos
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CFM
|
2
|
+
class TwoAzTwoPublicSubnetVpc < Vpc
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
template_file = @config.get_template_file(CFM::Vpc::TYPE.fetch(5))
|
6
|
+
file = get_template_full_path(template_file)
|
7
|
+
@config.template = File.read(file)
|
8
|
+
@config.parameters = [
|
9
|
+
{
|
10
|
+
parameter_key: "AZ1",
|
11
|
+
parameter_value: @config.azs[0],
|
12
|
+
use_previous_value: false,
|
13
|
+
},
|
14
|
+
{
|
15
|
+
parameter_key: "AZ2",
|
16
|
+
parameter_value: @config.azs[1],
|
17
|
+
use_previous_value: false,
|
18
|
+
},
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class TwoAzTwoPublicSubnetVpcStub < VpcStub
|
24
|
+
def get_subnet_info
|
25
|
+
info = {}
|
26
|
+
info[:subnet_id] = 'DUMMY_SUBNET_ID'
|
27
|
+
info[:az] = 'DUMMY_AZ'
|
28
|
+
info
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_subnet_infos
|
32
|
+
infos = []
|
33
|
+
infos << get_subnet_info
|
34
|
+
infos << get_subnet_info
|
35
|
+
infos
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module CFM
|
2
|
+
class Vpc
|
3
|
+
include EC2::VpcInterface
|
4
|
+
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
TYPE = {
|
8
|
+
1 => :ONE_AZ_ONE_PUB,
|
9
|
+
2 => :ONE_AZ_TWO_PUB,
|
10
|
+
3 => :ONE_AZ_ONE_PUB_PRI,
|
11
|
+
4 => :TWO_AZ_TWO_PRI,
|
12
|
+
5 => :TWO_AZ_TWO_PUB,
|
13
|
+
6 => :TWO_AZ_ONE_PUB_RPI,
|
14
|
+
7 => :TWO_AZ_TWO_PUB_PRI
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@config = Configuration.new
|
19
|
+
@cfm = @config.create_client
|
20
|
+
set_vpc_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def create
|
24
|
+
unless collect_stack_name.include?(@config.stack_name)
|
25
|
+
resp = @cfm.create_stack({
|
26
|
+
stack_name: @config.stack_name,
|
27
|
+
template_body: @config.template,
|
28
|
+
parameters: @config.parameters,
|
29
|
+
tags: [
|
30
|
+
{
|
31
|
+
key: 'Name',
|
32
|
+
value: @config.stack_tag_value,
|
33
|
+
},
|
34
|
+
],
|
35
|
+
})
|
36
|
+
@cfm.wait_until(:stack_create_complete, {stack_name: @config.stack_name})
|
37
|
+
@config.stack_id = resp.stack_id
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy
|
42
|
+
if collect_stack_name.include?(@config.stack_name)
|
43
|
+
resp = @cfm.delete_stack({
|
44
|
+
stack_name: @config.stack_name,
|
45
|
+
})
|
46
|
+
@cfm.wait_until(:stack_delete_complete, {stack_name: @config.stack_name})
|
47
|
+
@config.stack_id = resp.to_s
|
48
|
+
@config.vpc_id = nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_vpc_id
|
53
|
+
@config.vpc_id
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_subnet_infos
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
def get_template_full_path(template_file)
|
61
|
+
Dir.pwd + @config.template_path + template_file
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def collect_stack_name
|
66
|
+
stack_names = []
|
67
|
+
@cfm.describe_stacks.stacks.each do |stack|
|
68
|
+
stack_names << stack.stack_name
|
69
|
+
end
|
70
|
+
stack_names
|
71
|
+
end
|
72
|
+
|
73
|
+
def select_vpc_id
|
74
|
+
@cfm.describe_stack_resource({stack_name: @config.stack_name, logical_resource_id: 'VPC'}).stack_resource_detail.physical_resource_id
|
75
|
+
end
|
76
|
+
|
77
|
+
def set_vpc_id
|
78
|
+
if collect_stack_name.include?(@config.stack_name)
|
79
|
+
@config.vpc_id = get_vpc_id
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class VpcStub < Vpc
|
85
|
+
include EC2::VpcInterface
|
86
|
+
|
87
|
+
def initialize
|
88
|
+
super
|
89
|
+
@config = ConfigurationStub.new
|
90
|
+
@cfm = @config.create_client
|
91
|
+
end
|
92
|
+
|
93
|
+
def create
|
94
|
+
p "#{self.class} Create Virtual Private Cloud"
|
95
|
+
@config.stack_id = 'DUMMY'
|
96
|
+
end
|
97
|
+
|
98
|
+
def destroy
|
99
|
+
p "#{self.class} Destroy Virtual Private Cloud"
|
100
|
+
@config.stack_id = 'Aws::EmptyStructure'
|
101
|
+
@config.vpc_id = nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module EC2
|
2
|
+
class Configuration
|
3
|
+
include ConfigurationHelper
|
4
|
+
|
5
|
+
attr_accessor :vpc_id,
|
6
|
+
:subnet_id,
|
7
|
+
:az,
|
8
|
+
:instance_tags
|
9
|
+
|
10
|
+
attr_reader :security_group_name,
|
11
|
+
:security_group_description,
|
12
|
+
:key_pair_name,
|
13
|
+
:key_pair_path,
|
14
|
+
:image_id,
|
15
|
+
:instance_type,
|
16
|
+
:min_count,
|
17
|
+
:max_count,
|
18
|
+
:instance_tags_public,
|
19
|
+
:instance_tags_private,
|
20
|
+
:stub
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
ec2_config = get_yaml_ec2_config
|
24
|
+
@security_group_name = ec2_config['SECURITY_GROUP_NAME']
|
25
|
+
@security_group_description = ec2_config['SECURITY_GROUP_DESCRIPTION']
|
26
|
+
@key_pair_name = ec2_config['KEY_PAIR_NAME']
|
27
|
+
@key_pair_path = ec2_config['KEY_PAIR_PATH']
|
28
|
+
@image_id = ec2_config['IMAGE_ID']
|
29
|
+
@instance_type = ec2_config['INSTANCE_TYPE']
|
30
|
+
@min_count = ec2_config['MIN_COUNT'].to_i
|
31
|
+
@max_count = ec2_config['MAX_COUNT'].to_i
|
32
|
+
|
33
|
+
vpc_tags = get_yaml_vpc_tags
|
34
|
+
group_value = vpc_tags['GROUP']['VALUE']
|
35
|
+
instances = get_yaml_ec2_instances
|
36
|
+
@instance_tags_public = []
|
37
|
+
unless instances['PUBLIC'].nil?
|
38
|
+
instances['PUBLIC'].each do |v|
|
39
|
+
name_value = v['CONFIG']['INSTANCE_TAGS'].first['NAME']['VALUE']
|
40
|
+
@instance_tags_public << [{key: 'Name', value: name_value}, {key: 'Group', value: group_value}]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
@instance_tags_private = []
|
44
|
+
unless instances['PRIVATE'].nil?
|
45
|
+
instances['PRIVATE'].each do |v|
|
46
|
+
name_value = v['CONFIG']['INSTANCE_TAGS'].first['NAME']['VALUE']
|
47
|
+
@instance_tags_private << [{key: 'Name', value: name_value}, {key: 'Group', value: group_value}]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
@instance_tags = []
|
51
|
+
|
52
|
+
@stub = false
|
53
|
+
end
|
54
|
+
|
55
|
+
def stub?
|
56
|
+
@stub
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class ConfigurationStub < Configuration
|
61
|
+
def initialize
|
62
|
+
super
|
63
|
+
@stub = true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|