ami_spec 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87eebf7f488963ef90dec3e34678f6c75bd36eaf896467edaeb1651271ad8d8a
4
- data.tar.gz: 6425586e1732b2e78cb4099047f1ba6e5e99d08deb0dbd5aa4031daa24beb597
3
+ metadata.gz: 5c700a6f5448ab25c9b1247276aa03da13a25e8b6ee11c99627c0001b980bb7d
4
+ data.tar.gz: 162c0f91f251d700daecf145b80dc713d5f7770d6f718fd96276461c61497ab3
5
5
  SHA512:
6
- metadata.gz: 93dd91143f960c39da8cfdf24522a9daf271d4aaf3a69db345d4621e40c9a10ca43158abe19a0e2268cca9bbc699267fe9c54b954275d5e7bccb404eb2e487f7
7
- data.tar.gz: 7e1a7762ed90bfd5266ab9a869fe1a78af16e065fe8d5c8ac0663376195e9029d7b23c8d8d7ab818cba7fdf5d2ee821eab723b8b176459880685851e4a055ebe
6
+ metadata.gz: f202c83cce3214a851739e6eaa2564b8a8c85f3b865732196d11381a789a4e5ee15b44b381b1d0dddd41109614c0b1a1ba2aff58e9bfaacdb0f97a28be164c73
7
+ data.tar.gz: db260f6ed177d0f6574d4e53a4d445c340806c5c81c95d1f5ba3173673fe698c7be11a0a4a68c0075698d31f7ea4d0807262574284b45f44f1200861807a9f6b
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # AmiSpec
2
2
 
3
+ [![License MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/envato/ami-spec/blob/master/LICENSE.txt)
4
+ [![Gem Version](https://badge.fury.io/rb/ami_spec.svg)](https://badge.fury.io/rb/ami_spec)
5
+ [![Build Status](https://travis-ci.org/envato/ami-spec.svg?branch=master)](https://travis-ci.org/envato/ami-spec)
6
+
3
7
  Acceptance testing your AMIs.
4
8
 
5
9
  AmiSpec is a RubyGem used to launch an Amazon Machine Image (AMI) and run ServerSpecs against it. It wraps around the AWS API and ServerSpec to spin up, test and tear down instances.
@@ -35,7 +39,8 @@ Options:
35
39
  -o, --role-ami-file=<s> A file containing comma separated roles and amis. i.e.
36
40
  web_server,ami-id.
37
41
  -s, --specs=<s> The directory to find ServerSpecs
38
- -u, --subnet-id=<s> The subnet to start the instance in
42
+ -u, --subnet-id=<s> The subnet to start the instance in. If not provided a subnet
43
+ will be chosen from the default VPC
39
44
  -k, --key-name=<s> The SSH key name to assign to instances. If not provided a
40
45
  temporary key pair will be generated in AWS
41
46
  -e, --key-file=<s> The SSH private key file associated to the key_name
@@ -1,5 +1,6 @@
1
1
  require 'ami_spec/aws_instance'
2
2
  require 'ami_spec/aws_instance_options'
3
+ require 'ami_spec/aws_default_vpc'
3
4
  require 'ami_spec/aws_key_pair'
4
5
  require 'ami_spec/aws_security_group'
5
6
  require 'ami_spec/server_spec'
@@ -54,6 +55,13 @@ module AmiSpec
54
55
 
55
56
  ec2 = Aws::EC2::Resource.new(options[:aws_region] ? {region: options[:aws_region]} : {})
56
57
 
58
+ if options[:subnet_id].nil?
59
+ default_vpc_subnet = AwsDefaultVpc.find_subnet(ec2: ec2)
60
+ raise 'No default VPC subnet found. Please specify a subnet id.' if default_vpc_subnet.nil?
61
+ options[:subnet_id] = default_vpc_subnet.id
62
+ logger.info("Using subnet #{options[:subnet_id]} from the default VPC")
63
+ end
64
+
57
65
  unless options[:key_name]
58
66
  key_pair = AwsKeyPair.create(ec2: ec2, logger: logger)
59
67
  options[:key_name] = key_pair.key_name
@@ -94,7 +102,7 @@ module AmiSpec
94
102
  end
95
103
 
96
104
  def self.stop_instances(instances, debug)
97
- instances.each do |instance|
105
+ instances && instances.each do |instance|
98
106
  begin
99
107
  if debug
100
108
  puts "EC2 instance ##{instance.instance_id} has not been stopped due to debug mode."
@@ -116,7 +124,7 @@ module AmiSpec
116
124
  opt :role_ami_file, "A file containing comma separated roles and amis. i.e.\nweb_server,ami-id.",
117
125
  type: :string
118
126
  opt :specs, "The directory to find ServerSpecs", type: :string, required: true
119
- opt :subnet_id, "The subnet to start the instance in", type: :string, required: true
127
+ opt :subnet_id, "The subnet to start the instance in. If not provided a subnet will be chosen from the default VPC", type: :string
120
128
  opt :key_name, "The SSH key name to assign to instances. If not provided a temporary key pair will be generated in AWS",
121
129
  type: :string
122
130
  opt :key_file, "The SSH private key file associated to the key_name", type: :string
@@ -0,0 +1,10 @@
1
+ require 'aws-sdk-ec2'
2
+
3
+ module AmiSpec
4
+ class AwsDefaultVpc
5
+ def self.find_subnet(ec2: Aws::EC2::Resource.new)
6
+ default_vpc = ec2.vpcs(filters: [{name: 'isDefault', values: ['true']}]).first
7
+ default_vpc && default_vpc.subnets.first
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module AmiSpec
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ami_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Robinson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-07-29 00:00:00.000000000 Z
12
+ date: 2019-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-ec2
@@ -120,6 +120,7 @@ files:
120
120
  - README.md
121
121
  - bin/ami_spec
122
122
  - lib/ami_spec.rb
123
+ - lib/ami_spec/aws_default_vpc.rb
123
124
  - lib/ami_spec/aws_instance.rb
124
125
  - lib/ami_spec/aws_instance_options.rb
125
126
  - lib/ami_spec/aws_key_pair.rb