terraform-wrapper 1.3.1 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,39 +1,36 @@
1
1
  ###############################################################################
2
2
 
3
3
  module TerraformWrapper
4
-
5
- ###############################################################################
4
+ #############################################################################
6
5
 
7
6
  module Tasks
8
-
9
- ###############################################################################
7
+ ###########################################################################
10
8
 
11
9
  class Clean < ::Rake::TaskLib
12
-
13
- ###############################################################################
10
+ #########################################################################
14
11
 
15
12
  include TerraformWrapper::Shared::Logging
16
13
 
17
- ###############################################################################
14
+ #########################################################################
18
15
 
19
16
  @@glob_directories = {
20
- "Terraform Modules" => "**/.terraform"
17
+ 'Terraform Modules' => '**/.terraform'
21
18
  }
22
19
 
23
- ###############################################################################
20
+ #########################################################################
24
21
 
25
22
  @@glob_files = {
26
- "Crash Logs" => "**/crash.log",
27
- "Graph Images" => "**/graph.png",
28
- "Terraform States" => "**/*.tfstate",
29
- "Terraform State Backups" => "**/*.tfstate.backup"
23
+ 'Crash Logs' => '**/crash.log',
24
+ 'Graph Images' => '**/graph.png',
25
+ 'Terraform States' => '**/*.tfstate',
26
+ 'Terraform State Backups' => '**/*.tfstate.backup'
30
27
  }
31
28
 
32
- ###############################################################################
29
+ #########################################################################
33
30
 
34
31
  @code
35
32
 
36
- ###############################################################################
33
+ #########################################################################
37
34
 
38
35
  def initialize(code:)
39
36
  @code = code
@@ -43,11 +40,11 @@ module TerraformWrapper
43
40
  clean_task
44
41
  end
45
42
 
46
- ###############################################################################
43
+ #########################################################################
47
44
 
48
45
  def clean_task
49
- desc "Cleans a Terraform infrastructure component workspace of any downloaded providers and modules."
50
- task :clean do |t, args|
46
+ desc 'Cleans a Terraform infrastructure component workspace of any downloaded providers and modules.'
47
+ task :clean do |_t, _args|
51
48
  logger.info("Cleaning Terraform component: #{@code.name}...")
52
49
 
53
50
  directory_counter = 0
@@ -57,12 +54,12 @@ module TerraformWrapper
57
54
 
58
55
  directories = Dir.glob(File.join(@code.path, value))
59
56
  directories.each do |directory|
60
- if delete_directory(directory: directory) then
57
+ if delete_directory(directory: directory)
61
58
  directory_item_counter += 1
62
59
  directory_counter += 1
63
60
  end
64
61
  end
65
- logger.success("Cleaned: #{directory_item_counter.to_s} directories.")
62
+ logger.success("Cleaned: #{directory_item_counter} directories.")
66
63
  end
67
64
 
68
65
  file_counter = 0
@@ -72,70 +69,67 @@ module TerraformWrapper
72
69
 
73
70
  files = Dir.glob(File.join(@code.path, value))
74
71
  files.each do |file|
75
- if delete_file(file: file) then
72
+ if delete_file(file: file)
76
73
  file_item_counter += 1
77
74
  file_counter += 1
78
75
  end
79
76
  end
80
- logger.success("Cleaned: #{file_item_counter.to_s} files.")
77
+ logger.success("Cleaned: #{file_item_counter} files.")
81
78
  end
82
79
 
83
- logger.success("Cleaned total: #{directory_counter.to_s} directories and: #{file_counter.to_s} files.")
80
+ logger.success("Cleaned total: #{directory_counter} directories and: #{file_counter} files.")
84
81
  end
85
82
  end
86
83
 
87
- ###############################################################################
84
+ #########################################################################
88
85
 
89
- private
86
+ private
90
87
 
91
- ###############################################################################
88
+ #########################################################################
89
+
90
+ def delete_directory(directory:)
91
+ result = false
92
92
 
93
- def delete_directory(directory:)
94
- result = false
95
-
96
- if File.directory?(directory) then
97
- begin
98
- FileUtils.remove_dir(directory)
99
- result = true
100
- logger.info("Deleted directory: #{directory}")
101
- rescue
102
- result = false
103
- logger.warn("Failed to delete directory: #{directory}")
93
+ if File.directory?(directory)
94
+ begin
95
+ FileUtils.remove_dir(directory)
96
+ result = true
97
+ logger.info("Deleted directory: #{directory}")
98
+ rescue StandardError
99
+ result = false
100
+ logger.warn("Failed to delete directory: #{directory}")
101
+ end
104
102
  end
103
+
104
+ result
105
105
  end
106
106
 
107
- return result
108
- end
107
+ #########################################################################
109
108
 
110
- ###############################################################################
109
+ def delete_file(file:)
110
+ result = false
111
111
 
112
- def delete_file(file:)
113
- result = false
114
-
115
- if File.file?(file) then
116
- begin
117
- File.delete(file)
118
- result = true
119
- logger.info("Deleted file: #{file}")
120
- rescue
121
- result = false
122
- logger.warn("Failed to delete file: #{file}")
112
+ if File.file?(file)
113
+ begin
114
+ File.delete(file)
115
+ result = true
116
+ logger.info("Deleted file: #{file}")
117
+ rescue StandardError
118
+ result = false
119
+ logger.warn("Failed to delete file: #{file}")
120
+ end
123
121
  end
124
- end
125
-
126
- return result
127
- end
128
122
 
129
- ###############################################################################
123
+ result
124
+ end
130
125
 
126
+ #########################################################################
131
127
  end
132
128
 
133
- ###############################################################################
134
-
129
+ ###########################################################################
135
130
  end
136
131
 
137
- ###############################################################################
138
-
132
+ #############################################################################
139
133
  end
140
134
 
141
135
  ###############################################################################
@@ -1,26 +1,23 @@
1
1
  ###############################################################################
2
2
 
3
3
  module TerraformWrapper
4
-
5
- ###############################################################################
4
+ #############################################################################
6
5
 
7
6
  module Tasks
8
-
9
- ###############################################################################
7
+ ###########################################################################
10
8
 
11
9
  class Destroy < ::Rake::TaskLib
12
-
13
- ###############################################################################
10
+ #########################################################################
14
11
 
15
12
  include TerraformWrapper::Shared::Logging
16
13
 
17
- ###############################################################################
14
+ #########################################################################
18
15
 
19
16
  @binary
20
17
  @code
21
18
  @options
22
19
 
23
- ###############################################################################
20
+ #########################################################################
24
21
 
25
22
  def initialize(binary:, code:, options:)
26
23
  @binary = binary
@@ -32,14 +29,14 @@ module TerraformWrapper
32
29
  destroy_task
33
30
  end
34
31
 
35
- ###############################################################################
32
+ #########################################################################
36
33
 
37
34
  def destroy_task
38
- desc "Destroys infrastructure with Terraform for a given configuration on an infrastructure component."
39
- task :destroy, [:config] => :binary do |t, args|
40
- options = @options.merge({"name" => args[:config]})
35
+ desc 'Destroys infrastructure with Terraform for a given configuration on an infrastructure component.'
36
+ task :destroy, [:config] => :binary do |_t, args|
37
+ options = @options.merge({ 'name' => args[:config] })
41
38
 
42
- logger.info("Processing configuration for Terraform destroy...")
39
+ logger.info('Processing configuration for Terraform destroy...')
43
40
 
44
41
  config = TerraformWrapper::Shared::Config.new(code: @code, options: options)
45
42
  runner = TerraformWrapper::Shared::Runner.new(binary: @binary, code: @code)
@@ -51,16 +48,13 @@ module TerraformWrapper
51
48
  end
52
49
  end
53
50
 
54
- ###############################################################################
55
-
51
+ #########################################################################
56
52
  end
57
53
 
58
- ###############################################################################
59
-
54
+ ###########################################################################
60
55
  end
61
56
 
62
- ###############################################################################
63
-
57
+ #############################################################################
64
58
  end
65
59
 
66
60
  ###############################################################################
@@ -0,0 +1,54 @@
1
+ ###############################################################################
2
+
3
+ module TerraformWrapper
4
+ #############################################################################
5
+
6
+ module Tasks
7
+ ###########################################################################
8
+
9
+ class Fmt < ::Rake::TaskLib
10
+ #########################################################################
11
+
12
+ include TerraformWrapper::Shared::Logging
13
+
14
+ #########################################################################
15
+
16
+ @binary
17
+ @code
18
+
19
+ #########################################################################
20
+
21
+ def initialize(binary:, code:)
22
+ @binary = binary
23
+ @code = code
24
+
25
+ yield self if block_given?
26
+
27
+ fmt_task
28
+ end
29
+
30
+ #########################################################################
31
+
32
+ def fmt_task
33
+ desc 'Manages the formatting of the Terraform code for an infrastructure component.'
34
+ task :fmt, [:check] => :binary do |_t, args|
35
+ args.with_defaults(check: true)
36
+
37
+ runner = TerraformWrapper::Shared::Runner.new(binary: @binary, code: @code)
38
+
39
+ logger.info("Fmt Terraform component: #{@code.name}...")
40
+
41
+ runner.fmt(check: args[:check])
42
+ end
43
+ end
44
+
45
+ #########################################################################
46
+ end
47
+
48
+ ###########################################################################
49
+ end
50
+
51
+ #############################################################################
52
+ end
53
+
54
+ ###############################################################################
@@ -1,26 +1,23 @@
1
1
  ###############################################################################
2
2
 
3
3
  module TerraformWrapper
4
-
5
- ###############################################################################
4
+ #############################################################################
6
5
 
7
6
  module Tasks
8
-
9
- ###############################################################################
7
+ ###########################################################################
10
8
 
11
9
  class Import < ::Rake::TaskLib
12
-
13
- ###############################################################################
10
+ #########################################################################
14
11
 
15
12
  include TerraformWrapper::Shared::Logging
16
13
 
17
- ###############################################################################
14
+ #########################################################################
18
15
 
19
16
  @binary
20
17
  @code
21
18
  @options
22
19
 
23
- ###############################################################################
20
+ #########################################################################
24
21
 
25
22
  def initialize(binary:, code:, options:)
26
23
  @binary = binary
@@ -32,14 +29,14 @@ module TerraformWrapper
32
29
  import_task
33
30
  end
34
31
 
35
- ###############################################################################
32
+ #########################################################################
36
33
 
37
34
  def import_task
38
- desc "Import a piece of existing infrastructure into Terraform state for a given configuration on an infrastructure component."
39
- task :import, [:config, :address, :id] => :binary do |t, args|
40
- options = @options.merge({"name" => args[:config]})
35
+ desc 'Import a piece of existing infrastructure into Terraform state for a given configuration on an infrastructure component.'
36
+ task :import, %i[config address id] => :binary do |_t, args|
37
+ options = @options.merge({ 'name' => args[:config] })
41
38
 
42
- logger.info("Processing configuration for Terraform import...")
39
+ logger.info('Processing configuration for Terraform import...')
43
40
 
44
41
  config = TerraformWrapper::Shared::Config.new(code: @code, options: options)
45
42
  runner = TerraformWrapper::Shared::Runner.new(binary: @binary, code: @code)
@@ -51,16 +48,13 @@ module TerraformWrapper
51
48
  end
52
49
  end
53
50
 
54
- ###############################################################################
55
-
51
+ #########################################################################
56
52
  end
57
53
 
58
- ###############################################################################
59
-
54
+ ###########################################################################
60
55
  end
61
56
 
62
- ###############################################################################
63
-
57
+ #############################################################################
64
58
  end
65
59
 
66
60
  ###############################################################################
@@ -1,26 +1,23 @@
1
1
  ###############################################################################
2
2
 
3
3
  module TerraformWrapper
4
-
5
- ###############################################################################
4
+ #############################################################################
6
5
 
7
6
  module Tasks
8
-
9
- ###############################################################################
7
+ ###########################################################################
10
8
 
11
9
  class Init < ::Rake::TaskLib
12
-
13
- ###############################################################################
10
+ #########################################################################
14
11
 
15
12
  include TerraformWrapper::Shared::Logging
16
13
 
17
- ###############################################################################
14
+ #########################################################################
18
15
 
19
16
  @binary
20
17
  @code
21
18
  @options
22
19
 
23
- ###############################################################################
20
+ #########################################################################
24
21
 
25
22
  def initialize(binary:, code:, options:)
26
23
  @binary = binary
@@ -32,14 +29,14 @@ module TerraformWrapper
32
29
  init_task
33
30
  end
34
31
 
35
- ###############################################################################
32
+ #########################################################################
36
33
 
37
34
  def init_task
38
- desc "Initialises the Terraform infrastructure component and state backend."
39
- task :init, [:config] => :binary do |t, args|
40
- options = @options.merge({"name" => args[:config]})
35
+ desc 'Initialises the Terraform infrastructure component and state backend.'
36
+ task :init, [:config] => :binary do |_t, args|
37
+ options = @options.merge({ 'name' => args[:config] })
41
38
 
42
- logger.info("Processing configuration for Terraform init...")
39
+ logger.info('Processing configuration for Terraform init...')
43
40
 
44
41
  config = TerraformWrapper::Shared::Config.new(code: @code, options: options)
45
42
  runner = TerraformWrapper::Shared::Runner.new(binary: @binary, code: @code)
@@ -50,16 +47,13 @@ module TerraformWrapper
50
47
  end
51
48
  end
52
49
 
53
- ###############################################################################
54
-
50
+ #########################################################################
55
51
  end
56
52
 
57
- ###############################################################################
58
-
53
+ ###########################################################################
59
54
  end
60
55
 
61
- ###############################################################################
62
-
56
+ #############################################################################
63
57
  end
64
58
 
65
59
  ###############################################################################
@@ -1,26 +1,23 @@
1
1
  ###############################################################################
2
2
 
3
3
  module TerraformWrapper
4
-
5
- ###############################################################################
4
+ #############################################################################
6
5
 
7
6
  module Tasks
8
-
9
- ###############################################################################
7
+ ###########################################################################
10
8
 
11
9
  class Plan < ::Rake::TaskLib
12
-
13
- ###############################################################################
10
+ #########################################################################
14
11
 
15
12
  include TerraformWrapper::Shared::Logging
16
13
 
17
- ###############################################################################
14
+ #########################################################################
18
15
 
19
16
  @binary
20
17
  @code
21
18
  @options
22
19
 
23
- ###############################################################################
20
+ #########################################################################
24
21
 
25
22
  def initialize(binary:, code:, options:)
26
23
  @binary = binary
@@ -32,14 +29,14 @@ module TerraformWrapper
32
29
  plan_task
33
30
  end
34
31
 
35
- ###############################################################################
32
+ #########################################################################
36
33
 
37
34
  def plan_task
38
- desc "Creates a Terraform plan for a given configuration on an infrastructure component."
39
- task :plan, [:config, :out] => :binary do |t, args|
40
- options = @options.merge({"name" => args[:config]})
35
+ desc 'Creates a Terraform plan for a given configuration on an infrastructure component.'
36
+ task :plan, %i[config out] => :binary do |_t, args|
37
+ options = @options.merge({ 'name' => args[:config] })
41
38
 
42
- logger.info("Processing configuration for Terraform plan...")
39
+ logger.info('Processing configuration for Terraform plan...')
43
40
 
44
41
  config = TerraformWrapper::Shared::Config.new(code: @code, options: options)
45
42
  runner = TerraformWrapper::Shared::Runner.new(binary: @binary, code: @code)
@@ -51,16 +48,13 @@ module TerraformWrapper
51
48
  end
52
49
  end
53
50
 
54
- ###############################################################################
55
-
51
+ #########################################################################
56
52
  end
57
53
 
58
- ###############################################################################
59
-
54
+ ###########################################################################
60
55
  end
61
56
 
62
- ###############################################################################
63
-
57
+ #############################################################################
64
58
  end
65
59
 
66
60
  ###############################################################################
@@ -1,26 +1,23 @@
1
1
  ###############################################################################
2
2
 
3
3
  module TerraformWrapper
4
-
5
- ###############################################################################
4
+ #############################################################################
6
5
 
7
6
  module Tasks
8
-
9
- ###############################################################################
7
+ ###########################################################################
10
8
 
11
9
  class PlanDestroy < ::Rake::TaskLib
12
-
13
- ###############################################################################
10
+ #########################################################################
14
11
 
15
12
  include TerraformWrapper::Shared::Logging
16
13
 
17
- ###############################################################################
14
+ #########################################################################
18
15
 
19
16
  @binary
20
17
  @code
21
18
  @options
22
19
 
23
- ###############################################################################
20
+ #########################################################################
24
21
 
25
22
  def initialize(binary:, code:, options:)
26
23
  @binary = binary
@@ -32,14 +29,14 @@ module TerraformWrapper
32
29
  plan_destroy_task
33
30
  end
34
31
 
35
- ###############################################################################
32
+ #########################################################################
36
33
 
37
34
  def plan_destroy_task
38
- desc "Creates a Terraform destroy plan for a given configuration on an infrastructure component."
39
- task :"plan-destroy", [:config, :out] => :binary do |t, args|
40
- options = @options.merge({"name" => args[:config]})
35
+ desc 'Creates a Terraform destroy plan for a given configuration on an infrastructure component.'
36
+ task :"plan-destroy", %i[config out] => :binary do |_t, args|
37
+ options = @options.merge({ 'name' => args[:config] })
41
38
 
42
- logger.info("Processing configuration for Terraform destroy plan...")
39
+ logger.info('Processing configuration for Terraform destroy plan...')
43
40
 
44
41
  config = TerraformWrapper::Shared::Config.new(code: @code, options: options)
45
42
  runner = TerraformWrapper::Shared::Runner.new(binary: @binary, code: @code)
@@ -51,16 +48,13 @@ module TerraformWrapper
51
48
  end
52
49
  end
53
50
 
54
- ###############################################################################
55
-
51
+ #########################################################################
56
52
  end
57
53
 
58
- ###############################################################################
59
-
54
+ ###########################################################################
60
55
  end
61
56
 
62
- ###############################################################################
63
-
57
+ #############################################################################
64
58
  end
65
59
 
66
60
  ###############################################################################