vominator 0.0.6 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f2c3eeb2bdb95eda2193e4a341e0aecbb4478d5
4
- data.tar.gz: 9e24e5a58270175f46bc3f295c265c107f330af1
3
+ metadata.gz: f0c0d2ced046104f160fbe3dcfe0eb1d62bda5de
4
+ data.tar.gz: 5c5d4b48d8c3f3e608b81e67b97754e95307a926
5
5
  SHA512:
6
- metadata.gz: 2260cee2e7f3b6ad10c0915b75eddb77b7bd7f7b40177208e8299f2d9d126c2af631562948bb2b427b82aaa59a7fe198da4c0cb8ab84ce81a7f177e5d69c0d15
7
- data.tar.gz: 133b6eca3cfa06e0b304a2ae2d378ca0b92ae0eaeb6a5762862cb93852f007fbc7ffc04336e26ce3a8e1b944594b3f22300076ae10c582a01b33ee56516df7c9
6
+ metadata.gz: ab07df9cde02ebf6fa2708dfa06d285ae8e47f5d18333c9b74f1f7e550c8d49f25200574af4fa9daed8ea41e92265e737cd75eb98630523cfbbe546a2988a4c1
7
+ data.tar.gz: e435d4d9781779295c8aea362c675c473463d84ed6d5fab1e192e1b58a261540159e34e541354db2682ddeae7b1e604a6ec978e92b04dd7eb84c850b2f6db5ff
data/README.md CHANGED
@@ -18,8 +18,6 @@ See Usage for details about puke
18
18
  2. Create ~/.vominator.yaml
19
19
  ```
20
20
  ---
21
- access_key_id: AWS_SECRET_KEY
22
- secret_access_key: AWS_SECRET_ACCESS_KEY
23
21
  configuration_path: Location to puke
24
22
  key_pair_name: infrastructure@example.com
25
23
  instances_file: Location for cache file IE /Users/foo/.vominator/instances-metadata
@@ -69,6 +67,7 @@ Usage: vominate vpc create [options]
69
67
  --parent-domain PARENT DOMAIN
70
68
  REQUIRED: The parent domain name that will be used to create a seperate subdomain zone file for the new environment. IE, if you provide foo.org and your environment as bar, this will yield a new Route 53 zone file called bar.foo.org
71
69
  --cidr-block CIDR Block REQUIRED: The network block for the new environment. This must be a /16 and the second octet should be unique for this environment. IE. 10.123.0.0/16
70
+ --account ACCOUNT REQUIRED: The AWS account that you want to create this VPC in
72
71
  -d, --debug OPTIONAL: debug output
73
72
  -h, --help OPTIONAL: Display this screen
74
73
  ```
data/lib/ec2/instances.rb CHANGED
@@ -29,10 +29,6 @@ OptionParser.new do |opts|
29
29
  options[:test] = true
30
30
  end
31
31
 
32
- opts.on('--fix-security-groups', 'OPTIONAL: Fix an instances security groups') do
33
- options[:fix_security_groups] = true
34
- end
35
-
36
32
  opts.on('--disable-term-protection', 'OPTIONAL: This will disable termination protection on the targeted instances') do
37
33
  options[:disable_term_protection] = true
38
34
  end
@@ -114,6 +110,7 @@ unless instances
114
110
  end
115
111
 
116
112
  #Get ec2 connection, which is then passed to specific functions. Maybe a better way to do this?
113
+ Aws.config[:credentials] = Aws::SharedCredentials.new(:profile_name => puke_config['account'])
117
114
  ec2 = Aws::EC2::Resource.new(region: puke_config['region_name'])
118
115
  ec2_client = Aws::EC2::Client.new(region: puke_config['region_name'])
119
116
 
@@ -146,6 +143,7 @@ instances.each do |instance|
146
143
  instance_ebs_volumes = instance['ebs'].nil? ? [] : instance['ebs']
147
144
  key_name = Vominator.get_key_pair(VOMINATOR_CONFIG)
148
145
  ssm_documents = instance['ssm_documents'].nil? ? [] : instance['ssm_documents']
146
+ instance_az = instance['az'][options[:environment]] || instance['az']
149
147
 
150
148
  LOGGER.info("Working on #{fqdn}")
151
149
 
@@ -168,9 +166,9 @@ instances.each do |instance|
168
166
  #Check to see if the subnet exists for the instance. If not we should create it.
169
167
  subnet = "#{instance_ip.rpartition('.')[0]}.0/24"
170
168
  unless existing_subnets[subnet]
171
- unless test?("Would create a subnet for #{subnet} in #{instance['az']} and associate with the appropriate routing table")
172
- existing_subnets[subnet] = Vominator::EC2.create_subnet(ec2, subnet, instance['az'], puke_config['vpc_id'], puke_config['route_tables'][instance['az']])
173
- LOGGER.success("Created #{subnet} in #{instance['az']} for #{fqdn}")
169
+ unless test?("Would create a subnet for #{subnet} in #{instance_az} and associate with the appropriate routing table")
170
+ existing_subnets[subnet] = Vominator::EC2.create_subnet(ec2, subnet, instance_az, puke_config['vpc_id'], puke_config['route_tables'][instance_az])
171
+ LOGGER.success("Created #{subnet} in #{instance_az} for #{fqdn}")
174
172
  end
175
173
  end
176
174
 
@@ -289,7 +287,7 @@ instances.each do |instance|
289
287
  LOGGER.info("#{fqdn} is missing the following security groups: #{sg_missing.join(', ')}")
290
288
  updated_groups = instance_security_groups - Vominator::EC2.set_security_groups(ec2, ec2_instance.id, instance_security_groups, vpc_security_groups)
291
289
  if updated_groups.count > 0
292
- LOGGER.fatal "Failed to set #{updated_groups.join(', ')} for #{fqdn}"
290
+ LOGGER.warning "Failed to set #{updated_groups.join(', ')} for #{fqdn}"
293
291
  else
294
292
  LOGGER.success "Succesfully set security groups for #{fqdn}"
295
293
  end
@@ -346,10 +344,9 @@ instances.each do |instance|
346
344
 
347
345
  else #The instance does not exist, in which case we want to create it.
348
346
  user_data = Vominator::Instances.generate_cloud_config(hostname, options[:environment], instance['family'], instance['chef_roles'], instance['chef_recipes'])
349
- security_group_ids = instance_security_groups.map {|sg| vpc_security_groups[sg] }
350
-
347
+ security_group_ids = instance_security_groups.map {|sg| vpc_security_groups[sg] }.compact
351
348
  unless test?("Would create #{fqdn}")
352
- ec2_instance = Vominator::EC2.create_instance(ec2, hostname, options[:environment], ami, existing_subnets[subnet].id, instance_type, key_name, instance_ip, instance['az'], security_group_ids, user_data, ebs_optimized, instance['iam_profile'])
349
+ ec2_instance = Vominator::EC2.create_instance(ec2, hostname, options[:environment], ami, existing_subnets[subnet].id, instance_type, key_name, instance_ip, instance_az, security_group_ids, user_data, ebs_optimized, instance['iam_profile'])
353
350
  if ec2_instance
354
351
  LOGGER.success("Succesfully created #{fqdn}")
355
352
  ec2_instances[instance_ip] = {:instance_id => ec2_instance.id, :security_groups => ec2_instance.security_groups.map { |sg| sg.group_name}}
@@ -104,6 +104,7 @@ unless puke_security_groups
104
104
  LOGGER.fatal('Unable to load security groups . Make sure the product is correctly defined for the environment you have selected and that a security_groups.yaml file exists with at least one group defined.')
105
105
  end
106
106
 
107
+ Aws.config[:credentials] = Aws::SharedCredentials.new(:profile_name => puke_config['account'])
107
108
  ec2_client = Aws::EC2::Client.new(region: puke_config['region_name'])
108
109
 
109
110
 
data/lib/ec2/ssm.rb CHANGED
@@ -58,6 +58,7 @@ unless test?('Vominator is running in test mode. It will NOT make any changes.')
58
58
  end
59
59
  end
60
60
 
61
+ Aws.config[:credentials] = Aws::SharedCredentials.new(:profile_name => puke_config['account'])
61
62
  ssm = Aws::SSM::Client.new(region: puke_config['region_name'])
62
63
 
63
64
  aws_documents = Vominator::SSM.get_documents(ssm)
data/lib/vominator/aws.rb CHANGED
@@ -2,8 +2,6 @@ require 'aws-sdk'
2
2
  require_relative 'vominator'
3
3
  require_relative 'constants'
4
4
 
5
- Aws.config[:credentials] = Aws::Credentials.new(VOMINATOR_CONFIG['access_key_id'], VOMINATOR_CONFIG['secret_access_key'])
6
-
7
5
  module Vominator
8
6
  class AWS
9
7
  def self.get_availability_zones(ec2_client)
@@ -12,4 +10,4 @@ module Vominator
12
10
  return zones
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Vominator
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/vpc/create.rb CHANGED
@@ -31,7 +31,11 @@ OptionParser.new do |opts|
31
31
  opts.on('--cidr-block CIDR Block', 'REQUIRED: The network block for the new environment. This must be a /16 and the second octet should be unique for this environment. IE. 10.123.0.0/16') do |value|
32
32
  options[:cidr_block] = value
33
33
  end
34
-
34
+
35
+ opts.on('--account ACCOUNT', 'REQUIRED: The AWS account that you want to create this VPC in') do |value|
36
+ options[:account] = value
37
+ end
38
+
35
39
  #opts.on('-t', '--test', 'OPTIONAL: Test run. Show what would be changed without making any actual changes') do
36
40
  # options[:test] = true
37
41
  #end
@@ -52,7 +56,7 @@ OptionParser.new do |opts|
52
56
  begin
53
57
  opts.parse!
54
58
  ## Validate Data Inputs
55
- throw Exception unless ((options.include? :environment) && (options.include? :region) && (options.include? :parent_domain) && (options.include? :cidr_block)) || options[:list]
59
+ throw Exception unless ((options.include? :environment) && (options.include? :region) && (options.include? :parent_domain) && (options.include? :cidr_block) && (options.include? :account)) || options[:list]
56
60
  rescue
57
61
  puts opts
58
62
  exit
@@ -81,6 +85,7 @@ else
81
85
  puke_config['region_name'] = options[:region]
82
86
  end
83
87
 
88
+ Aws.config[:credentials] = Aws::SharedCredentials.new(:profile_name => options[:account])
84
89
  ec2_client = Aws::EC2::Client.new(region: puke_config['region_name'])
85
90
  r53_client = Aws::Route53::Client.new(region: puke_config['region_name'])
86
91
 
@@ -125,6 +130,8 @@ end
125
130
 
126
131
  vpc = Vominator::VPC.create_vpc(ec2_client,options[:cidr_block])
127
132
 
133
+ Vominator::EC2.tag_resource(ec2_client, vpc.vpc_id,[{key: 'Name', value: fqdn}])
134
+
128
135
  gateway = Vominator::VPC.create_internet_gateway(ec2_client)
129
136
 
130
137
  Vominator::VPC.attach_internet_gateway(ec2_client, gateway.internet_gateway_id, vpc.vpc_id)
@@ -146,6 +153,13 @@ availability_zones.each do |zone|
146
153
 
147
154
  Vominator::EC2.tag_resource(ec2_client, private_route_table.route_table_id,[{key: 'Name', value: "nat-#{options[:environment]}-#{zone}"}])
148
155
 
156
+ # Seed Initial Private Subnet
157
+ private_subnet_cidr_block = "#{options[:cidr_block].split('.')[0]}.#{options[:cidr_block].split('.')[1]}.1#{third_octet}.0/24"
158
+ private_subnet = Vominator::VPC.create_subnet(ec2_client, vpc.vpc_id, private_subnet_cidr_block, zone)
159
+
160
+ Vominator::VPC.associate_route_table(ec2_client, private_subnet.subnet_id, private_route_table.route_table_id)
161
+
162
+ # Seed Initial Public Subnet
149
163
  public_subnet_cidr_block = "#{options[:cidr_block].split('.')[0]}.#{options[:cidr_block].split('.')[1]}.#{third_octet}.0/24"
150
164
  public_subnet = Vominator::VPC.create_subnet(ec2_client, vpc.vpc_id, public_subnet_cidr_block, zone)
151
165
 
@@ -168,6 +182,7 @@ end
168
182
 
169
183
  config = {
170
184
  options[:environment] => {
185
+ 'account' => options[:account],
171
186
  'vpc_id' => vpc.vpc_id,
172
187
  'route_tables' => route_tables,
173
188
  'region_name' => options[:region],
@@ -23,8 +23,6 @@ describe Vominator do
23
23
  subject { vominator_config }
24
24
 
25
25
  it { is_expected.not_to be false }
26
- it { is_expected.to include('access_key_id' => 'DUMMY_ACCESS_KEY') }
27
- it { is_expected.to include('secret_access_key' => 'DUMMY_SECRET_KEY') }
28
26
  it { is_expected.to include('configuration_path' => 'test/puke') }
29
27
  it { is_expected.to include('key_pair_name' => 'ci@example.com') }
30
28
  it { is_expected.to include('chef_client_key' => 'ci.pem') }
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  test:
3
+ account: example-account
3
4
  vpc_id: vpc-ada2d4c8
4
5
  region_name: us-east-1
5
6
  zone: Z2IOTRJNNABNJ
data/test/vominator.yaml CHANGED
@@ -1,6 +1,4 @@
1
1
  ---
2
- access_key_id: DUMMY_ACCESS_KEY
3
- secret_access_key: DUMMY_SECRET_KEY
4
2
  configuration_path: test/puke
5
3
  key_pair_name: ci@example.com
6
4
  chef_client_key: ci.pem
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vominator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Kelly
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-02-27 00:00:00.000000000 Z
13
+ date: 2016-04-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk