TerraformDevKit 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -9
- data/lib/TerraformDevKit/terraform_config_manager.rb +2 -4
- data/lib/TerraformDevKit/terraform_installer.rb +11 -3
- data/lib/TerraformDevKit/version.rb +1 -1
- data/tasks/devkit.rake +16 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a94f0642cf970c5994db6fc663a2f2add47810e4
|
4
|
+
data.tar.gz: 8fa17cf1bf78f83abe26094616904692db12fdf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daf674ba9d45403f922f157eccb704ac0581470c801c9d8c86d90b1c3dab5a3899993706931b42712b9994fe3b104d232b8ddb17d816184a887ff5f844ff3285
|
7
|
+
data.tar.gz: 9171fd82c7de355a543053b1fd95bbd7f868ec2cb39547b4dec5faeb6510a820ec929e3931fec624683de7f8f924b694e767e44f20bb8c837708b0708bdbf64a
|
data/README.md
CHANGED
@@ -89,6 +89,27 @@ task :custom_test, [:env] do |_, args|
|
|
89
89
|
end
|
90
90
|
```
|
91
91
|
|
92
|
+
### Tasks and Hooks
|
93
|
+
|
94
|
+
TerraformDevKit provides a set of generic tasks to perform:
|
95
|
+
|
96
|
+
* `prepare`: prepares the environment
|
97
|
+
* `plan`: shows the plan to create the infrastructure
|
98
|
+
* `apply`: creates the infrastructure
|
99
|
+
* `destroy`: destroys the infrastructure
|
100
|
+
* `clean`: cleans the environment (after destroying the infrastructure)
|
101
|
+
* `test`: tests a local environment
|
102
|
+
* `preflight`: creates a temporary infrastructure and runs the test task
|
103
|
+
|
104
|
+
Additionally, TerraformDevKit allows users to define a set of hooks that will be called during the different steps required to complete the previous list of tasks. The following hooks are available:
|
105
|
+
|
106
|
+
* `pre_apply`: invoked before `apply` task runs
|
107
|
+
* `post_apply`: invoked after `apply` task runs
|
108
|
+
* `pre_destroy`: invoked before `destroy` task runs
|
109
|
+
* `post_destroy`: invoked after `destroy` task runs
|
110
|
+
* `custom_prepare`: invoked during the preparation process, before terraform is initialized
|
111
|
+
* `custom_test`: invoked during as part of the `test` task, right after `apply` completes.
|
112
|
+
|
92
113
|
### Sample Terraform/Terragrunt Templates
|
93
114
|
|
94
115
|
The following file (`main.tf.mustache`) contains the infrastructure configuration (a single S3 bucket) as well as information related to the AWS provider.
|
@@ -148,9 +169,7 @@ terragrunt = {
|
|
148
169
|
|
149
170
|
### Injecting Additional Variables into Template Files
|
150
171
|
|
151
|
-
In addition to the default variables that are passed to Mustache when rendering
|
152
|
-
a template file, users can provide additional variables. To do so, users must register a procedure that receives the environment as a parameter and returns
|
153
|
-
a map with the extra variables and their values. An example is shown next:
|
172
|
+
In addition to the default variables that are passed to Mustache when rendering a template file, users can provide additional variables. To do so, users must register a procedure that receives the environment as a parameter and returns a map with the extra variables and their values. An example is shown next:
|
154
173
|
|
155
174
|
```ruby
|
156
175
|
TDK::TerraformConfigManager.register_extra_vars_proc(
|
@@ -160,14 +179,11 @@ TDK::TerraformConfigManager.register_extra_vars_proc(
|
|
160
179
|
)
|
161
180
|
```
|
162
181
|
|
163
|
-
###
|
182
|
+
### Updating Modules
|
164
183
|
|
165
|
-
|
166
|
-
module when it executes Terraform. This may take a while, depending on the
|
167
|
-
number of modules used in the infrastructure.
|
184
|
+
Terraform will get the necessary modules every time a new environment is created. Once the modules are cached, there is generally no need to keep updating the modules each time Terraform is executed. When using a module repository it is possible to select a specific version to use (as shown [here](https://www.terraform.io/docs/modules/sources.html#ref)). In such a case, Terraform will automatically update the modules whenever the version number is changed.
|
168
185
|
|
169
|
-
When
|
170
|
-
by setting the environment variable `TF_DEVKIT_SKIP_MODULE_UPDATE` to `true`.
|
186
|
+
When using local modules (e.g., during development process) it might be desirable to update the modules every time Terraform runs. This can be achieved by setting the environment variable `TF_DEVKIT_UPDATE_MODULES` to `true`.
|
171
187
|
|
172
188
|
## Development
|
173
189
|
|
@@ -17,10 +17,8 @@ module TerraformDevKit
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.update_modules?
|
20
|
-
|
21
|
-
|
22
|
-
.downcase
|
23
|
-
skip_update != 'true'
|
20
|
+
var = ENV.fetch('TF_DEVKIT_UPDATE_MODULES', 'false')
|
21
|
+
var.strip.casecmp('true').zero?
|
24
22
|
end
|
25
23
|
|
26
24
|
private_class_method
|
@@ -10,13 +10,21 @@ module TerraformDevKit
|
|
10
10
|
LOCAL_FILE_NAME = 'terraform.zip'.freeze
|
11
11
|
|
12
12
|
def self.installed_terraform_version
|
13
|
-
|
14
|
-
match = /Terraform v(\d+\.\d+\.\d+)/.match(version)
|
15
|
-
match[1] unless match.nil?
|
13
|
+
extract_version(Command.run('terraform --version'))
|
16
14
|
rescue
|
17
15
|
nil
|
18
16
|
end
|
19
17
|
|
18
|
+
def self.extract_version(output)
|
19
|
+
# Terraform vx.y.z might be anywhere in the output (warnings may appear
|
20
|
+
# before the version does). Therefore we scan all the lines.
|
21
|
+
|
22
|
+
matches = output.map { |line| /Terraform v(\d+\.\d+\.\d+)/.match(line) }
|
23
|
+
.reject(&:nil?)
|
24
|
+
|
25
|
+
matches.count == 1 ? matches[0][1] : nil
|
26
|
+
end
|
27
|
+
|
20
28
|
def self.install_local(version, directory: Dir.pwd)
|
21
29
|
if installed_terraform_version == version
|
22
30
|
puts 'Terraform already installed'
|
data/tasks/devkit.rake
CHANGED
@@ -21,6 +21,12 @@ rescue StandardError => e
|
|
21
21
|
raise
|
22
22
|
end
|
23
23
|
|
24
|
+
def invoke_if_defined(task_name, env)
|
25
|
+
if Rake::Task.task_defined?(task_name)
|
26
|
+
task(task_name).invoke(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
24
30
|
desc 'Prepares the environment to create the infrastructure'
|
25
31
|
task :prepare, [:env] do |_, args|
|
26
32
|
puts "== Configuring environment #{args.env}"
|
@@ -41,9 +47,7 @@ task :prepare, [:env] do |_, args|
|
|
41
47
|
|
42
48
|
TDK::TerraformConfigManager.setup(env)
|
43
49
|
|
44
|
-
|
45
|
-
task('custom_prepare').invoke(args.env)
|
46
|
-
end
|
50
|
+
invoke_if_defined('custom_prepare', args.env)
|
47
51
|
|
48
52
|
TDK::Command.run(
|
49
53
|
'terragrunt init -upgrade=false',
|
@@ -64,13 +68,14 @@ end
|
|
64
68
|
|
65
69
|
desc 'Creates the infrastructure'
|
66
70
|
task :apply, [:env] => :prepare do |_, args|
|
71
|
+
invoke_if_defined('pre_apply', args.env)
|
72
|
+
|
67
73
|
env = TDK::Environment.new(args.env)
|
68
74
|
destroy_if_fails(env) do
|
69
75
|
TDK::Command.run('terragrunt apply', directory: env.working_dir)
|
70
76
|
end
|
71
|
-
|
72
|
-
|
73
|
-
end
|
77
|
+
|
78
|
+
invoke_if_defined('post_apply', args.env)
|
74
79
|
end
|
75
80
|
|
76
81
|
desc 'Tests a local environment'
|
@@ -81,9 +86,7 @@ task :test, [:env] do |_, args|
|
|
81
86
|
task('apply').invoke(env.name)
|
82
87
|
|
83
88
|
destroy_if_fails(env) do
|
84
|
-
|
85
|
-
task('custom_test').invoke(args.env)
|
86
|
-
end
|
89
|
+
invoke_if_defined('custom_test', args.env)
|
87
90
|
end
|
88
91
|
end
|
89
92
|
|
@@ -97,13 +100,14 @@ end
|
|
97
100
|
|
98
101
|
desc 'Destroys the infrastructure'
|
99
102
|
task :destroy, [:env] => :prepare do |_, args|
|
103
|
+
invoke_if_defined('pre_destroy', args.env)
|
104
|
+
|
100
105
|
env = TDK::Environment.new(args.env)
|
101
106
|
cmd = 'terragrunt destroy'
|
102
107
|
cmd += ' -force' if env.local_backend?
|
103
108
|
TDK::Command.run(cmd, directory: env.working_dir, close_stdin: false)
|
104
|
-
|
105
|
-
|
106
|
-
end
|
109
|
+
|
110
|
+
invoke_if_defined('post_destroy', args.env)
|
107
111
|
end
|
108
112
|
|
109
113
|
desc 'Cleans an environment (infrastructure is destroyed too)'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: TerraformDevKit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Jimenez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|