belt 0.3.27 → 0.3.28

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: 19b006b12335ff6d66a4834d47b1a2d69e29b1f6d82c81d17cb842cf8cd3b929
4
- data.tar.gz: b0c23c9f91bfac292603928ad63bdc28ac75fc0d9f306a5c32d2a57abaa0cf0a
3
+ metadata.gz: d392dbd28d642a7f18a3087e8640ef1382b5da70199804a77232b99f365a6822
4
+ data.tar.gz: 791f51d17d764ada25f3ce6395a141d02f3b1474556df4299067b78726b1db3c
5
5
  SHA512:
6
- metadata.gz: 30db85ef7c77debdc5ec7bc66977afb4dc2f5f72c0b61e43e3d3ad17d579fd3e7af7591e885be419e55819c0c8fc05ba5970095827c5b51bf889f9c3553372ec
7
- data.tar.gz: e46501282fc782535992b185f87014e6b27c6f5e5a5eb5572cb91e713a362cedd5209674436f535af03834d7fe3b8feafd47e5a533b6eb3d36c23c5bfa31ce6b
6
+ metadata.gz: bc6051c477ad262a13029781cb3a12a8df262a8d3a94d9a5f8a98b3adcb379d8c4f0d761244144cac8c69a37abbf7d3a5eba88fb3b7a7f2ba21a1cc41e77e196
7
+ data.tar.gz: b6470146bd1920c26462f8b37279eda6c35a92f5a184e37e2171d1015e2d694ac7e5b6b07b2a34cc7bd40f1af8464d891ae4f75d9808c8ee0af956e618aa494e
@@ -241,18 +241,11 @@ module Belt
241
241
  end
242
242
  end
243
243
 
244
- # Extract values
244
+ # Extract values from terraform state
245
245
  name_servers = outputs.dig('root_name_servers', 'value') || []
246
246
  zone_id = outputs.dig('root_zone_id', 'value')
247
247
  environments = outputs.dig('delegated_environments', 'value') || []
248
248
 
249
- if name_servers.empty?
250
- puts 'No name servers found. Is the DNS zone deployed?'
251
- puts "\nRun:"
252
- puts ' belt dns deploy'
253
- exit 1
254
- end
255
-
256
249
  # Read domain from tfvars
257
250
  tfvars_path = "#{DNS_DIR}/terraform.tfvars"
258
251
  domain = nil
@@ -262,6 +255,26 @@ module Belt
262
255
  domain = match[1] if match
263
256
  end
264
257
 
258
+ # Verify the zone actually exists in AWS (terraform state can be stale)
259
+ if zone_id && !zone_exists_in_aws?(zone_id, env)
260
+ puts 'Root Zone Not Found'
261
+ puts '==================='
262
+ puts ''
263
+ puts "Terraform state references zone #{zone_id}, but it doesn't exist in AWS."
264
+ puts 'The zone may have been deleted or the state is stale.'
265
+ puts ''
266
+ puts 'To create the root zone:'
267
+ puts ' belt dns deploy'
268
+ exit 1
269
+ end
270
+
271
+ if name_servers.empty?
272
+ puts 'No name servers found. Is the DNS zone deployed?'
273
+ puts "\nRun:"
274
+ puts ' belt dns deploy'
275
+ exit 1
276
+ end
277
+
265
278
  # Display
266
279
  puts 'Root Zone Name Servers'
267
280
  puts '======================'
@@ -456,6 +469,16 @@ module Belt
456
469
  _, status = Open3.capture2e(*cmd)
457
470
  status.success?
458
471
  end
472
+
473
+ # Verify a Route 53 hosted zone exists in AWS.
474
+ # env is a hash with optional AWS_PROFILE for the aws CLI.
475
+ def zone_exists_in_aws?(zone_id, env = {})
476
+ require 'open3'
477
+ cmd = ['aws', 'route53', 'get-hosted-zone', '--id', zone_id]
478
+ cmd += ['--profile', env['AWS_PROFILE']] if env['AWS_PROFILE']
479
+ _, status = Open3.capture2e(*cmd)
480
+ status.success?
481
+ end
459
482
  end
460
483
  end
461
484
  end
data/lib/belt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Belt
4
- VERSION = '0.3.27'
4
+ VERSION = '0.3.28'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.27
4
+ version: 0.3.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla