belt 0.3.26 → 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 +4 -4
- data/lib/belt/cli/dns_command.rb +102 -0
- data/lib/belt/cli.rb +1 -0
- data/lib/belt/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d392dbd28d642a7f18a3087e8640ef1382b5da70199804a77232b99f365a6822
|
|
4
|
+
data.tar.gz: 791f51d17d764ada25f3ce6395a141d02f3b1474556df4299067b78726b1db3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc6051c477ad262a13029781cb3a12a8df262a8d3a94d9a5f8a98b3adcb379d8c4f0d761244144cac8c69a37abbf7d3a5eba88fb3b7a7f2ba21a1cc41e77e196
|
|
7
|
+
data.tar.gz: b6470146bd1920c26462f8b37279eda6c35a92f5a184e37e2171d1015e2d694ac7e5b6b07b2a34cc7bd40f1af8464d891ae4f75d9808c8ee0af956e618aa494e
|
data/lib/belt/cli/dns_command.rb
CHANGED
|
@@ -25,6 +25,8 @@ module Belt
|
|
|
25
25
|
new.generate(args)
|
|
26
26
|
when 'add'
|
|
27
27
|
new.add_environment(args)
|
|
28
|
+
when 'show', 'list'
|
|
29
|
+
new.show(args)
|
|
28
30
|
when '--help', '-h', 'help'
|
|
29
31
|
puts help
|
|
30
32
|
else
|
|
@@ -41,6 +43,7 @@ module Belt
|
|
|
41
43
|
deploy Deploy the dns infrastructure (init → plan → apply)
|
|
42
44
|
generate Create the infrastructure/dns directory (same as belt generate dns)
|
|
43
45
|
add <env> Add an environment's NS records to dns/terraform.tfvars
|
|
46
|
+
show Show root zone name servers (for registrar configuration)
|
|
44
47
|
help Show this help
|
|
45
48
|
|
|
46
49
|
Options for generate:
|
|
@@ -52,6 +55,7 @@ module Belt
|
|
|
52
55
|
belt dns generate # Scaffold infrastructure/dns (prompts for profile)
|
|
53
56
|
belt dns generate --aws-profile fpshared # Non-interactive with profile
|
|
54
57
|
belt dns add staging # Add staging's NS records to tfvars
|
|
58
|
+
belt dns show # Show root name servers to configure at registrar
|
|
55
59
|
|
|
56
60
|
The dns directory manages your root domain and delegates subdomains to
|
|
57
61
|
per-environment hosted zones. Each environment (dev, staging, prod) gets
|
|
@@ -204,6 +208,94 @@ module Belt
|
|
|
204
208
|
puts "\nRun 'belt dns deploy' to apply the changes."
|
|
205
209
|
end
|
|
206
210
|
|
|
211
|
+
# --- Show ---
|
|
212
|
+
def show(_args)
|
|
213
|
+
require 'open3'
|
|
214
|
+
|
|
215
|
+
unless Dir.exist?(DNS_DIR)
|
|
216
|
+
puts 'No infrastructure/dns directory found.'
|
|
217
|
+
puts "\nCreate it first:"
|
|
218
|
+
puts ' belt dns generate'
|
|
219
|
+
exit 1
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
env_config = load_dns_config
|
|
223
|
+
env = {}
|
|
224
|
+
env['AWS_PROFILE'] = env_config.aws_profile if env_config.aws_profile?
|
|
225
|
+
|
|
226
|
+
# Get all outputs in one call
|
|
227
|
+
outputs = Dir.chdir(DNS_DIR) do
|
|
228
|
+
output, status = Open3.capture2e(env, 'terraform', 'output', '-json')
|
|
229
|
+
unless status.success?
|
|
230
|
+
puts 'Failed to read terraform outputs.'
|
|
231
|
+
puts "\nMake sure DNS is deployed:"
|
|
232
|
+
puts ' belt dns deploy'
|
|
233
|
+
exit 1
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
begin
|
|
237
|
+
JSON.parse(output)
|
|
238
|
+
rescue JSON::ParserError
|
|
239
|
+
puts 'Failed to parse terraform outputs.'
|
|
240
|
+
exit 1
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# Extract values from terraform state
|
|
245
|
+
name_servers = outputs.dig('root_name_servers', 'value') || []
|
|
246
|
+
zone_id = outputs.dig('root_zone_id', 'value')
|
|
247
|
+
environments = outputs.dig('delegated_environments', 'value') || []
|
|
248
|
+
|
|
249
|
+
# Read domain from tfvars
|
|
250
|
+
tfvars_path = "#{DNS_DIR}/terraform.tfvars"
|
|
251
|
+
domain = nil
|
|
252
|
+
if File.exist?(tfvars_path)
|
|
253
|
+
content = File.read(tfvars_path)
|
|
254
|
+
match = content.match(/domain\s*=\s*"([^"]+)"/)
|
|
255
|
+
domain = match[1] if match
|
|
256
|
+
end
|
|
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
|
+
|
|
278
|
+
# Display
|
|
279
|
+
puts 'Root Zone Name Servers'
|
|
280
|
+
puts '======================'
|
|
281
|
+
puts ''
|
|
282
|
+
puts "Domain: #{domain}" if domain
|
|
283
|
+
puts "Zone ID: #{zone_id}" if zone_id
|
|
284
|
+
puts ''
|
|
285
|
+
puts 'Configure these at your domain registrar:'
|
|
286
|
+
puts ''
|
|
287
|
+
name_servers.each { |ns| puts " #{ns}" }
|
|
288
|
+
puts ''
|
|
289
|
+
|
|
290
|
+
if environments.any?
|
|
291
|
+
puts "Delegated environments: #{environments.join(', ')}"
|
|
292
|
+
else
|
|
293
|
+
puts 'No environments delegated yet.'
|
|
294
|
+
puts "\nTo add an environment:"
|
|
295
|
+
puts ' belt dns add <env>'
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
|
|
207
299
|
private
|
|
208
300
|
|
|
209
301
|
def templates
|
|
@@ -377,6 +469,16 @@ module Belt
|
|
|
377
469
|
_, status = Open3.capture2e(*cmd)
|
|
378
470
|
status.success?
|
|
379
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
|
|
380
482
|
end
|
|
381
483
|
end
|
|
382
484
|
end
|
data/lib/belt/cli.rb
CHANGED
|
@@ -116,6 +116,7 @@ module Belt
|
|
|
116
116
|
deploy frontend <env> [--frontend NAME] Build and deploy frontend(s) to AWS
|
|
117
117
|
dns deploy Deploy root DNS zone (init → plan → apply)
|
|
118
118
|
dns add <env> Add environment NS records to dns/terraform.tfvars
|
|
119
|
+
dns show Show root zone name servers for registrar
|
|
119
120
|
frontend env <env> [--frontend NAME] Write <frontend>/.env from terraform outputs
|
|
120
121
|
frontend list List configured frontends
|
|
121
122
|
routes [-g PATTERN] [-f json] Show route definitions
|
data/lib/belt/version.rb
CHANGED