vagrant-ec2setup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2984b73ce9d4e675017aac00d079bf54dcc9ce46
4
+ data.tar.gz: 8aac2d5f70cafdadd9d7ce5fa8e608bf899a9761
5
+ SHA512:
6
+ metadata.gz: f826e42fe9a73e6d581efe0e20ae30118cdd4da655fd5854fd647fcfc25624ac9e5bfc7d3cf29b0a6700a74e458343a1c383e77e66908352da43ea7ed5151b14
7
+ data.tar.gz: c07e5fddb0255461d9b5531b279cc2b8de6168d975e3a71576f2225d0f8956f83b880ed8e828c4df049c721256b9a21b39dba221dd3c72a128dc2b88d6ebb8f4
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-ec2_setup.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 yalab
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Vagrant::Ec2Setup
2
+
3
+ Setup security group ssh key as single web applicatoin server on Amazon EC2.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'vagrant-ec2_setup'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install vagrant-ec2_setup
18
+
19
+ ## Usage
20
+
21
+ Edit your Vagrantfile like this
22
+
23
+ ```
24
+ Vagrant.configure("2") do |config|
25
+ (...)
26
+ config.ec2setup.key_pair_name = 'vagrant-aws'
27
+ config.ec2setup.region = 'ap-northeast-1'
28
+ config.ec2setup.private_key_path = "#{ENV['HOME']}/.ssh/vagrant-aws.pem"
29
+ config.ec2setup.security_group_name = 'webapp'
30
+
31
+
32
+ ```
33
+
34
+ Then use it
35
+
36
+ ```
37
+ $ vagrant ec2setup
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Vagrantfile ADDED
@@ -0,0 +1,117 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
4
+ require 'vagrant/ec2setup'
5
+
6
+ Vagrant.configure("2") do |config|
7
+ # All Vagrant configuration is done here. The most common configuration
8
+ # options are documented and commented below. For a complete reference,
9
+ # please see the online documentation at vagrantup.com.
10
+
11
+ # Every Vagrant virtual environment requires a box to build off of.
12
+ config.vm.box = "base"
13
+ config.ec2setup.key_pair_name = 'vagrant-aws'
14
+ config.ec2setup.region = 'ap-northeast-1'
15
+ config.ec2setup.private_key_path = "#{ENV['HOME']}/.ssh/vagrant-aws.pem"
16
+ config.ec2setup.security_group_name = 'default'
17
+
18
+ # The url from where the 'config.vm.box' box will be fetched if it
19
+ # doesn't already exist on the user's system.
20
+ # config.vm.box_url = "http://domain.com/path/to/above.box"
21
+
22
+ # Create a forwarded port mapping which allows access to a specific port
23
+ # within the machine from a port on the host machine. In the example below,
24
+ # accessing "localhost:8080" will access port 80 on the guest machine.
25
+ # config.vm.network :forwarded_port, guest: 80, host: 8080
26
+
27
+ # Create a private network, which allows host-only access to the machine
28
+ # using a specific IP.
29
+ # config.vm.network :private_network, ip: "192.168.33.10"
30
+
31
+ # Create a public network, which generally matched to bridged network.
32
+ # Bridged networks make the machine appear as another physical device on
33
+ # your network.
34
+ # config.vm.network :public_network
35
+
36
+ # Share an additional folder to the guest VM. The first argument is
37
+ # the path on the host to the actual folder. The second argument is
38
+ # the path on the guest to mount the folder. And the optional third
39
+ # argument is a set of non-required options.
40
+ # config.vm.synced_folder "../data", "/vagrant_data"
41
+
42
+ # Provider-specific configuration so you can fine-tune various
43
+ # backing providers for Vagrant. These expose provider-specific options.
44
+ # Example for VirtualBox:
45
+ #
46
+ # config.vm.provider :virtualbox do |vb|
47
+ # # Don't boot with headless mode
48
+ # vb.gui = true
49
+ #
50
+ # # Use VBoxManage to customize the VM. For example to change memory:
51
+ # vb.customize ["modifyvm", :id, "--memory", "1024"]
52
+ # end
53
+ #
54
+ # View the documentation for the provider you're using for more
55
+ # information on available options.
56
+
57
+ # Enable provisioning with Puppet stand alone. Puppet manifests
58
+ # are contained in a directory path relative to this Vagrantfile.
59
+ # You will need to create the manifests directory and a manifest in
60
+ # the file base.pp in the manifests_path directory.
61
+ #
62
+ # An example Puppet manifest to provision the message of the day:
63
+ #
64
+ # # group { "puppet":
65
+ # # ensure => "present",
66
+ # # }
67
+ # #
68
+ # # File { owner => 0, group => 0, mode => 0644 }
69
+ # #
70
+ # # file { '/etc/motd':
71
+ # # content => "Welcome to your Vagrant-built virtual machine!
72
+ # # Managed by Puppet.\n"
73
+ # # }
74
+ #
75
+ # config.vm.provision :puppet do |puppet|
76
+ # puppet.manifests_path = "manifests"
77
+ # puppet.manifest_file = "init.pp"
78
+ # end
79
+
80
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
81
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
82
+ # some recipes and/or roles.
83
+ #
84
+ # config.vm.provision :chef_solo do |chef|
85
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
86
+ # chef.roles_path = "../my-recipes/roles"
87
+ # chef.data_bags_path = "../my-recipes/data_bags"
88
+ # chef.add_recipe "mysql"
89
+ # chef.add_role "web"
90
+ #
91
+ # # You may also specify custom JSON attributes:
92
+ # chef.json = { :mysql_password => "foo" }
93
+ # end
94
+
95
+ # Enable provisioning with chef server, specifying the chef server URL,
96
+ # and the path to the validation key (relative to this Vagrantfile).
97
+ #
98
+ # The Opscode Platform uses HTTPS. Substitute your organization for
99
+ # ORGNAME in the URL and validation key.
100
+ #
101
+ # If you have your own Chef Server, use the appropriate URL, which may be
102
+ # HTTP instead of HTTPS depending on your configuration. Also change the
103
+ # validation key to validation.pem.
104
+ #
105
+ # config.vm.provision :chef_client do |chef|
106
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
107
+ # chef.validation_key_path = "ORGNAME-validator.pem"
108
+ # end
109
+ #
110
+ # If you're using the Opscode platform, your validator client is
111
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
112
+ #
113
+ # If you have your own Chef Server, the default validation client name is
114
+ # chef-validator, unless you changed the configuration.
115
+ #
116
+ # chef.validation_client_name = "ORGNAME-validator"
117
+ end
@@ -0,0 +1,56 @@
1
+ require 'aws-sdk'
2
+ require 'net/ssh'
3
+
4
+ module VagrantPlugins
5
+ module Ec2setup
6
+ class Command < Vagrant.plugin("2", :command)
7
+ def usage
8
+ puts <<-EOS.gsub(/^ {10}/, '')
9
+ You must set AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID.
10
+ For example into your ~/.bashrc
11
+
12
+ export AWS_ACCESS_KEY_ID="Your Aws Access Key"
13
+ export AWS_SECRET_ACCESS_KEY="Your Aws Access Token"
14
+ EOS
15
+ exit
16
+ end
17
+
18
+ def execute
19
+ @config = @env.config_global.ec2setup
20
+ ENV['AWS_ACCESS_KEY_ID'] || usage
21
+ ENV['AWS_SECRET_ACCESS_KEY'] || usage
22
+ generate_key_pair
23
+ generate_security_group
24
+ end
25
+
26
+ def region
27
+ region_name = @config.region
28
+ return @region if @region
29
+ @region = ::AWS::EC2.new.regions[region_name].tap{|region|
30
+ raise "No such region #{region_name}." unless region.exists?
31
+ }
32
+ end
33
+
34
+ def generate_key_pair
35
+ key_pair_name = @config.key_pair_name
36
+ private_key_path = @config.private_key_path
37
+ @key_pair ||= if File.exists?(private_key_path) && (key = region.key_pairs[key_pair_name]).exists?
38
+ key
39
+ else
40
+ region.key_pairs.create(key_pair_name).tap{|k|
41
+ File.open(private_key_path, 'w'){|f| f.write(k.private_key) }
42
+ }
43
+ end
44
+ end
45
+
46
+ def generate_security_group
47
+ security_group_name = @config.security_group_name
48
+ return if region.security_groups.filter('group-name', security_group_name).count > 0
49
+ security_group = region.security_groups.create(security_group_name)
50
+ [22, 80, 443].each do |port|
51
+ security_group.authorize_ingress(:tcp, port, "0.0.0.0/0")
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,27 @@
1
+ module VagrantPlugins
2
+ module Ec2setup
3
+ class Config < Vagrant.plugin(2, :config)
4
+ DEFAULT_VALUES = {
5
+ key_pair_name: 'vagrant',
6
+ region: 'ap-northeast-1',
7
+ private_key_path: '~/.ssh/id_rsa',
8
+ security_group_name: 'default'
9
+ }
10
+ DEFAULT_VALUES.keys.each do |name|
11
+ attr_accessor name
12
+ end
13
+
14
+ def initialize
15
+ DEFAULT_VALUES.keys.each do |name|
16
+ instance_variable_set("@#{name}", UNSET_VALUE)
17
+ end
18
+ end
19
+
20
+ def finalize!
21
+ DEFAULT_VALUES.each do |k, v|
22
+ instance_variable_set("@#{k}", v) if instance_variable_get("@#{k}") == UNSET_VALUE
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module Ec2setup
3
+ class Plugin < Vagrant.plugin("2")
4
+ name "ec2setup"
5
+ description <<-DESC.gsub(/ {8}/, '')
6
+ Setup your ec2 server.
7
+ DESC
8
+
9
+ config("ec2setup") do
10
+ require_relative 'config'
11
+ Config
12
+ end
13
+
14
+ command("ec2setup") do
15
+ require_relative 'command'
16
+ Command
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Ec2setup
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "vagrant/ec2setup/version"
2
+ require "vagrant/ec2setup/plugin"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant/ec2setup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-ec2setup"
8
+ spec.version = Vagrant::Ec2setup::VERSION
9
+ spec.authors = ["yalab"]
10
+ spec.email = ["rudeboyjet@gmail.com"]
11
+ spec.description = "Automation setup security group, ssh key on EC2."
12
+ spec.summary = "This gem is a vagrant plugin for provider ec2 environment setup. SSH key or Security group for web application."
13
+ spec.homepage = "https://github.com/yalab/vagrant-ec2_setup"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ec2setup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - yalab
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Automation setup security group, ssh key on EC2.
42
+ email:
43
+ - rudeboyjet@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - Vagrantfile
54
+ - lib/vagrant/ec2setup.rb
55
+ - lib/vagrant/ec2setup/command.rb
56
+ - lib/vagrant/ec2setup/config.rb
57
+ - lib/vagrant/ec2setup/plugin.rb
58
+ - lib/vagrant/ec2setup/version.rb
59
+ - vagrant-ec2setup.gemspec
60
+ homepage: https://github.com/yalab/vagrant-ec2_setup
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.0.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: This gem is a vagrant plugin for provider ec2 environment setup. SSH key
84
+ or Security group for web application.
85
+ test_files: []