rake_terraform 1.11.0 → 1.16.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +120 -32
- data/Rakefile +110 -37
- data/bin/console +4 -3
- data/lib/rake_terraform.rb +33 -114
- data/lib/rake_terraform/task_sets.rb +4 -0
- data/lib/rake_terraform/task_sets/all.rb +48 -40
- data/lib/rake_terraform/task_sets/provider.rb +168 -0
- data/lib/rake_terraform/task_sets/terraform.rb +179 -0
- data/lib/rake_terraform/tasks.rb +2 -0
- data/lib/rake_terraform/tasks/destroy.rb +30 -25
- data/lib/rake_terraform/tasks/output.rb +26 -21
- data/lib/rake_terraform/tasks/plan.rb +29 -24
- data/lib/rake_terraform/tasks/provision.rb +30 -26
- data/lib/rake_terraform/tasks/validate.rb +26 -21
- data/lib/rake_terraform/version.rb +3 -1
- data/rake_terraform.gemspec +36 -14
- metadata +145 -77
- data/.circleci/config.yml +0 -56
- data/.circleci/gpg.private.enc +0 -0
- data/.envrc +0 -5
- data/.git-crypt/.gitattributes +0 -4
- data/.git-crypt/keys/default/0/41D2606F66C3FF28874362B61A16916844CE9D82.gpg +0 -0
- data/.git-crypt/keys/default/0/AAE932B730C2BA697FFDFAE05DA390873E38358B.gpg +0 -0
- data/.gitattributes +0 -1
- data/.gitignore +0 -32
- data/.rspec +0 -2
- data/.ruby-version +0 -1
- data/CHANGELOG.md +0 -35
- data/config/secrets/.unlocked +0 -1
- data/config/secrets/ci/encryption.passphrase +0 -1
- data/config/secrets/ci/gpg.private +0 -58
- data/config/secrets/ci/gpg.public +0 -31
- data/config/secrets/ci/ssh.private +0 -51
- data/config/secrets/ci/ssh.public +0 -1
- data/config/secrets/circle_ci/config.yaml +0 -2
- data/config/secrets/github/config.yaml +0 -2
- data/config/secrets/rubygems/credentials +0 -2
- data/go +0 -56
- data/scripts/ci/common/configure-git.sh +0 -8
- data/scripts/ci/common/configure-rubygems.sh +0 -16
- data/scripts/ci/common/install-git-crypt.sh +0 -8
- data/scripts/ci/common/install-gpg-key.sh +0 -19
- data/scripts/ci/steps/prerelease.sh +0 -16
- data/scripts/ci/steps/release.sh +0 -18
- data/scripts/ci/steps/test.sh +0 -12
@@ -0,0 +1,179 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
module RakeTerraform
|
6
|
+
module TaskSets
|
7
|
+
# rubocop:disable Metrics/ClassLength
|
8
|
+
|
9
|
+
class Terraform
|
10
|
+
def self.define(*args, &configuration_block)
|
11
|
+
new(*args, &configuration_block).define_on(Rake.application)
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :delegate
|
15
|
+
|
16
|
+
def initialize(*args, &configuration_block)
|
17
|
+
@opts = args[0]
|
18
|
+
@delegate =
|
19
|
+
RakeDependencies::TaskSets::All.define(
|
20
|
+
task_set_opts, &configuration_block
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def define_on(application)
|
25
|
+
@delegate.define_on(application)
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def binary
|
30
|
+
@binary ||= File.join(path, binary_directory, binary_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# rubocop:disable Metrics/MethodLength
|
36
|
+
|
37
|
+
def task_set_opts
|
38
|
+
{
|
39
|
+
namespace: namespace,
|
40
|
+
dependency: dependency,
|
41
|
+
version: version,
|
42
|
+
path: path,
|
43
|
+
type: type,
|
44
|
+
|
45
|
+
os_ids: os_ids,
|
46
|
+
|
47
|
+
uri_template: uri_template,
|
48
|
+
file_name_template: file_name_template,
|
49
|
+
|
50
|
+
binary_directory: binary_directory,
|
51
|
+
|
52
|
+
needs_fetch: needs_fetch
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
# rubocop:enable Metrics/MethodLength
|
57
|
+
|
58
|
+
def logger
|
59
|
+
@logger ||=
|
60
|
+
@opts[:logger] ||
|
61
|
+
Logger.new($stderr,
|
62
|
+
level: Logger.const_get(ENV['TF_LOG'] || 'WARN'))
|
63
|
+
end
|
64
|
+
|
65
|
+
def namespace
|
66
|
+
@namespace ||= @opts[:namespace] || :terraform
|
67
|
+
end
|
68
|
+
|
69
|
+
def dependency
|
70
|
+
@dependency ||= 'terraform'
|
71
|
+
end
|
72
|
+
|
73
|
+
def version
|
74
|
+
@version ||= @opts[:version] || '0.10.3'
|
75
|
+
end
|
76
|
+
|
77
|
+
def path
|
78
|
+
@path ||= @opts[:path] ||
|
79
|
+
File.join(Dir.pwd, 'vendor', 'terraform')
|
80
|
+
end
|
81
|
+
|
82
|
+
def binary_directory
|
83
|
+
@binary_directory ||= 'bin'
|
84
|
+
end
|
85
|
+
|
86
|
+
def binary_name
|
87
|
+
@binary_name ||= 'terraform'
|
88
|
+
end
|
89
|
+
|
90
|
+
def type
|
91
|
+
@type ||= :zip
|
92
|
+
end
|
93
|
+
|
94
|
+
def os_ids
|
95
|
+
@os_ids ||= { mac: 'darwin', linux: 'linux' }
|
96
|
+
end
|
97
|
+
|
98
|
+
def uri_template
|
99
|
+
@uri_template ||=
|
100
|
+
'https://releases.hashicorp.com/terraform/<%= @version %>/' \
|
101
|
+
'terraform_<%= @version %>_<%= @os_id %>_amd64<%= @ext %>'
|
102
|
+
end
|
103
|
+
|
104
|
+
def file_name_template
|
105
|
+
@file_name_template ||=
|
106
|
+
'terraform_<%= @version %>_<%= @os_id %>_amd64<%= @ext %>'
|
107
|
+
end
|
108
|
+
|
109
|
+
def needs_fetch
|
110
|
+
@needs_fetch ||= ->(_) { return !exists_with_correct_version?(binary) }
|
111
|
+
end
|
112
|
+
|
113
|
+
def exists_with_correct_version?(binary)
|
114
|
+
log_binary_location(binary)
|
115
|
+
|
116
|
+
exist?(binary) && correct_version?(binary)
|
117
|
+
end
|
118
|
+
|
119
|
+
def exist?(binary)
|
120
|
+
File.exist?(binary)
|
121
|
+
end
|
122
|
+
|
123
|
+
def correct_version?(binary)
|
124
|
+
result = StringIO.new
|
125
|
+
command = version_command(binary)
|
126
|
+
|
127
|
+
log_version_lookup(command)
|
128
|
+
|
129
|
+
command.execute(stdout: result)
|
130
|
+
|
131
|
+
log_version_information(result)
|
132
|
+
log_check_outcome(result)
|
133
|
+
|
134
|
+
contains_version_number?(result)
|
135
|
+
end
|
136
|
+
|
137
|
+
def version_command(binary)
|
138
|
+
Lino::CommandLineBuilder
|
139
|
+
.for_command(binary)
|
140
|
+
.with_flag('-version')
|
141
|
+
.build
|
142
|
+
end
|
143
|
+
|
144
|
+
def log_binary_location(binary)
|
145
|
+
logger.info("Terraform binary should be at: #{binary}")
|
146
|
+
end
|
147
|
+
|
148
|
+
def log_version_lookup(command)
|
149
|
+
logger.info(
|
150
|
+
'Fetching terraform version information using command: ' \
|
151
|
+
"#{command}"
|
152
|
+
)
|
153
|
+
end
|
154
|
+
|
155
|
+
def log_version_information(result)
|
156
|
+
logger.info(
|
157
|
+
"Terraform version information is: \n#{result}"
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
def log_check_outcome(result)
|
162
|
+
logger.debug(
|
163
|
+
"Version: '#{version}' is in version line: " \
|
164
|
+
"'#{version_line(result)}'?: #{contains_version_number?(result)}"
|
165
|
+
)
|
166
|
+
end
|
167
|
+
|
168
|
+
def version_line(result)
|
169
|
+
result.string.lines.first
|
170
|
+
end
|
171
|
+
|
172
|
+
def contains_version_number?(result)
|
173
|
+
version_line(result) =~ /#{version}/
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# rubocop:enable Metrics/ClassLength
|
178
|
+
end
|
179
|
+
end
|
data/lib/rake_terraform/tasks.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rake_factory'
|
2
4
|
require 'ruby_terraform'
|
3
5
|
require 'ostruct'
|
@@ -7,16 +9,16 @@ module RakeTerraform
|
|
7
9
|
module Tasks
|
8
10
|
class Destroy < RakeFactory::Task
|
9
11
|
default_name :destroy
|
10
|
-
default_prerequisites
|
12
|
+
default_prerequisites(RakeFactory::DynamicValue.new do |t|
|
11
13
|
[t.ensure_task_name]
|
12
|
-
|
13
|
-
default_description
|
14
|
+
end)
|
15
|
+
default_description(RakeFactory::DynamicValue.new do |t|
|
14
16
|
"Destroy #{t.configuration_name} using terraform"
|
15
|
-
|
17
|
+
end)
|
16
18
|
|
17
|
-
parameter :configuration_name, :
|
18
|
-
parameter :source_directory, :
|
19
|
-
parameter :work_directory, :
|
19
|
+
parameter :configuration_name, required: true
|
20
|
+
parameter :source_directory, required: true
|
21
|
+
parameter :work_directory, required: true
|
20
22
|
|
21
23
|
parameter :backend_config
|
22
24
|
|
@@ -24,39 +26,42 @@ module RakeTerraform
|
|
24
26
|
parameter :var_file
|
25
27
|
parameter :state_file
|
26
28
|
|
27
|
-
parameter :debug, :
|
28
|
-
parameter :no_color, :
|
29
|
-
parameter :no_backup, :
|
29
|
+
parameter :debug, default: false
|
30
|
+
parameter :no_color, default: false
|
31
|
+
parameter :no_backup, default: false
|
30
32
|
|
31
33
|
parameter :backup_file
|
32
34
|
|
33
|
-
parameter :ensure_task_name, :
|
35
|
+
parameter :ensure_task_name, default: :'terraform:ensure'
|
34
36
|
|
35
37
|
action do |t|
|
36
38
|
Colored2.disable! if t.no_color
|
37
39
|
|
38
40
|
configuration_directory =
|
39
|
-
|
41
|
+
File.join(t.work_directory, t.source_directory)
|
40
42
|
|
41
|
-
puts "Destroying #{t.configuration_name}".cyan
|
43
|
+
Kernel.puts "Destroying #{t.configuration_name}".cyan
|
42
44
|
RubyTerraform.clean(
|
43
|
-
|
45
|
+
directory: configuration_directory
|
46
|
+
)
|
44
47
|
|
45
|
-
mkdir_p
|
46
|
-
cp_r
|
48
|
+
FileUtils.mkdir_p(File.dirname(configuration_directory))
|
49
|
+
FileUtils.cp_r(t.source_directory, configuration_directory)
|
47
50
|
|
48
51
|
Dir.chdir(configuration_directory) do
|
49
52
|
RubyTerraform.init(
|
50
|
-
|
51
|
-
|
53
|
+
backend_config: t.backend_config,
|
54
|
+
no_color: t.no_color
|
55
|
+
)
|
52
56
|
RubyTerraform.destroy(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
force: true,
|
58
|
+
no_color: t.no_color,
|
59
|
+
no_backup: t.no_backup,
|
60
|
+
backup: t.backup_file,
|
61
|
+
state: t.state_file,
|
62
|
+
vars: t.vars,
|
63
|
+
var_file: t.var_file
|
64
|
+
)
|
60
65
|
end
|
61
66
|
end
|
62
67
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rake_factory'
|
2
4
|
require 'ruby_terraform'
|
3
5
|
require 'ostruct'
|
@@ -7,50 +9,53 @@ module RakeTerraform
|
|
7
9
|
module Tasks
|
8
10
|
class Output < RakeFactory::Task
|
9
11
|
default_name :output
|
10
|
-
default_prerequisites
|
12
|
+
default_prerequisites(RakeFactory::DynamicValue.new do |t|
|
11
13
|
[t.ensure_task_name]
|
12
|
-
|
13
|
-
default_description
|
14
|
+
end)
|
15
|
+
default_description(RakeFactory::DynamicValue.new do |t|
|
14
16
|
"Output #{t.configuration_name} using terraform"
|
15
|
-
|
17
|
+
end)
|
16
18
|
|
17
|
-
parameter :configuration_name, :
|
18
|
-
parameter :source_directory, :
|
19
|
-
parameter :work_directory, :
|
19
|
+
parameter :configuration_name, required: true
|
20
|
+
parameter :source_directory, required: true
|
21
|
+
parameter :work_directory, required: true
|
20
22
|
|
21
23
|
parameter :backend_config
|
22
24
|
|
23
25
|
parameter :state_file
|
24
26
|
|
25
|
-
parameter :debug, :
|
26
|
-
parameter :no_color, :
|
27
|
-
parameter :no_print_output, :
|
27
|
+
parameter :debug, default: false
|
28
|
+
parameter :no_color, default: false
|
29
|
+
parameter :no_print_output, default: false
|
28
30
|
|
29
|
-
parameter :ensure_task_name, :
|
31
|
+
parameter :ensure_task_name, default: :'terraform:ensure'
|
30
32
|
|
31
33
|
action do |t|
|
32
34
|
Colored2.disable! if t.no_color
|
33
35
|
|
34
36
|
configuration_directory =
|
35
|
-
|
37
|
+
File.join(t.work_directory, t.source_directory)
|
36
38
|
|
37
|
-
puts
|
39
|
+
Kernel.puts("Output of #{t.configuration_name}".cyan)
|
38
40
|
RubyTerraform.clean(
|
39
|
-
|
41
|
+
directory: configuration_directory
|
42
|
+
)
|
40
43
|
|
41
|
-
mkdir_p
|
42
|
-
cp_r
|
44
|
+
FileUtils.mkdir_p(File.dirname(configuration_directory))
|
45
|
+
FileUtils.cp_r(t.source_directory, configuration_directory)
|
43
46
|
|
44
47
|
Dir.chdir(configuration_directory) do
|
45
48
|
RubyTerraform.init(
|
46
|
-
|
47
|
-
|
49
|
+
backend_config: t.backend_config,
|
50
|
+
no_color: t.no_color
|
51
|
+
)
|
48
52
|
|
49
53
|
output = RubyTerraform.output(
|
50
|
-
|
51
|
-
|
54
|
+
no_color: t.no_color,
|
55
|
+
state: t.state_file
|
56
|
+
)
|
52
57
|
|
53
|
-
puts
|
58
|
+
Kernel.puts(output) unless t.no_print_output
|
54
59
|
|
55
60
|
output
|
56
61
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rake_factory'
|
2
4
|
require 'ruby_terraform'
|
3
5
|
require 'ostruct'
|
@@ -7,16 +9,16 @@ module RakeTerraform
|
|
7
9
|
module Tasks
|
8
10
|
class Plan < RakeFactory::Task
|
9
11
|
default_name :plan
|
10
|
-
default_prerequisites
|
12
|
+
default_prerequisites(RakeFactory::DynamicValue.new do |t|
|
11
13
|
[t.ensure_task_name]
|
12
|
-
|
13
|
-
default_description
|
14
|
+
end)
|
15
|
+
default_description(RakeFactory::DynamicValue.new do |t|
|
14
16
|
"Plan #{t.configuration_name} using terraform"
|
15
|
-
|
17
|
+
end)
|
16
18
|
|
17
|
-
parameter :configuration_name, :
|
18
|
-
parameter :source_directory, :
|
19
|
-
parameter :work_directory, :
|
19
|
+
parameter :configuration_name, required: true
|
20
|
+
parameter :source_directory, required: true
|
21
|
+
parameter :work_directory, required: true
|
20
22
|
|
21
23
|
parameter :backend_config
|
22
24
|
|
@@ -24,38 +26,41 @@ module RakeTerraform
|
|
24
26
|
parameter :var_file
|
25
27
|
parameter :state_file
|
26
28
|
|
27
|
-
parameter :debug, :
|
28
|
-
parameter :no_color, :
|
29
|
+
parameter :debug, default: false
|
30
|
+
parameter :no_color, default: false
|
29
31
|
|
30
32
|
parameter :plan_file
|
31
|
-
parameter :destroy, :
|
33
|
+
parameter :destroy, default: false
|
32
34
|
|
33
|
-
parameter :ensure_task_name, :
|
35
|
+
parameter :ensure_task_name, default: :'terraform:ensure'
|
34
36
|
|
35
37
|
action do |t|
|
36
38
|
Colored2.disable! if t.no_color
|
37
39
|
|
38
40
|
configuration_directory =
|
39
|
-
|
41
|
+
File.join(t.work_directory, t.source_directory)
|
40
42
|
|
41
|
-
puts
|
43
|
+
Kernel.puts("Planning #{configuration_name}".cyan)
|
42
44
|
RubyTerraform.clean(
|
43
|
-
|
45
|
+
directory: configuration_directory
|
46
|
+
)
|
44
47
|
|
45
|
-
mkdir_p
|
46
|
-
cp_r
|
48
|
+
FileUtils.mkdir_p(File.dirname(configuration_directory))
|
49
|
+
FileUtils.cp_r(t.source_directory, configuration_directory)
|
47
50
|
|
48
51
|
Dir.chdir(configuration_directory) do
|
49
52
|
RubyTerraform.init(
|
50
|
-
|
51
|
-
|
53
|
+
backend_config: t.backend_config,
|
54
|
+
no_color: t.no_color
|
55
|
+
)
|
52
56
|
RubyTerraform.plan(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
no_color: t.no_color,
|
58
|
+
destroy: t.destroy,
|
59
|
+
state: t.state_file,
|
60
|
+
plan: t.plan_file,
|
61
|
+
vars: t.vars,
|
62
|
+
var_file: t.var_file
|
63
|
+
)
|
59
64
|
end
|
60
65
|
end
|
61
66
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rake_factory'
|
2
4
|
require 'ruby_terraform'
|
3
5
|
require 'ostruct'
|
@@ -7,16 +9,16 @@ module RakeTerraform
|
|
7
9
|
module Tasks
|
8
10
|
class Provision < RakeFactory::Task
|
9
11
|
default_name :provision
|
10
|
-
default_prerequisites
|
12
|
+
default_prerequisites(RakeFactory::DynamicValue.new do |t|
|
11
13
|
[t.ensure_task_name]
|
12
|
-
|
13
|
-
default_description
|
14
|
+
end)
|
15
|
+
default_description(RakeFactory::DynamicValue.new do |t|
|
14
16
|
"Provision #{t.configuration_name} using terraform"
|
15
|
-
|
17
|
+
end)
|
16
18
|
|
17
|
-
parameter :configuration_name, :
|
18
|
-
parameter :source_directory, :
|
19
|
-
parameter :work_directory, :
|
19
|
+
parameter :configuration_name, required: true
|
20
|
+
parameter :source_directory, required: true
|
21
|
+
parameter :work_directory, required: true
|
20
22
|
|
21
23
|
parameter :backend_config
|
22
24
|
|
@@ -24,40 +26,42 @@ module RakeTerraform
|
|
24
26
|
parameter :var_file
|
25
27
|
parameter :state_file
|
26
28
|
|
27
|
-
parameter :debug, :
|
28
|
-
parameter :no_color, :
|
29
|
-
parameter :no_backup, :
|
29
|
+
parameter :debug, default: false
|
30
|
+
parameter :no_color, default: false
|
31
|
+
parameter :no_backup, default: false
|
30
32
|
|
31
33
|
parameter :backup_file
|
32
34
|
|
33
|
-
parameter :ensure_task_name, :
|
35
|
+
parameter :ensure_task_name, default: :'terraform:ensure'
|
34
36
|
|
35
37
|
action do |t|
|
36
38
|
Colored2.disable! if t.no_color
|
37
39
|
|
38
40
|
configuration_directory =
|
39
|
-
|
41
|
+
File.join(t.work_directory, t.source_directory)
|
40
42
|
|
41
|
-
puts
|
43
|
+
Kernel.puts("Provisioning #{t.configuration_name}".cyan)
|
42
44
|
RubyTerraform.clean(
|
43
|
-
|
44
|
-
|
45
|
-
mkdir_p File.dirname(configuration_directory)
|
46
|
-
cp_r t.source_directory, configuration_directory
|
45
|
+
directory: configuration_directory
|
46
|
+
)
|
47
47
|
|
48
|
+
FileUtils.mkdir_p(File.dirname(configuration_directory))
|
49
|
+
FileUtils.cp_r(t.source_directory, configuration_directory)
|
48
50
|
|
49
51
|
Dir.chdir(configuration_directory) do
|
50
52
|
RubyTerraform.init(
|
51
|
-
|
52
|
-
|
53
|
+
backend_config: t.backend_config,
|
54
|
+
no_color: t.no_color
|
55
|
+
)
|
53
56
|
RubyTerraform.apply(
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
auto_approve: true,
|
58
|
+
no_color: t.no_color,
|
59
|
+
no_backup: t.no_backup,
|
60
|
+
backup: t.backup_file,
|
61
|
+
state: t.state_file,
|
62
|
+
vars: t.vars,
|
63
|
+
var_file: t.var_file
|
64
|
+
)
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|