terraform_landscape 0.1.10 → 0.1.11

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: cf360fe1ed1556c181a434de199f8d8e339773ed
4
- data.tar.gz: 515377583effa0f3c924d4b4e080ab54c569ca11
3
+ metadata.gz: e6de58a2bcb0f3d318ce203f19adeb2d54493b52
4
+ data.tar.gz: 55845cf9aa9e8653de8fc6944aa031d21be3f7bf
5
5
  SHA512:
6
- metadata.gz: 760a0f9f7ec82bdb8020accb56f59b70262222984a088bc8f4e33614479c1802954877c158488c755717af0f4a54c7455d13e8b843e9e15fd1b4b6c93d20316e
7
- data.tar.gz: 00d0f78fd2f0d2ba6db1d6899c1ba122a711508281e8357d73cb4b72b6b8b62faac97bea9bc4deedd0a04662d74656c4ce59bc9a015a3daae083c41539f5a358
6
+ metadata.gz: da0a63b397506b8e79b11a4ff9c83242f2abf7293baa283ebe02dc660cb777b1e25c88169d7d759b880cf356d5e7bfa9a4cc65be3211e2ae529cfa49975af7aa
7
+ data.tar.gz: 40a468725bfb87c9d5b81dda6370d809b34db3f61fc57a312f19adac3d990685bdc830cd8e72db355a94ec7c683ecf430789c06a4df0c566735dd16195457a87
@@ -77,7 +77,27 @@ grammar TerraformPlan
77
77
  rule attribute
78
78
  attribute_name:[^:]* ':' _? attribute_value:[^\n]+ {
79
79
  def to_ast
80
- { attribute_name.text_value => attribute_value.text_value }
80
+ { attribute_name.text_value => sanitize_value_and_reason }
81
+ end
82
+
83
+ def sanitize_value_and_reason
84
+ val = attribute_value.text_value
85
+
86
+ # We'll perform some sanitization of the values within the parser.
87
+
88
+ # Handle case where attribute has an annotation (e.g. "forces new resource")
89
+ if (match = val.match(/\s+\((?<reason>[^)]+)\)$/))
90
+ reason = match['reason']
91
+ val = val[0...match.begin(0)]
92
+ end
93
+
94
+ # With Terraform >= 0.10.4, the <computed> field is now without quotes,
95
+ # which will cause problem with how downstream we process the output.
96
+ # Convert it to have quotes and handle < 0.10.4 as well.
97
+ val = val.gsub(%r{=> <computed>$}, '=> "<computed>"')
98
+ .gsub(%r{^<computed>}, '"<computed>"')
99
+
100
+ { value: val, reason: reason }
81
101
  end
82
102
  }
83
103
  end
@@ -41,6 +41,8 @@ module TerraformLandscape
41
41
  # Remove preface
42
42
  if (match = scrubbed_output.match(/^Path:[^\n]+/))
43
43
  scrubbed_output = scrubbed_output[match.end(0)..-1]
44
+ elsif (match = scrubbed_output.match(/^Terraform.+following\sactions:/))
45
+ scrubbed_output = scrubbed_output[match.end(0)..-1]
44
46
  elsif (match = scrubbed_output.match(/^\s*(~|\+|\-)/))
45
47
  scrubbed_output = scrubbed_output[match.begin(0)..-1]
46
48
  elsif scrubbed_output =~ /^No changes/
@@ -76,11 +76,14 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
76
76
  # Determine longest attribute name so we align all values at same indentation
77
77
  attribute_value_indent_amount = attribute_indent_amount_for_resource(resource)
78
78
 
79
- resource[:attributes].each do |attribute_name, attribute_value|
79
+ resource[:attributes].each do |attribute_name, attribute_value_and_reason|
80
+ attribute_value = attribute_value_and_reason[:value]
81
+ attribute_change_reason = attribute_value_and_reason[:reason]
80
82
  display_attribute(resource,
81
83
  change_color,
82
84
  attribute_name,
83
85
  attribute_value,
86
+ attribute_change_reason,
84
87
  attribute_value_indent_amount)
85
88
  end
86
89
  end
@@ -122,6 +125,7 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
122
125
  change_color,
123
126
  attribute_name,
124
127
  attribute_value,
128
+ attribute_change_reason,
125
129
  attribute_value_indent_amount
126
130
  )
127
131
  attribute_value_indent = ' ' * attribute_value_indent_amount
@@ -130,6 +134,7 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
130
134
  display_modified_attribute(change_color,
131
135
  attribute_name,
132
136
  attribute_value,
137
+ attribute_change_reason,
133
138
  attribute_value_indent,
134
139
  attribute_value_indent_amount)
135
140
  else
@@ -145,17 +150,10 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
145
150
  change_color,
146
151
  attribute_name,
147
152
  attribute_value,
153
+ attribute_change_reason,
148
154
  attribute_value_indent,
149
155
  attribute_value_indent_amount
150
156
  )
151
- # Handle case where attribute has an annotation (e.g. "forces new resource")
152
- # appended onto the end. This is hard to parse in the Treetop grammar, so we
153
- # instead catch it here and extract
154
- if (match = attribute_value.match(/\((?<reason>[^)]+)\)$/))
155
- reason = match['reason']
156
- attribute_value = attribute_value[0...match.begin(0)]
157
- end
158
-
159
157
  # Since the attribute line is always of the form
160
158
  # "old value" => "new value", we can add curly braces and parse with
161
159
  # `eval` to obtain a hash with a single key/value.
@@ -181,7 +179,7 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
181
179
  @out.print '"' + new.colorize(:green) + '"'
182
180
  end
183
181
 
184
- @out.print " (#{reason})".colorize(:magenta) if reason
182
+ @out.print " (#{attribute_change_reason})".colorize(:magenta) if attribute_change_reason
185
183
 
186
184
  @out.newline
187
185
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module TerraformLandscape
5
- VERSION = '0.1.10'.freeze
5
+ VERSION = '0.1.11'.freeze
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraform_landscape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coinbase
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-09-06 00:00:00.000000000 Z
12
+ date: 2017-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize