rake-terraform-wrapper 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89c88b4d3fb51f2b11cac6e38f3750935ff678eedf6f8be9a4d57a50c0d7c18c
4
- data.tar.gz: 16f80114887a769b5473439f61009df0da52cc9683339ba97c9f9ddd195a3080
3
+ metadata.gz: 7397085e32a0cf518d65d3e6dfbe28a4ffde5cbacecac79bea4ae24b586f740c
4
+ data.tar.gz: 90474808154b39372a61dd0b691617987ca6a4ee3a3201ad2909e97d45533307
5
5
  SHA512:
6
- metadata.gz: 477ad93228587c2a6522725056f46ff8e76399069a2deb61516d3b27410d94e2c44f93aa92a66f2bffd15bd13b2fa6ec84f141663b27a833b00bc799f12bd418
7
- data.tar.gz: c03895337c9fbad834e96ab9c604505549e85744f0240b309b875ee402c135d2a8abff578799cb4c0ff4e7370d4e1019a3778439e8f21d00cc29c9a05c36c39a
6
+ metadata.gz: 44512e7239fbc0743d18378c6308bee6edb43fbf75d203383af1092dffbae5c393506ceacf324d5a12415eeae66b1b78d3515d858d1b6a82c9d0466210a08f81
7
+ data.tar.gz: 73463bcd33110d0a2750a1c2c588119cb93704793d57c08e0c2bc3079634b048e6f339677ed7750ca656b3976ef002e94b1bbf0394c47e0314dbccc71d9b9c6a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake-terraform-wrapper (0.1.0)
4
+ rake-terraform-wrapper (0.3.0)
5
5
  mixlib-shellout (~> 3.1)
6
6
  os (~> 1.1)
7
7
  rake (~> 13.0)
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- chef-utils (16.5.64)
13
+ chef-utils (16.6.14)
14
14
  coderay (1.1.3)
15
15
  diff-lcs (1.4.4)
16
16
  ffi (1.13.1)
data/README.md CHANGED
@@ -23,10 +23,29 @@ Or install it yourself as:
23
23
  ```ruby
24
24
  require 'rake-terraform-wrapper'
25
25
 
26
+ # specify the following optional config
27
+ Ruby::Terraform.config do |c|
28
+ c.binary = "/path/to/terraform" # or `terraform.exe` on windows
29
+
30
+ # if you prefer that the binary is downloaded automatically, specify the version of the terraform binary
31
+ c.terraform_version = '13.0' #Default version
32
+
33
+ # optionally, specifiy the location where you want the terraform zip file to be downloaded
34
+ c.download_path = "~/.terraform-bin/#{terraform_version}" #default path
35
+ end
36
+
37
+ # to force download, if not specified, terraform will be downloaded automatically on first usage
38
+ task :download_terraform do
39
+ executable = Ruby::Terraform::Executable.new
40
+ executable.download({verbose: true})
41
+ executable.extract
42
+ end
43
+
26
44
  namespace :network do
27
45
  Ruby::Terraform::Tasks::AllTasks.new(:network) do |tf|
28
46
  tf.dir = File.absolute_path("infra/network")
29
47
  tf.backend = 's3'
48
+ tf.build_dir = 'tmp' # optional. This will copy everything in the `tf.dir` into `build_dir` and execute terraform from this directory
30
49
  tf.backend_config = {
31
50
  bucket: 'some-bucket',
32
51
  key: 'network.tfstate',
@@ -3,10 +3,22 @@ module Ruby
3
3
  class Configuration
4
4
  attr_accessor :terraform_version
5
5
  attr_accessor :download_path
6
+ attr_accessor :binary
6
7
 
7
8
  def initialize(opts = {})
8
9
  @terraform_version = opts[:terraform_version] || Ruby::Terraform::TERRAFORM_VERSION
9
10
  @download_path = opts[:download_path] || File.expand_path("~/.terraform-bin/#{terraform_version}")
11
+ @binary = opts[:terraform_binary]
12
+ end
13
+
14
+ def binary
15
+ if @binary
16
+ @binary
17
+ elsif OS.windows?
18
+ "#{@download_path}/terraform.exe"
19
+ else
20
+ "#{@download_path}/terraform"
21
+ end
10
22
  end
11
23
  end
12
24
  end
@@ -7,6 +7,8 @@ module Ruby
7
7
 
8
8
  def config
9
9
  @config ||= Configuration.new
10
+ yield @config if block_given?
11
+ @config
10
12
  end
11
13
 
12
14
  class Executable
@@ -15,19 +17,15 @@ module Ruby
15
17
  def initialize(config = Ruby::Terraform.config)
16
18
  @terraform_version = config.terraform_version
17
19
  @download_path = config.download_path
20
+ @binary = config.binary
18
21
  @download_filename = "#{@terraform_version}-terraform.zip"
19
-
20
22
  FileUtils.mkdir_p(@download_path)
21
23
 
22
24
  raise PlatformUnsupported unless supported?
23
25
  end
24
26
 
25
27
  def binary
26
- if OS.windows?
27
- "#{@download_path}/terraform.exe"
28
- else
29
- "#{@download_path}/terraform"
30
- end
28
+ @binary
31
29
  end
32
30
 
33
31
  def download(opts = {})
@@ -18,7 +18,9 @@ module Ruby
18
18
  formatter = proc do |severity, datetime, progname, msg|
19
19
  "#{msg}\n"
20
20
  end
21
- shellout_opts[:logger] = Logger.new(STDERR, formatter: formatter)
21
+ logger = Logger.new(STDERR, formatter: formatter)
22
+ shellout_opts[:logger] = logger
23
+ logger.info("Running command inside directory: #{shellout_opts[:cwd]}") if shellout_opts[:cwd]
22
24
  end
23
25
 
24
26
  cmd = Mixlib::ShellOut.new(command, shellout_opts)
@@ -12,9 +12,21 @@ module Ruby
12
12
 
13
13
  attr_accessor :json
14
14
 
15
+ attr_accessor :build_dir
16
+
15
17
  def define
16
- InitTask.new(configuration_name, :init) do |task|
17
- task.dir = dir
18
+ dir_to_use = File.expand_path(build_dir ? "#{build_dir}/#{dir}" : dir)
19
+
20
+ if build_dir
21
+ task :pre_init do
22
+ rm_rf dir_to_use
23
+ mkdir_p File.dirname(dir_to_use) # create parent dir
24
+ cp_r dir, dir_to_use
25
+ end
26
+ end
27
+
28
+ InitTask.new(configuration_name, :init => build_dir ? [:pre_init] : []) do |task|
29
+ task.dir = dir_to_use
18
30
  task.backend = backend
19
31
  task.backend_config = backend_config
20
32
  task.show_output = show_output
@@ -22,7 +34,7 @@ module Ruby
22
34
  end
23
35
 
24
36
  ApplyTask.new(configuration_name, :apply => :init) do |task|
25
- task.dir = dir
37
+ task.dir = dir_to_use
26
38
  task.state = state
27
39
  task.vars = vars
28
40
  task.auto_approve = auto_approve
@@ -31,7 +43,7 @@ module Ruby
31
43
  end
32
44
 
33
45
  DestroyTask.new(configuration_name, :destroy => :init) do |task|
34
- task.dir = dir
46
+ task.dir = dir_to_use
35
47
  task.state = state
36
48
  task.vars = vars
37
49
  task.auto_approve = auto_approve
@@ -40,7 +52,7 @@ module Ruby
40
52
  end
41
53
 
42
54
  OutputTask.new(configuration_name, :output => :init) do |task|
43
- task.dir = dir
55
+ task.dir = dir_to_use
44
56
  task.state = state
45
57
  task.json = json
46
58
  task.show_output = show_output
@@ -48,7 +60,7 @@ module Ruby
48
60
  end
49
61
 
50
62
  PlanTask.new(configuration_name, :plan => :init) do |task|
51
- task.dir = dir
63
+ task.dir = dir_to_use
52
64
  task.state = state
53
65
  task.vars = vars
54
66
  task.show_output = show_output
@@ -56,7 +68,7 @@ module Ruby
56
68
  end
57
69
 
58
70
  ValidateTask.new(configuration_name, :validate => :init) do |task|
59
- task.dir = dir
71
+ task.dir = dir_to_use
60
72
  task.json = json
61
73
  task.show_output = show_output
62
74
  task.show_command = show_command
@@ -1,6 +1,6 @@
1
1
  module Ruby
2
2
  module Terraform
3
- VERSION = "0.1.0".freeze
3
+ VERSION = "0.3.0".freeze
4
4
  TERRAFORM_VERSION = '0.13.3'.freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake-terraform-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby Terraform
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-21 00:00:00.000000000 Z
11
+ date: 2020-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout