terragov 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: efde38002a354278423dd04e272889773b1f12dc
4
+ data.tar.gz: 0e6ef6a6f2467e1e5068099d0a8834fcea7242ae
5
+ SHA512:
6
+ metadata.gz: a6606cfa8752caeb244ff7331f51df36ace492410b66eac6180f5786aa736fc016c831225ce80e34f46c27c49d0552f54689a91d68720f772c0fb573eba2094d
7
+ data.tar.gz: 7210b3b4da942245aa24a67a5be44171813cd751000d195e5c4a2499f92e264c85a6b977761b26a1c5263afe797184999857aa14a312581fb5a99eef4c740b9c
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
6
+ os:
7
+ - osx
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at surminus@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in terragov.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Laura Martin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Terragov
2
+
3
+ ![Cockney deployments](https://github.com/surminus/terragov/blob/master/bricktop.jpg "Cockney deployments")
4
+
5
+ GOV.UK use [Terraform](https://terraform.io) to deploy infrastructure. Originally a lightweight bash script was built to support our opinionated Terraform project structure, but it quickly added further functionality and I decided it would be nicer to use a tool written in a more complete language.
6
+
7
+ ## Installation
8
+
9
+ `gem install terragov`
10
+
11
+ ## Project structure
12
+
13
+ This tool is only meant to be used specifically against the project structure [defined here](https://github.com/alphagov/govuk-aws/blob/cd28b00f6e1efb77e98c59ee8f92813e8f3278d1/doc/architecture/decisions/0010-terraform-directory-structure.md).
14
+
15
+ ## Usage
16
+
17
+ `terragov [CMD] [OPTIONS]`
18
+
19
+ Run `--help` for details.
20
+
21
+ There are several arguments to pass when running `apply`, `plan` or `destroy`:
22
+
23
+ Argument | Description
24
+ --- | ---
25
+ `stack` | Name of the stack you're deploying to
26
+ `environment` | Which environment to deploy to
27
+ `repo_dir` | The root of the repo containing terraform code
28
+ `data_dir` | The directory containing data
29
+ `project` | Name of the project you're deploying
30
+
31
+ ## Configuration
32
+
33
+ There are three ways to pass arguments, detailed below.
34
+
35
+ ### CLI options
36
+
37
+ Use command line flags to pass the relevant argument. This has **highest** precedence.
38
+
39
+ ### Environment variables
40
+
41
+ Every command has an environment variable which can also be set. This has second **highest** precedence. The value is the name, in upper case, and prefixed with `TERRAGOV`. For example, to set `environment`:
42
+
43
+ `export TERRAGOV_ENVIRONMENT=integration`
44
+
45
+ ### Configuration file
46
+
47
+ Specify a configuration file with the `-c` or `--config-file` flags, or use `TERRAGOV_CONFIG_FILE` to set the location of the file.
48
+
49
+ If environment variables or CLI flags are set, they will be overridden.
50
+
51
+ The contents should be YAML, and look like the following:
52
+
53
+ ```
54
+ ---
55
+ environment: 'integration'
56
+ stack: 'blue'
57
+ repo_dir: '~/govuk/govuk-aws'
58
+ data_dir: '~/govuk/govuk-aws-data/data'
59
+ ```
60
+
61
+ ## Development
62
+
63
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+
65
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/surminus/terragov. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
70
+
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
75
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "terragov"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/terragov ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'terragov/cli'
3
+
4
+ Terragov::Cli.new.run
data/bricktop.jpg ADDED
Binary file
data/example.cfg ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ environment: 'integration'
3
+ stack: 'blue'
4
+ repo_dir: '~/govuk/govuk-aws'
5
+ data_dir: '~/govuk/govuk-aws-data/data'
data/lib/terragov.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "terragov/version"
2
+ require "terragov/buildpaths"
3
+ require "terragov/cli"
4
+ require "terragov/terraform"
5
+
6
+ module Terragov
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,115 @@
1
+ require_relative 'cli'
2
+
3
+ module Terragov
4
+ class BuildPaths
5
+
6
+ def base(options={})
7
+
8
+ environment = options['environment']
9
+ data_dir = options['data_dir']
10
+ repo_dir = options['repo_dir']
11
+ stack = options['stack']
12
+ project = options['project']
13
+ extra = options['extra']
14
+
15
+ # Construct variables
16
+ terraform_dir = File.join(repo_dir, "terraform")
17
+ project_dir = File.join(terraform_dir, "projects/#{project}")
18
+ backend_file = File.join(project_dir, "#{environment}.#{stack}.backend")
19
+ common_data_dir = File.join(data_dir, "common/#{environment}")
20
+ common_data = File.join(common_data_dir, "common.tfvars")
21
+ stack_common_data = File.join(common_data_dir, "#{stack}.tfvars")
22
+ project_data_dir = File.join(data_dir, "#{project}/#{environment}")
23
+ common_project_data = File.join(project_data_dir, "common.tfvars")
24
+ secret_common_project_data = File.join(project_data_dir, "common.secret.tfvars")
25
+ stack_project_data = File.join(project_data_dir, "#{stack}.tfvars")
26
+ secret_project_data = File.join(project_data_dir, "#{stack}.secret.tfvars")
27
+
28
+ # Return hash to enable testing
29
+ data_paths = {
30
+ :terraform_dir => terraform_dir,
31
+ :project_dir => project_dir,
32
+ :backend_file => backend_file,
33
+ :common_data_dir => common_data_dir,
34
+ :common_data => common_data,
35
+ :stack_common_data => stack_common_data,
36
+ :project_data_dir => project_data_dir,
37
+ :common_project_data => common_project_data,
38
+ :secret_common_project_data => secret_common_project_data,
39
+ :stack_project_data => stack_project_data,
40
+ :secret_project_data => secret_project_data,
41
+ }
42
+ end
43
+
44
+ def data_validation(path, required = false)
45
+ if required
46
+ if File.exist?(path)
47
+ return true
48
+ else
49
+ abort("Invalid directory or file: #{path}")
50
+ end
51
+ else
52
+ if File.exist?(path)
53
+ return true
54
+ else
55
+ return false
56
+ end
57
+ end
58
+ end
59
+
60
+ def data_paths(options={})
61
+ # The path order is important for passing the var files in the correct
62
+ # order to Terraform as that creates the hierarchy for overrides
63
+ base = self.base(options)
64
+ paths = [
65
+ base[:common_data],
66
+ base[:stack_common_data],
67
+ base[:common_project_data],
68
+ base[:secret_common_project_data],
69
+ base[:stack_project_data],
70
+ base[:secret_project_data],
71
+ ]
72
+ end
73
+
74
+ def check_var_files(paths = [])
75
+ $path_array = []
76
+ paths.each do |path|
77
+ $path_array << data_validation(path)
78
+ end
79
+
80
+ unless $path_array.include? true
81
+ puts "Files checked: "
82
+ paths.each do |path|
83
+ puts path
84
+ end
85
+ return false
86
+ else
87
+ return true
88
+ end
89
+ end
90
+
91
+ def build_command(options={})
92
+ paths = self.base(options)
93
+ abort("Cannot find main repository") unless data_validation(paths[:terraform_dir], true)
94
+ var_paths = data_paths(options)
95
+ abort("Can't find any var files") unless check_var_files(var_paths)
96
+
97
+ $full_vars = []
98
+ data_paths(options).each do |path|
99
+ if data_validation(path)
100
+ # TODO: write sops class
101
+ if path == paths[:secret_project_data] || path == paths[:secret_common_project_data]
102
+ $full_vars << "-var-file <(sops -d #{path})"
103
+ else
104
+ $full_vars << "-var-file #{path}"
105
+ end
106
+ end
107
+ end
108
+ # If defining additional Terraform commands, they need to be passed in as one string,
109
+ # with any hyphens escaped twice so it does not conflict with commander CLI options
110
+ extra = options["extra"].to_s
111
+ $full_vars << extra.gsub('\\', '')
112
+ return $full_vars.join(" ")
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,32 @@
1
+ require 'find'
2
+ require 'highline'
3
+
4
+ module Terragov
5
+ class Cleaner
6
+ def delete(path, pattern, force=false)
7
+ cli = HighLine.new
8
+
9
+ files = Find.find(path).grep(pattern)
10
+
11
+ if files.empty?
12
+ puts "No files found matching #{pattern} in #{path}"
13
+ exit
14
+ end
15
+
16
+ puts "Files matching #{pattern} found:"
17
+
18
+ files.each do |file|
19
+ puts File.expand_path(file)
20
+ end
21
+
22
+ unless force
23
+ exit unless HighLine.agree('Do you wish to delete?')
24
+ end
25
+
26
+ files.each do |file|
27
+ File.delete(File.expand_path(file))
28
+ end
29
+ puts "Done"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,232 @@
1
+ require 'commander'
2
+ require 'yaml'
3
+ require_relative 'buildpaths'
4
+ require_relative 'terraform'
5
+ require_relative 'cleaner'
6
+
7
+ module Terragov
8
+ class Cli
9
+ include Commander::Methods
10
+
11
+ def initialize
12
+ program :name, 'terragov'
13
+ program :version, Terragov::VERSION
14
+ program :description, 'Wrapper for GOV.UK Terraform deployments.'
15
+
16
+ global_option('-c', "--config-file FILE", 'Specify a config file. Has less precedence than environment variables, which in turn have left precedence than CLI options') do |config_file|
17
+ $config_file = config_file
18
+ end
19
+
20
+ global_option('-d', "--data-dir DIRECTORY", 'Location of the data directory') do |data_dir|
21
+ $data_dir = data_dir
22
+ end
23
+
24
+ global_option( '-e', '--env STRING', String, 'Select environment') do |env|
25
+ $environment = env
26
+ end
27
+
28
+ global_option( '-p', '--project STRING', String, 'Name of the project') do |project|
29
+ $project = project
30
+ end
31
+
32
+ global_option( '-r', '--repo-dir DIRECTORY', String, 'Location of the main terraform repository') do |repo_dir|
33
+ $repo_dir = repo_dir
34
+ end
35
+
36
+ global_option( '-s', '--stack STRING', String, 'Name of the stack') do |stack|
37
+ $stack = stack
38
+ end
39
+
40
+ global_option('--extra STRING', String, 'Any additional arguments to pass in the following format: --extra \\\\-target resource.foo.') do |extra|
41
+ $extra = extra
42
+ end
43
+
44
+ global_option('--verbose', String, 'Verbose mode') do |verbose|
45
+ $verbose = verbose
46
+ end
47
+
48
+ global_option('--dry-run', String, 'Verbose mode', 'Output the commands to run, but do not run them') do |dryrun|
49
+ $dryrun = dryrun
50
+ end
51
+
52
+ end
53
+
54
+ def load_config_file
55
+ if $config_file || ENV['TERRAGOV_CONFIG_FILE']
56
+ file = $config_file || ENV['TERRAGOV_CONFIG_FILE']
57
+ $values = YAML.load_file(File.expand_path(file))
58
+ end
59
+ return $values
60
+ end
61
+
62
+ def data_dir
63
+ error_message = "Must provided the data directory. See --help for details"
64
+ if $data_dir
65
+ return File.expand_path($data_dir)
66
+ elsif ENV['TERRAGOV_DATA_DIR']
67
+ return File.expand_path(ENV['TERRAGOV_DATA_DIR'])
68
+ elsif load_config_file['data_dir']
69
+ return File.expand_path(load_config_file['data_dir'])
70
+ else
71
+ abort(error_message)
72
+ end
73
+ end
74
+
75
+ def environment
76
+ error_message = "Must set AWS environment. Use --help for details"
77
+ if $environment
78
+ return $environment
79
+ elsif ENV['TERRAGOV_ENVIRONMENT']
80
+ return ENV['TERRAGOV_ENVIRONMENT']
81
+ elsif load_config_file['environment']
82
+ return load_config_file['environment']
83
+ else
84
+ abort(error_message)
85
+ end
86
+ end
87
+
88
+ def project
89
+ error_message = "Must set AWS project. Use --help for details"
90
+
91
+ if $project
92
+ return $project
93
+ elsif ENV['TERRAGOV_PROJECT']
94
+ return ENV['TERRAGOV_PROJECT']
95
+ elsif load_config_file['project']
96
+ return load_config_file['project']
97
+ else
98
+ abort(error_message)
99
+ end
100
+ end
101
+
102
+ def repo_dir
103
+
104
+ if $repo_dir
105
+ return File.expand_path($repo_dir)
106
+ elsif ENV['TERRAGOV_REPO_DIR']
107
+ return File.expand_path(ENV['TERRAGOV_REPO_DIR'])
108
+ elsif load_config_file['repo_dir']
109
+ return File.expand_path(load_config_file['repo_dir'])
110
+ else
111
+ return File.expand_path('.')
112
+ end
113
+ end
114
+
115
+ def stack
116
+ error_message = "Must set AWS stackname. Use --help for details"
117
+
118
+ if $stack
119
+ return $stack
120
+ elsif ENV['TERRAGOV_STACK']
121
+ return ENV['TERRAGOV_STACK']
122
+ elsif load_config_file['stack']
123
+ return load_config_file['stack']
124
+ else
125
+ abort(error_message)
126
+ end
127
+ end
128
+
129
+ def extra
130
+ return $extra if $extra
131
+ end
132
+
133
+ def cmd_options
134
+ cmd_options_hash = {
135
+ "environment" => environment,
136
+ "data_dir" => data_dir,
137
+ "project" => project,
138
+ "stack" => stack,
139
+ "repo_dir" => repo_dir,
140
+ "extra" => extra,
141
+ }
142
+ return cmd_options_hash
143
+ end
144
+
145
+ def run_terraform_cmd(cmd, opt = nil)
146
+ paths = Terragov::BuildPaths.new.base(cmd_options)
147
+ varfiles = Terragov::BuildPaths.new.build_command(cmd_options)
148
+ backend = paths[:backend_file]
149
+ project_dir = paths[:project_dir]
150
+ if opt
151
+ cmd = "#{cmd} #{opt}"
152
+ end
153
+ Terragov::Terraform.new.execute(cmd, varfiles, backend, project_dir)
154
+ end
155
+
156
+ def run
157
+ command :plan do |c|
158
+ c.syntax = 'terragov plan'
159
+ c.description = 'Runs a plan of your code'
160
+ c.action do |args, options|
161
+ if options.verbose
162
+ ENV['TERRAGOV_VERBOSE'] = "true"
163
+ puts "Planning..."
164
+ puts cmd_options.to_yaml
165
+ end
166
+
167
+ if options.dry_run
168
+ ENV['TERRAGOV_DRYRUN'] = "true"
169
+ end
170
+
171
+ run_terraform_cmd(c.name)
172
+ end
173
+ end
174
+
175
+ command :apply do |c|
176
+ c.syntax = 'terragov apply'
177
+ c.description = 'Apply your code'
178
+ c.action do |args, options|
179
+ if options.verbose
180
+ ENV['TERRAGOV_VERBOSE'] = "true"
181
+ puts "Applying..."
182
+ puts cmd_options.to_yaml
183
+ end
184
+
185
+ if options.dry_run
186
+ ENV['TERRAGOV_DRYRUN'] = "true"
187
+ end
188
+
189
+ run_terraform_cmd(c.name)
190
+ end
191
+ end
192
+
193
+ command :destroy do |c|
194
+ c.syntax = 'terragov destroy'
195
+ c.description = 'Destroy your selected project'
196
+ c.option '--force', 'Force destroy'
197
+ c.action do |args, options|
198
+ if options.verbose
199
+ ENV['TERRAGOV_VERBOSE'] = "true"
200
+ puts "Destroying..."
201
+ puts cmd_options.to_yaml
202
+ end
203
+
204
+ if options.dry_run
205
+ ENV['TERRAGOV_DRYRUN'] = "true"
206
+ end
207
+
208
+ if options.force
209
+ run_terraform_cmd("#{c.name} -force")
210
+ else
211
+ run_terraform_cmd(c.name)
212
+ end
213
+ end
214
+ end
215
+
216
+ command :clean do |c|
217
+ c.syntax = 'terragov clean'
218
+ c.description = 'Clean your directory of any files terraform may have left lying around'
219
+ c.option '--force', 'Force removal of files'
220
+ c.action do |args, options|
221
+ if options.verbose
222
+ puts "Selecting directory #{repo_dir}"
223
+ end
224
+
225
+ Terragov::Cleaner.new.delete(repo_dir, /terraform\.tfstate\.backup/, options.force)
226
+ end
227
+ end
228
+
229
+ run!
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,46 @@
1
+ module Terragov
2
+ class Terraform
3
+
4
+ def package_check
5
+ unless system("which terraform >/dev/null")
6
+ abort("Must install terraform")
7
+ end
8
+
9
+ unless system("which sops >/dev/null")
10
+ abort("Must install sops")
11
+ end
12
+ end
13
+
14
+ def execute(command, vars, backend, directory)
15
+ package_check
16
+
17
+ if command == 'init'
18
+ puts "Running 'init' is not required as it is applied for each command"
19
+ exit 1
20
+ end
21
+
22
+ Dir.chdir directory
23
+ init(backend)
24
+
25
+ full_command = "bash -c 'terraform #{command} #{vars}'"
26
+
27
+ if ENV['TERRAGOV_DRYRUN']
28
+ puts full_command
29
+ else
30
+ puts "#{command} command: #{full_command}" if ENV['TERRAGOV_VERBOSE']
31
+ abort("There was an issue running the command") unless system(full_command)
32
+ end
33
+ end
34
+
35
+ def init(backend_file)
36
+ init_cmd = "terraform init -backend-config #{backend_file}"
37
+ if ENV['TERRAGOV_DRYRUN']
38
+ puts init_cmd
39
+ else
40
+ puts "init command: #{init_cmd}" if ENV['TERRAGOV_VERBOSE']
41
+ abort("Issue running: terraform init -backend-config #{backend_file}") unless system(init_cmd)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Terragov
2
+ VERSION = "0.1.0"
3
+ end
data/terragov.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'terragov/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "terragov"
8
+ spec.version = Terragov::VERSION
9
+ spec.authors = ["Laura Martin"]
10
+ spec.email = ["surminus@gmail.com"]
11
+
12
+ spec.summary = "Wrapper for GOV.UK Terraform deployments."
13
+ spec.description = "GOV.UK deploy infrastructure using Terraform. This is a wrapper to help deployments."
14
+ spec.homepage = "https://github.com/surminus/terragov"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.executables = ['terragov']
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "commander"
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "pry"
29
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: terragov
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Laura Martin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commander
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: '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
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: GOV.UK deploy infrastructure using Terraform. This is a wrapper to help
84
+ deployments.
85
+ email:
86
+ - surminus@gmail.com
87
+ executables:
88
+ - terragov
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - bin/terragov
103
+ - bricktop.jpg
104
+ - example.cfg
105
+ - lib/terragov.rb
106
+ - lib/terragov/buildpaths.rb
107
+ - lib/terragov/cleaner.rb
108
+ - lib/terragov/cli.rb
109
+ - lib/terragov/terraform.rb
110
+ - lib/terragov/version.rb
111
+ - terragov.gemspec
112
+ homepage: https://github.com/surminus/terragov
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.5.1
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Wrapper for GOV.UK Terraform deployments.
136
+ test_files: []