rake-terraform 0.0.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +19 -0
- data/.rspec +5 -0
- data/.rubocop.yml +25 -0
- data/.travis.yml +1 -0
- data/README.md +93 -1
- data/Rakefile +22 -3
- data/lib/{rake_terraform.rb → rake-terraform.rb} +1 -0
- data/lib/rake-terraform/apply_task/config.rb +47 -0
- data/lib/rake-terraform/{tasks/applytask.rb → apply_task/task.rb} +21 -33
- data/lib/rake-terraform/applytask.rb +11 -0
- data/lib/rake-terraform/{tasks/basetask.rb → basetask.rb} +2 -1
- data/lib/rake-terraform/default_tasks.rb +5 -2
- data/lib/rake-terraform/dsl.rb +2 -2
- data/lib/rake-terraform/env_process.rb +142 -0
- data/lib/rake-terraform/errors.rb +4 -0
- data/lib/rake-terraform/plan_task/config.rb +61 -0
- data/lib/rake-terraform/plan_task/task.rb +51 -0
- data/lib/rake-terraform/plantask.rb +13 -0
- data/lib/rake-terraform/terraformcmd.rb +56 -0
- data/lib/rake-terraform/version.rb +1 -1
- data/rake-terraform.gemspec +3 -0
- data/spec/fixtures/envprocess_uniq_state_dir_var_invalid.env +3 -0
- data/spec/fixtures/envprocess_uniq_state_dir_var_valid.env +4 -0
- data/spec/fixtures/envprocess_uniq_state_false.env +2 -0
- data/spec/fixtures/envprocess_uniq_state_false_file_valid.env +3 -0
- data/spec/fixtures/envprocess_uniq_state_invalid_state_file_str.env +3 -0
- data/spec/fixtures/envprocess_uniq_state_missing_dir_var.env +4 -0
- data/spec/fixtures/envprocess_uniq_state_true.env +5 -0
- data/spec/fixtures/envprocess_uniq_state_true_both.env +6 -0
- data/spec/fixtures/envprocess_uniq_state_true_file_valid.env +3 -0
- data/spec/fixtures/set_all_variables_nil.env +8 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/unit/applytask_spec.rb +112 -0
- data/spec/unit/basetask_spec.rb +10 -0
- data/spec/unit/envprocess_spec.rb +263 -0
- data/spec/unit/plantask_spec.rb +118 -0
- data/spec/unit/terraformcmd_spec.rb +174 -0
- metadata +90 -7
- data/lib/rake-terraform/tasks/plantask.rb +0 -87
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake-terraform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norm MacLennan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,48 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.29'
|
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.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.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: wannabe_bool
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.3.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.3.0
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: rake
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,19 +146,44 @@ extensions: []
|
|
104
146
|
extra_rdoc_files: []
|
105
147
|
files:
|
106
148
|
- .gitignore
|
149
|
+
- .rspec
|
150
|
+
- .rubocop.yml
|
107
151
|
- .travis.yml
|
108
152
|
- Gemfile
|
109
153
|
- LICENSE.txt
|
110
154
|
- README.md
|
111
155
|
- Rakefile
|
156
|
+
- lib/rake-terraform.rb
|
157
|
+
- lib/rake-terraform/apply_task/config.rb
|
158
|
+
- lib/rake-terraform/apply_task/task.rb
|
159
|
+
- lib/rake-terraform/applytask.rb
|
160
|
+
- lib/rake-terraform/basetask.rb
|
112
161
|
- lib/rake-terraform/default_tasks.rb
|
113
162
|
- lib/rake-terraform/dsl.rb
|
114
|
-
- lib/rake-terraform/
|
115
|
-
- lib/rake-terraform/
|
116
|
-
- lib/rake-terraform/
|
163
|
+
- lib/rake-terraform/env_process.rb
|
164
|
+
- lib/rake-terraform/errors.rb
|
165
|
+
- lib/rake-terraform/plan_task/config.rb
|
166
|
+
- lib/rake-terraform/plan_task/task.rb
|
167
|
+
- lib/rake-terraform/plantask.rb
|
168
|
+
- lib/rake-terraform/terraformcmd.rb
|
117
169
|
- lib/rake-terraform/version.rb
|
118
|
-
- lib/rake_terraform.rb
|
119
170
|
- rake-terraform.gemspec
|
171
|
+
- spec/fixtures/envprocess_uniq_state_dir_var_invalid.env
|
172
|
+
- spec/fixtures/envprocess_uniq_state_dir_var_valid.env
|
173
|
+
- spec/fixtures/envprocess_uniq_state_false.env
|
174
|
+
- spec/fixtures/envprocess_uniq_state_false_file_valid.env
|
175
|
+
- spec/fixtures/envprocess_uniq_state_invalid_state_file_str.env
|
176
|
+
- spec/fixtures/envprocess_uniq_state_missing_dir_var.env
|
177
|
+
- spec/fixtures/envprocess_uniq_state_true.env
|
178
|
+
- spec/fixtures/envprocess_uniq_state_true_both.env
|
179
|
+
- spec/fixtures/envprocess_uniq_state_true_file_valid.env
|
180
|
+
- spec/fixtures/set_all_variables_nil.env
|
181
|
+
- spec/spec_helper.rb
|
182
|
+
- spec/unit/applytask_spec.rb
|
183
|
+
- spec/unit/basetask_spec.rb
|
184
|
+
- spec/unit/envprocess_spec.rb
|
185
|
+
- spec/unit/plantask_spec.rb
|
186
|
+
- spec/unit/terraformcmd_spec.rb
|
120
187
|
homepage: https://github.com/maclennann/rake-terraform
|
121
188
|
licenses:
|
122
189
|
- MIT
|
@@ -141,4 +208,20 @@ rubygems_version: 2.4.5
|
|
141
208
|
signing_key:
|
142
209
|
specification_version: 4
|
143
210
|
summary: Rake tasks for use with Terraform.
|
144
|
-
test_files:
|
211
|
+
test_files:
|
212
|
+
- spec/fixtures/envprocess_uniq_state_dir_var_invalid.env
|
213
|
+
- spec/fixtures/envprocess_uniq_state_dir_var_valid.env
|
214
|
+
- spec/fixtures/envprocess_uniq_state_false.env
|
215
|
+
- spec/fixtures/envprocess_uniq_state_false_file_valid.env
|
216
|
+
- spec/fixtures/envprocess_uniq_state_invalid_state_file_str.env
|
217
|
+
- spec/fixtures/envprocess_uniq_state_missing_dir_var.env
|
218
|
+
- spec/fixtures/envprocess_uniq_state_true.env
|
219
|
+
- spec/fixtures/envprocess_uniq_state_true_both.env
|
220
|
+
- spec/fixtures/envprocess_uniq_state_true_file_valid.env
|
221
|
+
- spec/fixtures/set_all_variables_nil.env
|
222
|
+
- spec/spec_helper.rb
|
223
|
+
- spec/unit/applytask_spec.rb
|
224
|
+
- spec/unit/basetask_spec.rb
|
225
|
+
- spec/unit/envprocess_spec.rb
|
226
|
+
- spec/unit/plantask_spec.rb
|
227
|
+
- spec/unit/terraformcmd_spec.rb
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'rake/task'
|
2
|
-
require 'rake-terraform/tasks/basetask'
|
3
|
-
require 'map'
|
4
|
-
|
5
|
-
# Custom rake task to perform `terraform plan`
|
6
|
-
module RakeTerraform
|
7
|
-
module PlanTask
|
8
|
-
# Configuration data for terraform plan task
|
9
|
-
class Config
|
10
|
-
attr_accessor :input_dir
|
11
|
-
attr_accessor :output_file
|
12
|
-
attr_accessor :credentials
|
13
|
-
attr_accessor :aws_project
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@input_dir = File.expand_path 'terraform'
|
17
|
-
@output_file = File.expand_path(default_output)
|
18
|
-
@credentials = File.expand_path(default_credentials)
|
19
|
-
@aws_project = 'default'
|
20
|
-
end
|
21
|
-
|
22
|
-
def opts
|
23
|
-
Map.new(input_dir: @input_dir,
|
24
|
-
output_file: @output_file,
|
25
|
-
credentials: @credentials,
|
26
|
-
aws_project: @aws_project)
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def default_output
|
32
|
-
File.join('output', 'terraform', 'plan.tf')
|
33
|
-
end
|
34
|
-
|
35
|
-
def default_credentials
|
36
|
-
File.join('~', '.aws', 'credentials')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# Custom rake task to run `terraform plan`
|
41
|
-
class Task < BaseTask
|
42
|
-
attr_accessor :creds_file
|
43
|
-
|
44
|
-
def initialize(opts)
|
45
|
-
@creds_file = opts.get(:credentials)
|
46
|
-
@opts = opts
|
47
|
-
end
|
48
|
-
|
49
|
-
def execute
|
50
|
-
validate_terraform_installed
|
51
|
-
ensure_output_directory
|
52
|
-
|
53
|
-
creds = get_aws_credentials(@creds_file, @opts.get(:aws_project))
|
54
|
-
|
55
|
-
Dir.chdir(@opts.get(:input_dir)) do
|
56
|
-
puts '=> Fetching modules...'
|
57
|
-
system('terraform get')
|
58
|
-
|
59
|
-
command = construct_command creds
|
60
|
-
puts "=> Generating plan for #{@opts.get(:input_dir)}..."
|
61
|
-
system(command)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def construct_command(creds)
|
68
|
-
access_key = creds[:accesskey]
|
69
|
-
secret_key = creds[:secretkey]
|
70
|
-
|
71
|
-
command = 'terraform plan '
|
72
|
-
command << "-var access_key=\"#{access_key}\" "
|
73
|
-
command << "-var secret_key=\"#{secret_key}\" "
|
74
|
-
command << '-module-depth 2 '
|
75
|
-
command << "-out #{@opts.get(:output_file)}" if @opts.get(:output_file)
|
76
|
-
|
77
|
-
command
|
78
|
-
end
|
79
|
-
|
80
|
-
def ensure_output_directory
|
81
|
-
require 'fileutils'
|
82
|
-
dir = File.dirname @opts.get(:output_file)
|
83
|
-
FileUtils.mkdir_p dir unless File.exist? dir
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|