belt 0.3.21 → 0.3.23

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: e913248aec69e4989d916f23eca445762abbdd0f3e1aa46b71bda1de8accbb68
4
- data.tar.gz: 9865a153a7f77ffbdedccf3e0250d205fab538f57a853723d043f51d9eacd162
3
+ metadata.gz: 1e5abc1ab2820331aaad684f79c2b43cd5f5d99d0c38abbbd38e4dcd1efe0aad
4
+ data.tar.gz: 315d3cf0a8209683598ba624e5a5017b26d764b0e1e88ab654cdaa7eedfe7ab9
5
5
  SHA512:
6
- metadata.gz: 8bab207b1d5c59d7ededcfe54a106b971cfe9d2ce8538b339bc68206aeeb241893369c62664d92f675c6717476e747740c4b69103e5f84ec32332efa717f139b
7
- data.tar.gz: f6ec883e69585c5e5f2ac8bbea321b1e33f751a43f5d615c638066a9c330f98ba9a03ef29c624714eae619f3ac3e7472b33d6add7850e43a2c1dea6084035fd9
6
+ metadata.gz: 2a0254ea0e2b6de26b6cf3e65caee76db2df44a714a492edfeef0490e2644fa6bdf2a38c6150e09c71d94d389f699d60fcfd0235be8a44f4da25bc28a0cfba17
7
+ data.tar.gz: 7310bc92ea3749017da52f6be928288b3970c5e52a828d948796f44e75a2ff628652db767227622f4e371889c37a7387d2aca02a844fae32c108b95448a4a603
@@ -21,7 +21,7 @@ module Belt
21
21
  when 'deploy', nil
22
22
  new.deploy(args)
23
23
  when 'generate', 'init'
24
- new.generate
24
+ new.generate(args)
25
25
  when 'add'
26
26
  new.add_environment(args)
27
27
  when '--help', '-h', 'help'
@@ -42,9 +42,14 @@ module Belt
42
42
  add <env> Add an environment's NS records to dns/terraform.tfvars
43
43
  help Show this help
44
44
 
45
+ Options for generate:
46
+ --aws-profile NAME AWS profile to use for DNS infrastructure
47
+ Sets belt.rb config and derives state bucket from account ID
48
+
45
49
  Examples:
46
50
  belt dns deploy # Deploy the root zone
47
- belt dns generate # Scaffold infrastructure/dns
51
+ belt dns generate # Scaffold infrastructure/dns (prompts for profile)
52
+ belt dns generate --aws-profile fpshared # Non-interactive with profile
48
53
  belt dns add staging # Add staging's NS records to tfvars
49
54
 
50
55
  The dns directory manages your root domain and delegates subdomains to
@@ -60,14 +65,23 @@ module Belt
60
65
  HELP
61
66
  end
62
67
 
63
- def initialize(quiet: false)
68
+ def initialize(quiet: false, aws_profile: nil)
64
69
  @app_name = detect_app_name
65
70
  @quiet = quiet
66
- @state_bucket = resolve_state_bucket
71
+ @aws_profile = aws_profile
72
+ @state_bucket = nil # Resolved during generate with profile context
67
73
  end
68
74
 
69
75
  # --- Generate ---
70
- def generate
76
+ def generate(args = [])
77
+ # Parse --aws-profile flag
78
+ profile_index = args.index('--aws-profile')
79
+ if profile_index
80
+ @aws_profile = args[profile_index + 1]
81
+ args.delete_at(profile_index + 1)
82
+ args.delete_at(profile_index)
83
+ end
84
+
71
85
  if Dir.exist?(DNS_DIR)
72
86
  puts "dns infrastructure already exists at #{DNS_DIR}/"
73
87
  puts "\nTo configure it:"
@@ -76,7 +90,21 @@ module Belt
76
90
  exit 1
77
91
  end
78
92
 
93
+ # Prompt for AWS profile if not provided and not quiet mode
94
+ if @aws_profile.nil? && !@quiet && $stdin.tty?
95
+ print 'AWS profile for DNS infrastructure (leave blank to use current credentials): '
96
+ input = $stdin.gets&.strip
97
+ @aws_profile = input unless input.nil? || input.empty?
98
+ end
99
+
100
+ # Resolve state bucket using the specified profile (or current credentials)
101
+ @state_bucket = resolve_state_bucket_for_profile(@aws_profile)
102
+
79
103
  puts 'Creating dns infrastructure...' unless @quiet
104
+ if @aws_profile && !@quiet
105
+ puts " Using AWS profile: #{@aws_profile}"
106
+ puts " State bucket: #{@state_bucket}"
107
+ end
80
108
  FileUtils.mkdir_p(DNS_DIR)
81
109
 
82
110
  templates.each do |template_name, dest_file|
@@ -192,19 +220,19 @@ module Belt
192
220
  end
193
221
 
194
222
  def load_dns_config
195
- belt_rb = File.join(DNS_DIR, 'belt.rb')
196
- return {} unless File.exist?(belt_rb)
197
-
198
- EnvironmentConfig.load(belt_rb)
223
+ # Load config from infrastructure/dns/belt.rb
224
+ # EnvironmentConfig.load expects (env_name, infra_dir:) where the path
225
+ # is infra_dir/env_name/belt.rb. We pass 'dns' as env_name.
226
+ EnvironmentConfig.load('dns')
199
227
  end
200
228
 
201
229
  def run_terraform(action, env_config, *extra_args)
202
230
  cmd = ['terraform', action] + extra_args
203
231
  env = {}
204
232
 
205
- if env_config[:aws_profile]
206
- env['AWS_PROFILE'] = env_config[:aws_profile]
207
- puts "Using AWS profile: #{env_config[:aws_profile]}" if action == 'init'
233
+ if env_config.aws_profile?
234
+ env['AWS_PROFILE'] = env_config.aws_profile
235
+ puts "Using AWS profile: #{env_config.aws_profile}" if action == 'init'
208
236
  end
209
237
 
210
238
  system(env, *cmd) || begin
@@ -281,6 +309,13 @@ module Belt
281
309
  bucket_from_sibling || bucket_from_aws || 'belt-terraform-state'
282
310
  end
283
311
 
312
+ # Resolve state bucket for a specific AWS profile.
313
+ # If profile is provided, uses that profile's account ID.
314
+ # Otherwise falls back to existing sibling backend.tf or current credentials.
315
+ def resolve_state_bucket_for_profile(profile)
316
+ bucket_from_sibling || bucket_from_aws_profile(profile) || 'belt-terraform-state'
317
+ end
318
+
284
319
  def bucket_from_sibling
285
320
  Dir.glob('infrastructure/*/backend.tf').each do |f|
286
321
  match = File.read(f).match(/bucket\s*=\s*"([^"]+)"/)
@@ -292,8 +327,14 @@ module Belt
292
327
  end
293
328
 
294
329
  def bucket_from_aws
330
+ bucket_from_aws_profile(nil)
331
+ end
332
+
333
+ def bucket_from_aws_profile(profile)
295
334
  require 'open3'
296
- output, status = Open3.capture2e('aws', 'sts', 'get-caller-identity')
335
+ cmd = %w[aws sts get-caller-identity]
336
+ cmd += ['--profile', profile] if profile
337
+ output, status = Open3.capture2e(*cmd)
297
338
  return nil unless status.success?
298
339
 
299
340
  data = begin
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.21'
4
+ VERSION = '0.3.23'
5
5
  end
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Belt.configure do |config|
4
+ <% if @aws_profile -%>
5
+ # AWS profile for DNS infrastructure
6
+ config.aws_profile = "<%= @aws_profile %>"
7
+ <% else -%>
4
8
  # Set the AWS profile to use for DNS infrastructure.
5
9
  # This can be a shared account for cross-environment DNS management,
6
10
  # or the same profile as your environments for single-account setups.
@@ -12,4 +16,5 @@ Belt.configure do |config|
12
16
  # config.aws_profile = "myapp-dev"
13
17
  #
14
18
  # config.aws_profile = ""
19
+ <% end -%>
15
20
  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.21
4
+ version: 0.3.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla