genesis_cli 0.0.1
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/LICENSE.txt +22 -0
- data/README.md +17 -0
- data/Thorfile +50 -0
- data/bin/genesis +3 -0
- data/genesis.gemspec +30 -0
- data/lib/genesis.rb +5 -0
- data/lib/genesis/cli.rb +125 -0
- data/lib/genesis/commands.rb +66 -0
- data/lib/genesis/version.rb +3 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8404175a13d695db7f851bbaf4f3beaa2d3b1795
|
4
|
+
data.tar.gz: 7f46627e06d7dc71167d88494245ba6797cd9d93
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ccfb66acc63bf35ac0be6632a48e25f4585a05e002274550a50f0fbadc783b3bc80db427b8ae745ac2de53c6fc5d0569d9dbb57cde691859b207e13ad66d2b9
|
7
|
+
data.tar.gz: d4da0fbb8b275365d1b2c74243704f47e03a9cbe0fbc9e99ae2951dd7bba150c36cc6dc1fa81798f6ed51a773fe036d8d5ae2409a11b96762447fe3ea2281423
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tyler Cross
|
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,17 @@
|
|
1
|
+
genesis [](https://travis-ci.org/bandwidthcom/genesis)
|
2
|
+
=========
|
3
|
+
|
4
|
+
A Terraform CLI wrapper built by the Bandwidth Incubator.
|
5
|
+
|
6
|
+
Goals:
|
7
|
+
1. Expose a command for each infrastructure-related lifecycle event in an Incubator-style project.
|
8
|
+
2. Each command should protect against accidental non-automated actions that impact infrastructure.
|
9
|
+
3. Don't do anything other than wrap the Terraform CLI
|
10
|
+
|
11
|
+
#### Installation
|
12
|
+
```gem install genesis```
|
13
|
+
|
14
|
+
#### Commands
|
15
|
+
|
16
|
+
#### License
|
17
|
+
[MIT](LICENSE.txt)
|
data/Thorfile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
require 'thor/rake_compat'
|
5
|
+
|
6
|
+
class Default < Thor
|
7
|
+
include Thor::RakeCompat
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
desc 'build', "Build #{@gem_name} into the pkg directory"
|
11
|
+
def build
|
12
|
+
Rake::Task['build'].execute
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'install', "Build and install #{@gem_name} into system gems"
|
16
|
+
def install
|
17
|
+
Rake::Task['install'].execute
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'release', "Create tag #{@gem_tag} and build and push #{@gem_name}"
|
21
|
+
def release
|
22
|
+
Rake::Task['release'].execute
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'rubocop', 'Run Rubocop on all Ruby files'
|
26
|
+
def rubocop
|
27
|
+
say 'Performing linting and style checking with rubocop...', :white
|
28
|
+
success = system 'rubocop'
|
29
|
+
exit(!success) unless success
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'spec', 'Run tests.'
|
33
|
+
def spec
|
34
|
+
say 'Running all rspec tests...', :white
|
35
|
+
success = system 'rspec spec'
|
36
|
+
exit(!success) unless success
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'check', 'Lint, style, and test.'
|
40
|
+
def check
|
41
|
+
invoke :rubocop
|
42
|
+
# invoke :spec
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(*args)
|
46
|
+
super
|
47
|
+
@gem_name = "genesis-#{Genesis::VERSION}.gem"
|
48
|
+
@gem_tag = "v#{Genesis::VERSION}"
|
49
|
+
end
|
50
|
+
end
|
data/bin/genesis
ADDED
data/genesis.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'genesis/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'genesis_cli'
|
8
|
+
spec.version = Genesis::VERSION
|
9
|
+
spec.authors = ['Tyler Cross']
|
10
|
+
spec.email = ['tcross@bandwidth.com']
|
11
|
+
spec.description = %q(A terraform wrapper for Bandwidth Incubator)
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = 'https://github.com/bandwidthcom/genesis'
|
14
|
+
spec.licenses = %w[MIT]
|
15
|
+
|
16
|
+
spec.executables = %w[genesis]
|
17
|
+
|
18
|
+
spec.files = %w[LICENSE.txt README.md Thorfile genesis.gemspec]
|
19
|
+
spec.files += Dir.glob('bin/**/*')
|
20
|
+
spec.files += Dir.glob('lib/**/*.rb')
|
21
|
+
spec.files += Dir.glob('spec/**/*')
|
22
|
+
|
23
|
+
spec.test_files = Dir.glob('spec/**/*')
|
24
|
+
|
25
|
+
spec.require_paths = %w[lib]
|
26
|
+
|
27
|
+
spec.add_dependency 'thor'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
30
|
+
end
|
data/lib/genesis.rb
ADDED
data/lib/genesis/cli.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'genesis/commands'
|
3
|
+
|
4
|
+
module Genesis
|
5
|
+
class Cli < Thor
|
6
|
+
include Commands
|
7
|
+
|
8
|
+
desc 'refresh', 'Reconcile state with the real-world infrastructure'
|
9
|
+
def refresh
|
10
|
+
system refresh_command
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'plan', 'Output an execution plan'
|
14
|
+
def plan
|
15
|
+
system plan_command
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'apply', 'Apply infrastructure changes to match plan'
|
19
|
+
def apply
|
20
|
+
confirmed = if @prompt
|
21
|
+
message = 'Are you sure you want to apply changes? (y/n)'
|
22
|
+
yes?(message, :red)
|
23
|
+
else
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
system apply_command if confirmed
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'show', 'Output contents of the state file'
|
31
|
+
def show
|
32
|
+
system show_command
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'destroy', 'Destroy infrastructure Terraform knows about'
|
36
|
+
def destroy
|
37
|
+
plan_created = system destroy_plan_command
|
38
|
+
exit(1) unless plan_created
|
39
|
+
|
40
|
+
confirmed = if @prompt
|
41
|
+
yes?('Are you sure you want to destroy infrastructure? (y/n)', :red)
|
42
|
+
else
|
43
|
+
true
|
44
|
+
end
|
45
|
+
|
46
|
+
system apply_plan_command if confirmed
|
47
|
+
File.delete(plan_file) if File.exist?(plan_file)
|
48
|
+
end
|
49
|
+
|
50
|
+
option :prompt, {
|
51
|
+
type: :boolean,
|
52
|
+
default: true,
|
53
|
+
desc: 'Prompt before executing dangerous commands'
|
54
|
+
}
|
55
|
+
def initialize(*args)
|
56
|
+
super
|
57
|
+
|
58
|
+
validate_environment_variables
|
59
|
+
validate_path
|
60
|
+
validate_terraform_directory
|
61
|
+
|
62
|
+
@aws_access_key = ENV['AWS_ACCESS_KEY']
|
63
|
+
@aws_secret_key = ENV['AWS_SECRET_KEY']
|
64
|
+
@aws_key_pair = ENV['AWS_KEY_PAIR']
|
65
|
+
@prompt = options[:prompt]
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def validate_environment_variables
|
71
|
+
# Check for required environment variables
|
72
|
+
required_variables = %w[
|
73
|
+
AWS_ACCESS_KEY
|
74
|
+
AWS_SECRET_KEY
|
75
|
+
AWS_KEY_PAIR
|
76
|
+
]
|
77
|
+
|
78
|
+
required_variables.each do |variable|
|
79
|
+
unless ENV.member? variable
|
80
|
+
$stderr.puts "Missing required environment variable: '#{variable}'"
|
81
|
+
exit(1)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def validate_path
|
87
|
+
# Check for required executables on the system path
|
88
|
+
required_executables = %w[terraform]
|
89
|
+
|
90
|
+
required_executables.each do |name|
|
91
|
+
next unless /#{name}/.match(ENV['PATH']).nil?
|
92
|
+
|
93
|
+
message = "Missing required executable on system path: '#{name}'"
|
94
|
+
$stderr.puts message
|
95
|
+
exit(1)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def validate_terraform_directory
|
100
|
+
# Check that terraform directory is present
|
101
|
+
path = File.join(project_root, 'terraform')
|
102
|
+
|
103
|
+
return if Dir.exist? path
|
104
|
+
|
105
|
+
$stderr.puts "Unable to find terraform directory: #{path}"
|
106
|
+
exit(1)
|
107
|
+
end
|
108
|
+
|
109
|
+
def project_root
|
110
|
+
Dir.pwd
|
111
|
+
end
|
112
|
+
|
113
|
+
def terraform_dir
|
114
|
+
File.join(project_root, 'terraform')
|
115
|
+
end
|
116
|
+
|
117
|
+
def state_file
|
118
|
+
File.join(terraform_dir, 'terraform.tfstate')
|
119
|
+
end
|
120
|
+
|
121
|
+
def plan_file
|
122
|
+
File.join(terraform_dir, 'terraform.tfplan')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Genesis
|
4
|
+
module Commands
|
5
|
+
def destroy_plan_command
|
6
|
+
%W[
|
7
|
+
terraform plan
|
8
|
+
-var "aws_access_key=#{@aws_access_key}"
|
9
|
+
-var "aws_secret_key=#{@aws_secret_key}"
|
10
|
+
-var "aws_key_pair=#{@aws_key_pair}"
|
11
|
+
-refresh=true
|
12
|
+
-destroy
|
13
|
+
-state=#{state_file}
|
14
|
+
-out=#{plan_file}
|
15
|
+
#{terraform_dir}
|
16
|
+
].join(' ')
|
17
|
+
end
|
18
|
+
|
19
|
+
def apply_plan_command
|
20
|
+
%W[
|
21
|
+
terraform apply
|
22
|
+
-state=#{state_file}
|
23
|
+
#{plan_file}
|
24
|
+
].join(' ')
|
25
|
+
end
|
26
|
+
|
27
|
+
def apply_command
|
28
|
+
%W[
|
29
|
+
terraform apply
|
30
|
+
-var "aws_access_key=#{@aws_access_key}"
|
31
|
+
-var "aws_secret_key=#{@aws_secret_key}"
|
32
|
+
-var "aws_key_pair=#{@aws_key_pair}"
|
33
|
+
-refresh=true
|
34
|
+
-state=#{state_file}
|
35
|
+
#{terraform_dir}
|
36
|
+
].join(' ')
|
37
|
+
end
|
38
|
+
|
39
|
+
def refresh_command
|
40
|
+
%W[
|
41
|
+
terraform refresh
|
42
|
+
-var "aws_access_key=#{@aws_access_key}"
|
43
|
+
-var "aws_secret_key=#{@aws_secret_key}"
|
44
|
+
-var "aws_key_pair=#{@aws_key_pair}"
|
45
|
+
-state=#{state_file}
|
46
|
+
#{terraform_dir}
|
47
|
+
].join(' ')
|
48
|
+
end
|
49
|
+
|
50
|
+
def plan_command
|
51
|
+
%W[
|
52
|
+
terraform plan
|
53
|
+
-var "aws_access_key=#{@aws_access_key}"
|
54
|
+
-var "aws_secret_key=#{@aws_secret_key}"
|
55
|
+
-var "aws_key_pair=#{@aws_key_pair}"
|
56
|
+
-refresh=true
|
57
|
+
-state=#{state_file}
|
58
|
+
#{terraform_dir}
|
59
|
+
].join(' ')
|
60
|
+
end
|
61
|
+
|
62
|
+
def show_command
|
63
|
+
"terraform show #{state_file}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: genesis_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler Cross
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
description: A terraform wrapper for Bandwidth Incubator
|
42
|
+
email:
|
43
|
+
- tcross@bandwidth.com
|
44
|
+
executables:
|
45
|
+
- genesis
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.md
|
51
|
+
- Thorfile
|
52
|
+
- bin/genesis
|
53
|
+
- genesis.gemspec
|
54
|
+
- lib/genesis.rb
|
55
|
+
- lib/genesis/cli.rb
|
56
|
+
- lib/genesis/commands.rb
|
57
|
+
- lib/genesis/version.rb
|
58
|
+
homepage: https://github.com/bandwidthcom/genesis
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.2.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: A terraform wrapper for Bandwidth Incubator
|
82
|
+
test_files: []
|