stax 0.0.9 → 0.0.10

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: 1637c27b601383577e3b2f002e93de68a1d030d13a083fafaf0ae29d325d4cc3
4
- data.tar.gz: 9d3d833071c1ef2c0ce92491e64aecbc39858dd44ffe225dc61d0e0adf487219
3
+ metadata.gz: 0c1fb0c4863d5f462054105ec15720e4b2055ec4656d703a2217a9bec0ea7957
4
+ data.tar.gz: 388679f36efeb35b963f7d0a89162282b82df717cd55d69e0100ceff8c0109c9
5
5
  SHA512:
6
- metadata.gz: e560c98cafefb0228b31e0613372f722ed2b129e804a1010eaa6557e35de3ed070f93eba1e3e15b8fe8b76d78fbf5e2d9ca6b1492925caed3721198030af3c5a
7
- data.tar.gz: c173d44f14e732458c6f677a24972b0eb88c8d8dc2f6189a397b598c8c46c3d09c0cd9bb68627bbab25c4f9888ef9c3587961a3c6cb1ee9bc9563c4d56a508d5
6
+ metadata.gz: 82b5a4b04a7880868e806fe561be31651efdb30127bba6a2ebd5aaaf9f9a3d314280d53098285853853107a2154d4140ab3fe84092a4e4399c45eae566939193
7
+ data.tar.gz: f31ff85970907378fed57b52c2daecb0f8b93b65cd2addec05ab0676530fd23e78af870ee35be916b34deff1ccf45b558f2799c7082376f4f2d2b46eaaa85032
@@ -17,6 +17,7 @@ require 'stax/stack/parameters'
17
17
  require 'stax/stack/outputs'
18
18
  require 'stax/stack/imports'
19
19
  require 'stax/stack/resources'
20
+ require 'stax/stack/drift'
20
21
 
21
22
  require 'stax/mixin/ec2'
22
23
  require 'stax/mixin/alb'
@@ -160,6 +160,18 @@ module Stax
160
160
  client.execute_change_set(opt)
161
161
  end
162
162
 
163
+ def detect_drift(opt)
164
+ client.detect_stack_drift(opt).stack_drift_detection_id
165
+ end
166
+
167
+ def drift_status(id)
168
+ client.describe_stack_drift_detection_status(stack_drift_detection_id: id)
169
+ end
170
+
171
+ def drifts(opt)
172
+ client.describe_stack_resource_drifts(opt).map(&:stack_resource_drifts).flatten
173
+ end
174
+
163
175
  end
164
176
 
165
177
  end
@@ -0,0 +1,56 @@
1
+ module Stax
2
+ class Stack < Base
3
+ COLORS = {
4
+ IN_SYNC: :green,
5
+ MODIFIED: :red,
6
+ DELETED: :red,
7
+ ADD: :green,
8
+ REMOVE: :red,
9
+ }
10
+
11
+ no_commands do
12
+ ## start a drift detection job and wait for it to complete
13
+ def run_drift_detection
14
+ debug("Running drift detection for #{stack_name}")
15
+ id = Aws::Cfn.detect_drift(stack_name: stack_name)
16
+ puts "waiting for #{id}"
17
+ loop do
18
+ sleep(1)
19
+ break unless Aws::Cfn.drift_status(id).detection_status == 'DETECTION_IN_PROGRESS'
20
+ end
21
+ end
22
+
23
+ ## show the latest drift status for each resource
24
+ def show_drifts
25
+ debug("Resource drift status for #{stack_name}")
26
+ Aws::Cfn.drifts(stack_name: stack_name).tap do |drifts|
27
+ print_table drifts.map { |d|
28
+ [d.logical_resource_id, d.resource_type, color(d.stack_resource_drift_status, COLORS), d.timestamp]
29
+ }
30
+ end
31
+ end
32
+
33
+ ## show drift diffs for out of sync resources
34
+ def show_drifts_details(drifts)
35
+ drifts.select{ |d| d.stack_resource_drift_status == 'MODIFIED' }.each do |r|
36
+ debug("Property differences for #{r.logical_resource_id}")
37
+ r.property_differences.each do |p|
38
+ puts(
39
+ p.property_path + ' ' + color(p.difference_type, COLORS),
40
+ ' ' + set_color('-' + p.expected_value, :red),
41
+ ' ' + set_color('+' + p.actual_value, :green)
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ desc 'drifts', 'stack drifts'
49
+ def drifts
50
+ run_drift_detection
51
+ drifts = show_drifts
52
+ show_drifts_details(drifts)
53
+ end
54
+
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module Stax
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-20 00:00:00.000000000 Z
11
+ date: 2018-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -241,6 +241,7 @@ files:
241
241
  - lib/stax/stack/cfn.rb
242
242
  - lib/stax/stack/changeset.rb
243
243
  - lib/stax/stack/crud.rb
244
+ - lib/stax/stack/drift.rb
244
245
  - lib/stax/stack/imports.rb
245
246
  - lib/stax/stack/outputs.rb
246
247
  - lib/stax/stack/parameters.rb