guard-terraform 1.0.0 → 1.0.1

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: ca3ea8a74f9eff42a135900b1365b7ef91ad4d8ab8a8860bb67478e7518be6e2
4
- data.tar.gz: a31ec380ad1a26eae1e58a068aa9b9ca36bf65c6f14ab34808cab3bc1ccd9317
3
+ metadata.gz: 42c6614a4b4d8c9de19825c6e3959c392f4edb8f2641e48658873db3642bb3a4
4
+ data.tar.gz: 57595bd4449cbcf06851508175c80217bd7d91ad490726df0af08890385f9ccc
5
5
  SHA512:
6
- metadata.gz: fc02153c09113c7b6c7d6b45c8ad94b3cb2bba8e551ec7178bbcd6f62125ea667e950949735b505c0b9a83d8120ee03a7f56c485490b4d2a91de982fc0b598bb
7
- data.tar.gz: 39c791ea2b260282696c1c6495f00df39cf322a8ccf57c89702096e44c53290e755c7e06de003f7bd1148c95a5c2b4a597c6022d903d9608004c1ccf28b1e13f
6
+ metadata.gz: 2e324f81d68630ff90790c0cccf1bd5cd894f3fb6de1194fbd9828358d2b21ca21e01347ee8a460a372e85d58166f3890a53df3c5f1ad67e5531307554e9eb59
7
+ data.tar.gz: d1dc22204bf90613e249ad37c3a0d90f5696ead97b7f5d5a95a8b0804d28c656a355eef214b3e731638244d1fc25ad03e3bcfcc59a41149b618d912f8b412ec2
@@ -3,6 +3,6 @@
3
3
  module Guard
4
4
  # Use own namespace to avoid inheriting from `Guard::Plugin`
5
5
  module TerraformVersion
6
- VERSION = '1.0.0'
6
+ VERSION = '1.0.1'
7
7
  end
8
8
  end
@@ -18,7 +18,8 @@ module Guard
18
18
  write: false, # fix the formatting instead of just verifying?
19
19
  }.freeze
20
20
 
21
- attr_reader :options, :terraform, :tf_flags
21
+ attr_reader :options
22
+ attr_reader :terraform, :tf_flags
22
23
 
23
24
  def initialize(**options)
24
25
  super
@@ -49,13 +50,19 @@ module Guard
49
50
  end
50
51
 
51
52
  def run_all
53
+ paths = ['.']
54
+ extra_flags = {}
55
+
52
56
  if terraform.pre_0_12?
53
57
  # Terraform v<0.12 does not check *.tfvars by default,
54
- # so collect them to the list, too
55
- run(all_tf_files)
58
+ # so find and check them separately
59
+ paths += terraform.find_tfvars_files
56
60
  else
57
- run('.', recursive: true)
61
+ # Terraform 0.12+ does not check recursively by default
62
+ extra_flags[:recursive] = true
58
63
  end
64
+
65
+ run(paths, extra_flags)
59
66
  end
60
67
 
61
68
  def run_on_modifications(paths)
@@ -65,10 +72,11 @@ module Guard
65
72
  alias run_on_additions run_on_modifications
66
73
 
67
74
  def run(paths, **extra_flags)
75
+ print_pre_run_message(paths)
76
+
68
77
  flags = tf_flags.merge(extra_flags)
69
78
 
70
- result = terraform.fmt(paths, flags) do |path, cmd|
71
- UI.info("#{flags[:write] ? 'Enforcing' : 'Inspecting'} Terraform formatting: #{path}")
79
+ result = terraform.fmt(paths, flags) do |_, cmd|
72
80
  UI.debug(Shellwords.join(cmd))
73
81
  end
74
82
 
@@ -78,6 +86,21 @@ module Guard
78
86
  throw(:task_has_failed)
79
87
  end
80
88
 
89
+ def print_pre_run_message(paths)
90
+ @msg_format ||= "#{options[:write] ? 'Enforcing' : 'Inspecting'} " \
91
+ 'Terraform formatting for %s'
92
+
93
+ target = if paths.count > 1
94
+ "#{paths.count} files or dirs"
95
+ elsif paths.first == '.'
96
+ 'the whole project'
97
+ else
98
+ paths.first
99
+ end
100
+
101
+ UI.info(format(@msg_format, target))
102
+ end
103
+
81
104
  def notify_failure
82
105
  Notifier.notify(
83
106
  'Terraform format check failed',
@@ -86,11 +109,6 @@ module Guard
86
109
  )
87
110
  end
88
111
 
89
- # Returns list of all Terraform files
90
- def all_tf_files
91
- Dir['**/*.{tf,tfvars}']
92
- end
93
-
94
112
  # Terraform 0.12+ only supports checking directories,
95
113
  # older versions accept also files
96
114
  def mungle_paths(paths)
data/lib/terraform.rb CHANGED
@@ -31,6 +31,14 @@ class Terraform
31
31
  VersionRequirement.new('< 0.12.0-alpha').satisfied_by?(version)
32
32
  end
33
33
 
34
+ # Finds all *.tfvars files recursively in the given directory,
35
+ # or current working directory if not specified.
36
+ def find_tfvars_files(dir = nil, &block)
37
+ dir = "#{dir}/" if dir && !dir.empty? && dir[-1] != '/'
38
+
39
+ Dir.glob("#{dir}**/*.tfvars", &block)
40
+ end
41
+
34
42
  # Returns `Array` of CLI flags for Terraform
35
43
  # E.g. `{ foo: true, bar: 'baz' }` -> `[ '-foo=true', '-bar=baz' ]`
36
44
  def cli_flags(**flags)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-terraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Teemu Matilainen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard