wdi_tf 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: fb3e856034e61e9147c43c6bd641ca9a13829ac7
4
- data.tar.gz: 9f3aa90a750926a3b11da2419ad4d9ace71307ea
3
+ metadata.gz: 3b643dd4f299853cd8f802fd08a04464ed5f925e
4
+ data.tar.gz: 8726fca6bb0b7ba1040518ad7f300f9007a4a537
5
5
  SHA512:
6
- metadata.gz: 80cce084c46ef46ed3ba0a59a6cd8e46e2f79667048ac1ab6c06e21f802cdc81c9ee0b978af2e4ecd571af9c3afb16b5d0bb6d2fbb6b2ab7120f7949ddc365ca
7
- data.tar.gz: 340ed07f572b731de753d034f15ee8a949ca16aae6961d1b46ae1479527889d000d36e7e7894c929e0fc98c464cdb411d85613093d6adaaa235cee548ea3dd91
6
+ metadata.gz: 085449d1484b833f287ade7a3179c149278da1528969bb0754c822e6419eb3a95fad36e928ec3854451e4ca58af8f029d71d240e5fdc888833f612f926f500f7
7
+ data.tar.gz: 4b68c769667f743f34c1654c0d4cacf58da66950003eb82b2b1af8eff259b327afdf1853ca23b89fd0db589dfdb284dc5c1df06033927a8797502e7efeea2149
data/lib/wdi_tf/cli.rb CHANGED
@@ -9,8 +9,9 @@ module WdiTf
9
9
  module Cli
10
10
  module_function
11
11
 
12
- @@project_file = 'Terraform.tfproj'
12
+ @@project_file = 'Terraform.tfproj'
13
13
  @@variables_file = 'Terraform.tfvars'
14
+ @@allowed_cmds = ['clean', 'plan', 'apply', 'destroy']
14
15
 
15
16
  def load_opts(args: ARGV)
16
17
  Trollop.options(args) do
@@ -19,6 +20,14 @@ module WdiTf
19
20
 
20
21
  Usage:
21
22
  tf [options] COMMAND
23
+
24
+ Commands:
25
+ clean - cleans the workspace and returns it back to the original state.
26
+ plan - runs 'terraform plan' on the workspace. (default)
27
+ apply - runs 'terraform apply' on the workspace.
28
+ destroy - runs 'teraform destroy' on the workspace.
29
+
30
+ Options:
22
31
  EOS
23
32
 
24
33
  opt :debug, 'Puts the wrapper into debug mode', type: TrueClass, default: nil
@@ -34,6 +43,10 @@ module WdiTf
34
43
  cmd = ARGV.shift
35
44
  cmd ||= "plan"
36
45
 
46
+ if not @@allowed_cmds.include?(cmd)
47
+ error(msg: "Unknown command '#{ cmd }'. Accepted commands: #{ @@allowed_cmds.join(', ') }")
48
+ end
49
+
37
50
  return cmd
38
51
  end
39
52
 
data/lib/wdi_tf/main.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'open3'
1
2
  require 'wdi_tf/main'
2
3
 
3
4
  module WdiTf
@@ -40,13 +41,32 @@ module WdiTf
40
41
  def run_terraform(command:, variables:)
41
42
  info("Running Terraform command.")
42
43
 
43
- cmd = "terraform #{ command }"
44
+ cmd = "terraform init && terraform #{ command }"
44
45
 
45
46
  if File.exists?(variables)
46
47
  cmd = "#{ cmd } -var-file=#{ variables }"
47
48
  end
48
49
 
50
+ if command == 'apply'
51
+ cmd = "#{ cmd } -auto-approve"
52
+ end
53
+
54
+ if command == 'destroy'
55
+ cmd = "#{ cmd } -force"
56
+ end
57
+
49
58
  info(" #{ cmd }")
59
+ Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
60
+ while line = stdout_err.gets
61
+ puts line
62
+ end
63
+
64
+ exit_status = wait_thr.value
65
+
66
+ unless exit_status.success?
67
+ abort "FAILED !!! #{cmd}"
68
+ end
69
+ end
50
70
  end
51
71
  end
52
72
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module WdiTf
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
data/wdi_tf.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Anthony Kirby"]
10
10
  spec.email = 'anthony.kirby@winedirect.com'
11
11
 
12
- spec.description = "Terraform wrapper"
12
+ spec.description = "Terraform wrapper to simply working with TF by introducing Terraform projects."
13
13
  spec.summary = spec.description
14
14
  spec.homepage = 'http://rubygems.org/gems/wdi_tf'
15
15
  spec.license = 'Apache-2.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wdi_tf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Kirby
@@ -52,7 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.4'
55
- description: Terraform wrapper
55
+ description: Terraform wrapper to simply working with TF by introducing Terraform
56
+ projects.
56
57
  email: anthony.kirby@winedirect.com
57
58
  executables:
58
59
  - wdi-tf
@@ -91,5 +92,5 @@ rubyforge_project:
91
92
  rubygems_version: 2.6.12
92
93
  signing_key:
93
94
  specification_version: 4
94
- summary: Terraform wrapper
95
+ summary: Terraform wrapper to simply working with TF by introducing Terraform projects.
95
96
  test_files: []