terraform-exporter 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +14 -0
- data/.gitignore +18 -2
- data/.rspec +4 -0
- data/.travis.yml +6 -0
- data/MIT-LICENCE +21 -0
- data/Rakefile +4 -2
- data/bin/terraformer +9 -4
- data/lib/terraformer/cli.rb +2 -0
- data/lib/terraformer/credentials/aws.rb +20 -4
- data/lib/terraformer/credentials/datadog.rb +20 -4
- data/lib/terraformer/resource/cloud_watch_alarm.rb +9 -5
- data/lib/terraformer/resource/datadog_monitor.rb +1 -1
- data/lib/terraformer/terraform.rb +3 -5
- data/lib/terraformer/user_input.rb +4 -6
- data/lib/terraformer/version.rb +1 -1
- data/terraformer.gemspec +2 -2
- metadata +14 -11
- data/Gemfile.lock +0 -127
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 268df7a7c3734ec6b3262aaad17fd35992ab3da5
|
4
|
+
data.tar.gz: ff73e11a723b3572828093a152b759d7e6e2c23e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c62a4264e70ea0b3bf45c930e9f913be5ee9372355233995d5f511d4cd232881eb17b481a298a12fc28256fa860894df2a1b836362243fdd9353a4540ac7736f
|
7
|
+
data.tar.gz: d99388881840946c339f82633821155571a4bb1b291ce6294d87f943a1da94818d788990884c3554b6a8d16748798ec3c7141ff63300db09c359a4cd97d911cb
|
data/.codeclimate.yml
ADDED
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/MIT-LICENCE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011- Intercom, Inc. (https://www.intercom.io)
|
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/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
3
|
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
4
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
5
|
+
task.rspec_opts = %w(--format progress --order random --color)
|
6
|
+
end
|
5
7
|
|
6
|
-
task :
|
8
|
+
task default: :spec
|
data/bin/terraformer
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require "terraformer"
|
2
3
|
|
3
|
-
require "terraforming"
|
4
4
|
begin
|
5
5
|
Terraformer::CLI.start(ARGV)
|
6
|
-
rescue
|
7
|
-
|
6
|
+
rescue Exception => exception
|
7
|
+
case exception
|
8
|
+
when Terraformer::UserInputError
|
8
9
|
exit 0
|
10
|
+
else
|
11
|
+
message = "[ERROR] #{exception.class.to_s}"
|
12
|
+
message += " => #{exception.message}" unless exception.message.strip.empty?
|
13
|
+
puts message
|
14
|
+
exit 1
|
9
15
|
end
|
10
|
-
exit 1
|
11
16
|
end
|
data/lib/terraformer/cli.rb
CHANGED
@@ -1,15 +1,31 @@
|
|
1
1
|
module Terraformer
|
2
2
|
module Credentials
|
3
|
+
class AwsMissingCredentals < RuntimeError
|
4
|
+
attr_reader :key
|
5
|
+
|
6
|
+
def initialize(key)
|
7
|
+
@key = key
|
8
|
+
|
9
|
+
super(message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def message
|
13
|
+
"'#{key}' not passed. set it via CLI --#{key} or #{key.upcase} enviroment variable."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
3
17
|
class Aws
|
18
|
+
KEYS = %w(aws_region aws_access_key_id aws_secret_access_key).freeze
|
19
|
+
|
4
20
|
def self.get_from_options(options)
|
5
|
-
credentials
|
6
|
-
%w(aws_region aws_access_key_id aws_secret_access_key).each do |key|
|
21
|
+
KEYS.inject({}) do |credentials, key|
|
7
22
|
aws_key = key.sub("aws_", "").to_sym
|
8
23
|
credentials[aws_key] = options[key.to_sym].nil? ? options[key] : options[key.to_sym]
|
9
24
|
credentials[aws_key] = ENV[key.upcase] if credentials[aws_key].nil?
|
10
|
-
|
25
|
+
raise AwsMissingCredentals.new(key) if credentials[aws_key].nil?
|
11
26
|
|
12
|
-
|
27
|
+
credentials
|
28
|
+
end
|
13
29
|
end
|
14
30
|
end
|
15
31
|
end
|
@@ -1,15 +1,31 @@
|
|
1
1
|
module Terraformer
|
2
2
|
module Credentials
|
3
|
+
class DatadogMissingCredentals < RuntimeError
|
4
|
+
attr_reader :key
|
5
|
+
|
6
|
+
def initialize(key)
|
7
|
+
@key = key
|
8
|
+
|
9
|
+
super(message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def message
|
13
|
+
"'#{key}' not being passed. set it via CLI --#{key} or #{key.upcase} enviroment variable."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
3
17
|
class Datadog
|
18
|
+
KEYS = %w(datadog_api_key datadog_app_key).freeze
|
19
|
+
|
4
20
|
def self.get_from_options(options)
|
5
|
-
credentials
|
6
|
-
%w(datadog_api_key datadog_app_key).each do |key|
|
21
|
+
KEYS.inject({}) do |credentials, key|
|
7
22
|
datadog_key = key.sub("datadog_", "").to_sym
|
8
23
|
credentials[datadog_key] = options[key.to_sym].nil? ? options[key] : options[key.to_sym]
|
9
24
|
credentials[datadog_key] = ENV[key.upcase] if credentials[datadog_key].nil?
|
10
|
-
|
25
|
+
raise DatadogMissingCredentals.new(key) if credentials[datadog_key].nil?
|
11
26
|
|
12
|
-
|
27
|
+
credentials
|
28
|
+
end
|
13
29
|
end
|
14
30
|
end
|
15
31
|
end
|
@@ -56,13 +56,17 @@ module Terraformer
|
|
56
56
|
add_checksummed_attributes(attributes, alarm)
|
57
57
|
end
|
58
58
|
|
59
|
+
private
|
60
|
+
|
59
61
|
def alarms
|
60
62
|
@alarms ||= begin
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
aws_response = @client.describe_alarms.map(&:metric_alarms).flatten
|
64
|
+
aws_response.inject([]) do |alarms, alarm|
|
65
|
+
alarm = alarm.to_h
|
66
|
+
alarm[:normalized_name] = Terraformer::Normalizer.module_name(alarm[:alarm_name])
|
67
|
+
alarm[:dimensions].map! { |d| OpenStruct.new(d) }
|
68
|
+
|
69
|
+
alarms << OpenStruct.new(alarm)
|
66
70
|
end
|
67
71
|
end
|
68
72
|
end
|
@@ -64,7 +64,7 @@ module Terraformer
|
|
64
64
|
|
65
65
|
def check_response(response)
|
66
66
|
unless response[0] == "200"
|
67
|
-
raise "
|
67
|
+
raise "Received bad response form Datadog. code: #{response[0]} response: #{response[1]}"
|
68
68
|
end
|
69
69
|
|
70
70
|
response[1]
|
@@ -30,13 +30,12 @@ module Terraformer
|
|
30
30
|
if File.file?(tfstate_path)
|
31
31
|
tfstate = parse_json_file(tfstate_path)
|
32
32
|
else
|
33
|
-
|
34
|
-
raise TerraformFileNotFound
|
33
|
+
raise TerraformFileNotFound, "File not found while trying to merge state file with: #{tfstate_path}."
|
35
34
|
end
|
36
35
|
else
|
37
36
|
tfstate_path = "terraform.tfstate"
|
38
37
|
if File.file?(tfstate_path)
|
39
|
-
UserInput.ask("File: #{tfstate_path} already exists. Overwrite?", "Y", "n")
|
38
|
+
UserInput.ask("File: #{tfstate_path} already exists and the 'merge' option was not passed. Overwrite?", "Y", "n")
|
40
39
|
end
|
41
40
|
tfstate = tfstate_skeleton
|
42
41
|
end
|
@@ -55,8 +54,7 @@ module Terraformer
|
|
55
54
|
file_content = File.read(file_path)
|
56
55
|
JSON.parse(file_content)
|
57
56
|
rescue JSON::ParserError
|
58
|
-
|
59
|
-
raise TerraformInvalidTfstateFile
|
57
|
+
raise TerraformInvalidTfstateFile, "Unable to parse: #{file_path}."
|
60
58
|
end
|
61
59
|
|
62
60
|
def tfstate_skeleton
|
@@ -9,15 +9,13 @@ module Terraformer
|
|
9
9
|
MAX_ATTEMPTS = 10
|
10
10
|
|
11
11
|
class << self
|
12
|
-
def get_input
|
13
|
-
|
14
|
-
response.chomp
|
12
|
+
def get_input(message, success, failure)
|
13
|
+
Thor::Shell::Basic.new.ask("#{message} [#{success}/#{failure}]")
|
15
14
|
end
|
16
15
|
|
17
16
|
def ask(message, success, failure)
|
18
17
|
(0..MAX_ATTEMPTS).each do |i|
|
19
|
-
|
20
|
-
response = get_input
|
18
|
+
response = get_input(message, success, failure).chomp
|
21
19
|
|
22
20
|
if response.downcase == success.downcase || response == ""
|
23
21
|
return true
|
@@ -26,7 +24,7 @@ module Terraformer
|
|
26
24
|
raise UserInputError
|
27
25
|
end
|
28
26
|
end
|
29
|
-
raise UserInputMaxAttemptsError
|
27
|
+
raise UserInputMaxAttemptsError, "Reached max number of attempts."
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
data/lib/terraformer/version.rb
CHANGED
data/terraformer.gemspec
CHANGED
@@ -23,11 +23,11 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "dogapi", "~> 1.23"
|
24
24
|
spec.add_dependency "oj", "~> 2.17.1"
|
25
25
|
spec.add_dependency "ox", "~> 2.4.0"
|
26
|
-
spec.add_dependency "thor"
|
26
|
+
spec.add_dependency "thor", "~> 0.19.1"
|
27
27
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 1.7"
|
29
29
|
spec.add_development_dependency "coveralls", "~> 0.8.13"
|
30
|
-
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.5"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.2"
|
32
32
|
spec.add_development_dependency "simplecov", "~> 0.11.1"
|
33
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terraform-exporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacopo Scrinzi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: thor
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.19.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.19.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: bundler
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,16 +112,16 @@ dependencies:
|
|
112
112
|
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '10.5'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '10.5'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rspec
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,10 +158,13 @@ executables:
|
|
158
158
|
extensions: []
|
159
159
|
extra_rdoc_files: []
|
160
160
|
files:
|
161
|
+
- ".codeclimate.yml"
|
161
162
|
- ".gitignore"
|
163
|
+
- ".rspec"
|
164
|
+
- ".travis.yml"
|
162
165
|
- Gemfile
|
163
|
-
- Gemfile.lock
|
164
166
|
- Guardfile
|
167
|
+
- MIT-LICENCE
|
165
168
|
- README.md
|
166
169
|
- Rakefile
|
167
170
|
- bin/terraformer
|
data/Gemfile.lock
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
terraform-exporter (0.0.1)
|
5
|
-
aws-sdk (~> 2.5.1)
|
6
|
-
dogapi (~> 1.23)
|
7
|
-
oj (~> 2.17.1)
|
8
|
-
ox (~> 2.4.0)
|
9
|
-
thor
|
10
|
-
|
11
|
-
GEM
|
12
|
-
remote: https://rubygems.org/
|
13
|
-
specs:
|
14
|
-
ast (2.3.0)
|
15
|
-
aws-sdk (2.5.11)
|
16
|
-
aws-sdk-resources (= 2.5.11)
|
17
|
-
aws-sdk-core (2.5.11)
|
18
|
-
jmespath (~> 1.0)
|
19
|
-
aws-sdk-resources (2.5.11)
|
20
|
-
aws-sdk-core (= 2.5.11)
|
21
|
-
coderay (1.1.1)
|
22
|
-
coveralls (0.8.13)
|
23
|
-
json (~> 1.8)
|
24
|
-
simplecov (~> 0.11.0)
|
25
|
-
term-ansicolor (~> 1.3)
|
26
|
-
thor (~> 0.19.1)
|
27
|
-
tins (~> 1.6.0)
|
28
|
-
diff-lcs (1.2.5)
|
29
|
-
docile (1.1.5)
|
30
|
-
dogapi (1.23.0)
|
31
|
-
multi_json
|
32
|
-
ffi (1.9.14)
|
33
|
-
formatador (0.2.5)
|
34
|
-
guard (2.14.0)
|
35
|
-
formatador (>= 0.2.4)
|
36
|
-
listen (>= 2.7, < 4.0)
|
37
|
-
lumberjack (~> 1.0)
|
38
|
-
nenv (~> 0.1)
|
39
|
-
notiffany (~> 0.0)
|
40
|
-
pry (>= 0.9.12)
|
41
|
-
shellany (~> 0.0)
|
42
|
-
thor (>= 0.18.1)
|
43
|
-
guard-compat (1.2.1)
|
44
|
-
guard-rspec (4.7.3)
|
45
|
-
guard (~> 2.1)
|
46
|
-
guard-compat (~> 1.1)
|
47
|
-
rspec (>= 2.99.0, < 4.0)
|
48
|
-
jmespath (1.3.1)
|
49
|
-
json (1.8.3)
|
50
|
-
listen (3.1.5)
|
51
|
-
rb-fsevent (~> 0.9, >= 0.9.4)
|
52
|
-
rb-inotify (~> 0.9, >= 0.9.7)
|
53
|
-
ruby_dep (~> 1.2)
|
54
|
-
lumberjack (1.0.10)
|
55
|
-
method_source (0.8.2)
|
56
|
-
multi_json (1.12.1)
|
57
|
-
nenv (0.3.0)
|
58
|
-
notiffany (0.1.1)
|
59
|
-
nenv (~> 0.1)
|
60
|
-
shellany (~> 0.0)
|
61
|
-
oj (2.17.4)
|
62
|
-
ox (2.4.5)
|
63
|
-
parser (2.3.1.4)
|
64
|
-
ast (~> 2.2)
|
65
|
-
powerpack (0.1.1)
|
66
|
-
pry (0.10.4)
|
67
|
-
coderay (~> 1.1.0)
|
68
|
-
method_source (~> 0.8.1)
|
69
|
-
slop (~> 3.4)
|
70
|
-
rainbow (2.1.0)
|
71
|
-
rake (11.3.0)
|
72
|
-
rb-fsevent (0.9.7)
|
73
|
-
rb-inotify (0.9.7)
|
74
|
-
ffi (>= 0.5.0)
|
75
|
-
rspec (3.5.0)
|
76
|
-
rspec-core (~> 3.5.0)
|
77
|
-
rspec-expectations (~> 3.5.0)
|
78
|
-
rspec-mocks (~> 3.5.0)
|
79
|
-
rspec-core (3.5.3)
|
80
|
-
rspec-support (~> 3.5.0)
|
81
|
-
rspec-expectations (3.5.0)
|
82
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
-
rspec-support (~> 3.5.0)
|
84
|
-
rspec-mocks (3.5.0)
|
85
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
-
rspec-support (~> 3.5.0)
|
87
|
-
rspec-support (3.5.0)
|
88
|
-
rubocop (0.43.0)
|
89
|
-
parser (>= 2.3.1.1, < 3.0)
|
90
|
-
powerpack (~> 0.1)
|
91
|
-
rainbow (>= 1.99.1, < 3.0)
|
92
|
-
ruby-progressbar (~> 1.7)
|
93
|
-
unicode-display_width (~> 1.0, >= 1.0.1)
|
94
|
-
ruby-progressbar (1.8.1)
|
95
|
-
ruby_dep (1.4.0)
|
96
|
-
shellany (0.0.1)
|
97
|
-
simplecov (0.11.2)
|
98
|
-
docile (~> 1.1.0)
|
99
|
-
json (~> 1.8)
|
100
|
-
simplecov-html (~> 0.10.0)
|
101
|
-
simplecov-html (0.10.0)
|
102
|
-
slop (3.6.0)
|
103
|
-
term-ansicolor (1.3.2)
|
104
|
-
tins (~> 1.0)
|
105
|
-
terminal-notifier-guard (1.7.0)
|
106
|
-
thor (0.19.1)
|
107
|
-
tins (1.6.0)
|
108
|
-
unicode-display_width (1.1.1)
|
109
|
-
|
110
|
-
PLATFORMS
|
111
|
-
ruby
|
112
|
-
|
113
|
-
DEPENDENCIES
|
114
|
-
bundler (~> 1.7)
|
115
|
-
coveralls (~> 0.8.13)
|
116
|
-
guard
|
117
|
-
guard-rspec
|
118
|
-
listen (~> 3.1.0)
|
119
|
-
rake
|
120
|
-
rspec (~> 3.2)
|
121
|
-
rubocop
|
122
|
-
simplecov (~> 0.11.1)
|
123
|
-
terminal-notifier-guard
|
124
|
-
terraform-exporter!
|
125
|
-
|
126
|
-
BUNDLED WITH
|
127
|
-
1.13.2
|