TerraformDevKit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +131 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE +13 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/TerraformDevKit.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/wait_for_url +32 -0
- data/lib/TerraformDevKit.rb +9 -0
- data/lib/TerraformDevKit/aws.rb +63 -0
- data/lib/TerraformDevKit/backup_state.rb +18 -0
- data/lib/TerraformDevKit/command.rb +20 -0
- data/lib/TerraformDevKit/config.rb +15 -0
- data/lib/TerraformDevKit/download.rb +17 -0
- data/lib/TerraformDevKit/dynamodb.rb +24 -0
- data/lib/TerraformDevKit/os.rb +29 -0
- data/lib/TerraformDevKit/terraform_installer.rb +47 -0
- data/lib/TerraformDevKit/terragrunt_installer.rb +41 -0
- data/lib/TerraformDevKit/version.rb +3 -0
- data/lib/TerraformDevKit/zip_file_generator.rb +48 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 631ca645a080aebd548ff5f41535be564205eb55
|
4
|
+
data.tar.gz: b7b4c8b3d1cae82a36ecfd5a9c5e2c37df0ce29c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aff2cf1d9f94408c7f6a61d049aaab32d774f36b358f73ee26562f57d04ed86e1216578eee3609dbcc4b6a5e6aea19744675f1f2f3a01de47c889df4903038b5
|
7
|
+
data.tar.gz: 8fae71f01f65ce6ea1c86b024bc5cbbc174a1894f15e4537dd0390595df3273a9cdeb7020020bb5f1a9250e163682233744fffd8bfccd2337588e85eca2d9f00
|
data/.gitignore
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
|
2
|
+
# Created by https://www.gitignore.io/api/ruby,visualstudiocode,rubymine
|
3
|
+
|
4
|
+
### Ruby ###
|
5
|
+
*.gem
|
6
|
+
*.rbc
|
7
|
+
/.config
|
8
|
+
/coverage/
|
9
|
+
/InstalledFiles
|
10
|
+
/pkg/
|
11
|
+
/spec/reports/
|
12
|
+
/spec/examples.txt
|
13
|
+
/test/tmp/
|
14
|
+
/test/version_tmp/
|
15
|
+
/tmp/
|
16
|
+
|
17
|
+
# Used by dotenv library to load environment variables.
|
18
|
+
# .env
|
19
|
+
|
20
|
+
## Specific to RubyMotion:
|
21
|
+
.dat*
|
22
|
+
.repl_history
|
23
|
+
build/
|
24
|
+
*.bridgesupport
|
25
|
+
build-iPhoneOS/
|
26
|
+
build-iPhoneSimulator/
|
27
|
+
|
28
|
+
## Specific to RubyMotion (use of CocoaPods):
|
29
|
+
#
|
30
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
31
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
32
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
33
|
+
#
|
34
|
+
# vendor/Pods/
|
35
|
+
|
36
|
+
## Documentation cache and generated files:
|
37
|
+
/.yardoc/
|
38
|
+
/_yardoc/
|
39
|
+
/doc/
|
40
|
+
/rdoc/
|
41
|
+
|
42
|
+
## Environment normalization:
|
43
|
+
/.bundle/
|
44
|
+
/vendor/bundle
|
45
|
+
/lib/bundler/man/
|
46
|
+
|
47
|
+
# for a library or gem, you might want to ignore these files since the code is
|
48
|
+
# intended to run in multiple environments; otherwise, check them in:
|
49
|
+
# Gemfile.lock
|
50
|
+
# .ruby-version
|
51
|
+
# .ruby-gemset
|
52
|
+
|
53
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
54
|
+
.rvmrc
|
55
|
+
|
56
|
+
### RubyMine ###
|
57
|
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
58
|
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
59
|
+
|
60
|
+
# User-specific stuff:
|
61
|
+
.idea/**/workspace.xml
|
62
|
+
.idea/**/tasks.xml
|
63
|
+
.idea/dictionaries
|
64
|
+
|
65
|
+
# Sensitive or high-churn files:
|
66
|
+
.idea/**/dataSources/
|
67
|
+
.idea/**/dataSources.ids
|
68
|
+
.idea/**/dataSources.xml
|
69
|
+
.idea/**/dataSources.local.xml
|
70
|
+
.idea/**/sqlDataSources.xml
|
71
|
+
.idea/**/dynamic.xml
|
72
|
+
.idea/**/uiDesigner.xml
|
73
|
+
|
74
|
+
# Gradle:
|
75
|
+
.idea/**/gradle.xml
|
76
|
+
.idea/**/libraries
|
77
|
+
|
78
|
+
# CMake
|
79
|
+
cmake-build-debug/
|
80
|
+
|
81
|
+
# Mongo Explorer plugin:
|
82
|
+
.idea/**/mongoSettings.xml
|
83
|
+
|
84
|
+
## File-based project format:
|
85
|
+
*.iws
|
86
|
+
|
87
|
+
## Plugin-specific files:
|
88
|
+
|
89
|
+
# IntelliJ
|
90
|
+
/out/
|
91
|
+
|
92
|
+
# mpeltonen/sbt-idea plugin
|
93
|
+
.idea_modules/
|
94
|
+
|
95
|
+
# JIRA plugin
|
96
|
+
atlassian-ide-plugin.xml
|
97
|
+
|
98
|
+
# Cursive Clojure plugin
|
99
|
+
.idea/replstate.xml
|
100
|
+
|
101
|
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
102
|
+
com_crashlytics_export_strings.xml
|
103
|
+
crashlytics.properties
|
104
|
+
crashlytics-build.properties
|
105
|
+
fabric.properties
|
106
|
+
|
107
|
+
### RubyMine Patch ###
|
108
|
+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
109
|
+
|
110
|
+
.idea/
|
111
|
+
*.iml
|
112
|
+
modules.xml
|
113
|
+
.idea/misc.xml
|
114
|
+
*.ipr
|
115
|
+
|
116
|
+
# Sonarlint plugin
|
117
|
+
.idea/sonarlint
|
118
|
+
|
119
|
+
### VisualStudioCode ###
|
120
|
+
.vscode/*
|
121
|
+
!.vscode/settings.json
|
122
|
+
!.vscode/tasks.json
|
123
|
+
!.vscode/launch.json
|
124
|
+
!.vscode/extensions.json
|
125
|
+
|
126
|
+
# End of https://www.gitignore.io/api/ruby,visualstudiocode,rubymine
|
127
|
+
|
128
|
+
# Custom
|
129
|
+
|
130
|
+
Gemfile.lock
|
131
|
+
.rspec_status
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2017 Cimpress
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# TerraformDevKit
|
2
|
+
|
3
|
+
Set of scripts to ease development and testing with [Terraform](https://www.terraform.io/).
|
4
|
+
|
5
|
+
The script collection incldues support for:
|
6
|
+
|
7
|
+
* Managing AWS credentials
|
8
|
+
* Simple reading and writing to AWS DynamoDB
|
9
|
+
* Polling until an AWS ApiGateway resource becomes ready
|
10
|
+
* Executing commands
|
11
|
+
* Locally installing Terraform and [Terragrunt](https://github.com/gruntwork-io/terragrunt)
|
12
|
+
* Backing up the state from a failed Terraform execution
|
13
|
+
* Multiplatform tools
|
14
|
+
* Simple configuration management
|
15
|
+
|
16
|
+
Most of these scripts exist to provide support to a module development and testing environment for Terraform: [TerraformModules](https://github.com/betabandido/TerraformModules). But, they might be useful for other purposes too.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'TerraformDevKit'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install TerraformDevKit
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
To use the library simply import it as:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'TerraformDevKit'
|
40
|
+
```
|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
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.
|
45
|
+
|
46
|
+
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).
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/betabandido/TerraformDevKit.
|
51
|
+
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
The gem is available as open source under the terms of the [Apache License, Version 2.0](https://opensource.org/licenses/Apache-2.0).
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'TerraformDevKit/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'TerraformDevKit'
|
9
|
+
spec.version = TerraformDevKit::VERSION
|
10
|
+
spec.authors = ['Victor Jimenez']
|
11
|
+
spec.email = ['vjimenez@vistaprint.com']
|
12
|
+
|
13
|
+
spec.summary = 'Set of scripts to ease development and testing with Terraform.'
|
14
|
+
spec.homepage = 'https://github.com/betabandido/TerraformDevKit'
|
15
|
+
spec.license = 'Apache-2.0'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
|
28
|
+
spec.add_runtime_dependency 'aws-sdk', '~> 2.9.37'
|
29
|
+
spec.add_runtime_dependency 'rubyzip', '~> 1.2.1'
|
30
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "TerraformDevKit"
|
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
data/exe/wait_for_url
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'openssl'
|
5
|
+
|
6
|
+
# Interval between retries (in seconds)
|
7
|
+
INTERVAL_LENGTH = 5.0
|
8
|
+
|
9
|
+
# Maximum amount of time to keep retrying (in seconds)
|
10
|
+
MAX_TIME_TO_RETRY = 300.0
|
11
|
+
|
12
|
+
if ARGV.length != 1
|
13
|
+
puts 'USAGE: wait_for_url.rb <url>'
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
url = ARGV[0]
|
18
|
+
retries = (MAX_TIME_TO_RETRY / INTERVAL_LENGTH).ceil
|
19
|
+
|
20
|
+
begin
|
21
|
+
puts "Fetching #{url}"
|
22
|
+
open(url, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE, redirect: false)
|
23
|
+
rescue OpenURI::HTTPError => error
|
24
|
+
response = error.io
|
25
|
+
puts "Response status code: #{response.status[0]}"
|
26
|
+
unless (retries -= 1).zero? || response.status[0] != '500'
|
27
|
+
sleep(INTERVAL_LENGTH)
|
28
|
+
retry
|
29
|
+
end
|
30
|
+
rescue OpenURI::HTTPRedirect => error
|
31
|
+
puts "Redirect to: #{error.uri}"
|
32
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'TerraformDevKit/aws'
|
2
|
+
require 'TerraformDevKit/backup_state'
|
3
|
+
require 'TerraformDevKit/command'
|
4
|
+
require 'TerraformDevKit/config'
|
5
|
+
require 'TerraformDevKit/dynamodb'
|
6
|
+
require 'TerraformDevKit/os'
|
7
|
+
require 'TerraformDevKit/terraform_installer'
|
8
|
+
require 'TerraformDevKit/terragrunt_installer'
|
9
|
+
require 'TerraformDevKit/version'
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
Aws.use_bundled_cert!
|
4
|
+
|
5
|
+
module TerraformDevKit
|
6
|
+
class AwsConfig
|
7
|
+
def initialize(config)
|
8
|
+
unless config.nil?
|
9
|
+
@profile = config.fetch('profile', nil)
|
10
|
+
@region = config.fetch('region', nil)
|
11
|
+
@access_key_id = config.fetch('access_key_id', nil)
|
12
|
+
@secret_access_key = config.fetch('secret_access_key', nil)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def credentials
|
17
|
+
unless profile.nil?
|
18
|
+
credentials = Aws::SharedCredentials.new(profile_name: profile)
|
19
|
+
return credentials if credentials.set?
|
20
|
+
end
|
21
|
+
|
22
|
+
return Aws::Credentials.new(*access_keys) if access_keys_available?
|
23
|
+
|
24
|
+
raise 'Cannot find AWS credentials'
|
25
|
+
end
|
26
|
+
|
27
|
+
def region
|
28
|
+
@region || ENV['AWS_REGION']
|
29
|
+
end
|
30
|
+
|
31
|
+
def profile
|
32
|
+
@profile || ENV['AWS_PROFILE']
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def access_keys
|
38
|
+
return config_access_keys if config_has_access_keys?
|
39
|
+
return environment_access_keys if environment_has_access_keys?
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def access_keys_available?
|
44
|
+
config_has_access_keys? || environment_has_access_keys?
|
45
|
+
end
|
46
|
+
|
47
|
+
def config_has_access_keys?
|
48
|
+
!@access_key_id.nil? && !@secret_access_key.nil?
|
49
|
+
end
|
50
|
+
|
51
|
+
def config_access_keys
|
52
|
+
return @access_key_id, @secret_access_key
|
53
|
+
end
|
54
|
+
|
55
|
+
def environment_has_access_keys?
|
56
|
+
ENV.key?('AWS_ACCESS_KEY_ID') && ENV.key?('AWS_SECRET_ACCESS_KEY')
|
57
|
+
end
|
58
|
+
|
59
|
+
def environment_access_keys
|
60
|
+
return ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require_relative 'zip_file_generator'
|
4
|
+
|
5
|
+
module TerraformDevKit
|
6
|
+
class BackupState
|
7
|
+
def self.backup(prefix)
|
8
|
+
backup_path = ENV['TM_STATE_BACKUP_PATH']
|
9
|
+
return if backup_path.nil?
|
10
|
+
|
11
|
+
filename = "#{prefix}failure_state.zip"
|
12
|
+
ZipFileGenerator.new('.', filename).write
|
13
|
+
|
14
|
+
FileUtils.cp(filename, backup_path)
|
15
|
+
puts "Copied state to #{File.join(backup_path, filename)}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module TerraformDevKit
|
4
|
+
class Command
|
5
|
+
def self.run(cmd, directory = Dir.pwd)
|
6
|
+
output = []
|
7
|
+
|
8
|
+
Open3.popen2e(cmd, chdir: directory) do |_, stdout, thread|
|
9
|
+
while line = stdout.gets
|
10
|
+
output << line
|
11
|
+
puts(line)
|
12
|
+
end
|
13
|
+
|
14
|
+
raise "Error running command #{cmd}" unless thread.value.success?
|
15
|
+
end
|
16
|
+
|
17
|
+
output.join('')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
module TerraformDevKit
|
5
|
+
def self.download_file(url, filename, force_download: false)
|
6
|
+
unless File.exist?(filename) && !force_download
|
7
|
+
dirname = File.dirname(filename)
|
8
|
+
FileUtils.mkdir_p(dirname) unless Dir.exist?(dirname)
|
9
|
+
|
10
|
+
puts "Downloading #{url} to #{filename}..."
|
11
|
+
|
12
|
+
open(filename, 'wb') do |file|
|
13
|
+
file << open(url, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE).read
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
Aws.use_bundled_cert!
|
4
|
+
|
5
|
+
module TerraformDevKit
|
6
|
+
class DynamoDB
|
7
|
+
def initialize(credentials, region)
|
8
|
+
@db_client = Aws::DynamoDB::Resource.new(
|
9
|
+
credentials: credentials,
|
10
|
+
region: region
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_item(table_name, key)
|
15
|
+
table = @db_client.table(table_name)
|
16
|
+
table.get_item(key: key)
|
17
|
+
end
|
18
|
+
|
19
|
+
def put_item(table_name, item)
|
20
|
+
table = @db_client.table(table_name)
|
21
|
+
table.put_item(item: item)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module TerraformDevKit
|
2
|
+
class OS
|
3
|
+
def self.host_os
|
4
|
+
case RUBY_PLATFORM
|
5
|
+
when /linux/
|
6
|
+
'linux'
|
7
|
+
when /darwin/
|
8
|
+
'darwin'
|
9
|
+
when /mingw/
|
10
|
+
'windows'
|
11
|
+
else
|
12
|
+
raise 'Cannot determine OS'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.env_path_separator
|
17
|
+
case host_os
|
18
|
+
when 'linux', 'darwin'
|
19
|
+
':'
|
20
|
+
when 'windows'
|
21
|
+
';'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.join_env_path(path1, path2)
|
26
|
+
"#{path1}#{env_path_separator}#{path2}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
require_relative 'download'
|
4
|
+
require_relative 'os'
|
5
|
+
require_relative 'command'
|
6
|
+
|
7
|
+
module TerraformDevKit
|
8
|
+
class TerraformInstaller
|
9
|
+
LOCAL_FILE_NAME = 'terraform.zip'.freeze
|
10
|
+
|
11
|
+
def self.installed_terraform_version
|
12
|
+
version = Command.run('terraform --version').tr("\r\n", '')
|
13
|
+
match = /Terraform v(\d+\.\d+\.\d+)/.match(version)
|
14
|
+
match[1] unless match.nil?
|
15
|
+
rescue
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.download_terraform(version)
|
20
|
+
TerraformDevKit.download_file(
|
21
|
+
"https://releases.hashicorp.com/terraform/#{version}/terraform_#{version}_#{OS.host_os}_amd64.zip",
|
22
|
+
LOCAL_FILE_NAME,
|
23
|
+
force_download: true
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.unzip_terraform
|
28
|
+
Zip::File.open(LOCAL_FILE_NAME) do |zip_file|
|
29
|
+
zip_file.each do |entry|
|
30
|
+
puts "Extracting #{entry.name}"
|
31
|
+
entry.restore_permissions = true
|
32
|
+
entry.extract { true }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.install_local(version)
|
38
|
+
if installed_terraform_version == version
|
39
|
+
puts 'Terraform already installed'
|
40
|
+
return
|
41
|
+
end
|
42
|
+
|
43
|
+
download_terraform(version)
|
44
|
+
unzip_terraform
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require_relative 'download'
|
4
|
+
require_relative 'os'
|
5
|
+
require_relative 'command'
|
6
|
+
|
7
|
+
module TerraformDevKit
|
8
|
+
class TerragruntInstaller
|
9
|
+
EXTENSION = (OS.host_os == 'windows' ? '.exe' : '').freeze
|
10
|
+
LOCAL_FILE_NAME = "terragrunt#{EXTENSION}".freeze
|
11
|
+
|
12
|
+
def self.installed_terragrunt_version
|
13
|
+
version = Command.run('terragrunt --version').tr("\r\n", '')
|
14
|
+
match = /terragrunt version v(\d+\.\d+\.\d+)/.match(version)
|
15
|
+
match[1] unless match.nil?
|
16
|
+
rescue
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.download_terragrunt(version)
|
21
|
+
TerraformDevKit.download_file(
|
22
|
+
"https://github.com/gruntwork-io/terragrunt/releases/download/v#{version}/terragrunt_#{OS.host_os}_amd64#{EXTENSION}",
|
23
|
+
LOCAL_FILE_NAME,
|
24
|
+
force_download: true
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.install_local(version)
|
29
|
+
if installed_terragrunt_version == version
|
30
|
+
puts 'Terragrunt already installed'
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
download_terragrunt(version)
|
35
|
+
|
36
|
+
unless TerraformDevKit::OS.host_os == 'windows'
|
37
|
+
FileUtils.chmod('u+x', LOCAL_FILE_NAME)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
module TerraformDevKit
|
4
|
+
class ZipFileGenerator
|
5
|
+
def initialize(input_dir, output_file)
|
6
|
+
puts "REAL ONE"
|
7
|
+
@input_dir = input_dir
|
8
|
+
@output_file = output_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def write
|
12
|
+
entries = Dir.entries(@input_dir)
|
13
|
+
entries.delete('.')
|
14
|
+
entries.delete('..')
|
15
|
+
Zip::File.open(@output_file, Zip::File::CREATE) do |zipfile|
|
16
|
+
write_entries(entries, '', zipfile)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def write_entries(entries, path, zipfile)
|
23
|
+
entries.each do |e|
|
24
|
+
zip_file_path = path == '' ? e : File.join(path, e)
|
25
|
+
disk_file_path = File.join(@input_dir, zip_file_path)
|
26
|
+
if File.directory?(disk_file_path)
|
27
|
+
write_directory(disk_file_path, zip_file_path, zipfile)
|
28
|
+
else
|
29
|
+
write_file(disk_file_path, zip_file_path, zipfile)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def write_directory(disk_file_path, zip_file_path, zipfile)
|
35
|
+
zipfile.mkdir(zip_file_path)
|
36
|
+
subdir = Dir.entries(disk_file_path)
|
37
|
+
subdir.delete('.')
|
38
|
+
subdir.delete('..')
|
39
|
+
write_entries(subdir, zip_file_path, zipfile)
|
40
|
+
end
|
41
|
+
|
42
|
+
def write_file(disk_file_path, zip_file_path, zipfile)
|
43
|
+
zipfile.get_output_stream(zip_file_path) do |f|
|
44
|
+
f.puts(File.open(disk_file_path, 'rb').read)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: TerraformDevKit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Jimenez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-14 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.9.37
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.9.37
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubyzip
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.2.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.2.1
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- vjimenez@vistaprint.com
|
86
|
+
executables:
|
87
|
+
- wait_for_url
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- TerraformDevKit.gemspec
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- exe/wait_for_url
|
102
|
+
- lib/TerraformDevKit.rb
|
103
|
+
- lib/TerraformDevKit/aws.rb
|
104
|
+
- lib/TerraformDevKit/backup_state.rb
|
105
|
+
- lib/TerraformDevKit/command.rb
|
106
|
+
- lib/TerraformDevKit/config.rb
|
107
|
+
- lib/TerraformDevKit/download.rb
|
108
|
+
- lib/TerraformDevKit/dynamodb.rb
|
109
|
+
- lib/TerraformDevKit/os.rb
|
110
|
+
- lib/TerraformDevKit/terraform_installer.rb
|
111
|
+
- lib/TerraformDevKit/terragrunt_installer.rb
|
112
|
+
- lib/TerraformDevKit/version.rb
|
113
|
+
- lib/TerraformDevKit/zip_file_generator.rb
|
114
|
+
homepage: https://github.com/betabandido/TerraformDevKit
|
115
|
+
licenses:
|
116
|
+
- Apache-2.0
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.5.1
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Set of scripts to ease development and testing with Terraform.
|
138
|
+
test_files: []
|