belt 0.4.7 → 0.4.8

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: 1f2da2bf0507f4f380a01130c184e6a2bb54103e21274d0aa589ae1dd1d546a7
4
- data.tar.gz: 1ad686dae1cf98301b286465beee62b5ae23e3d56541679e93110a9c7fa933ff
3
+ metadata.gz: 21aaed39c7b6868b8c6f370cbc97a686bf369f7d3fe7a03c56b850c1bc49fd62
4
+ data.tar.gz: 8825ef22ce89cee45435dcd1e7b405c954c9f630e90f569ee0d575de33db5b49
5
5
  SHA512:
6
- metadata.gz: 298cba520960d5ebe54cbc47623aa068ef22ab7888edd3535b77278ef5d71d5d28bd01e7ac02d984d03f4f9baa09b1ff932c87d665a00f218aba12c88be5ac83
7
- data.tar.gz: f5fe8ff182396627f1bdd2fd451f664d6bf1848959e7d869a7912709487035df8fd87cdae10ed983aec7181a82a9cd5fca9bb17af6f488bea5bfadcd8cd89c6e
6
+ metadata.gz: 9bdf007e3adcc59dd1e852f2d9563002416272ae4f954ce72231856bead07c261cc6bad6a86a8b6bbdbc6a2896b321eb717dcf5f70bda7e77cc2538ed67b2970
7
+ data.tar.gz: 95c20325ca7427776e6c08dbf9c6e2ad3a8dacb4293339bf24cb48dc74021a887dfd0152865a0cc295c311314047f605119e22ea8b293ba9e9dbb977a0a8c549
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.8
4
+
5
+ ### Added
6
+
7
+ - **`belt deploy` auto-bootstraps the ACM certificate on first deploy.** First-time
8
+ deploys hit the classic ACM chicken-and-egg problem: `terraform plan` fails because
9
+ `domain_validation_options` aren't known until the certificate is applied. Belt now
10
+ detects that error pattern, runs
11
+ `terraform apply -target=module.app.aws_acm_certificate.app` to create the certificate,
12
+ and re-runs the plan automatically. No manual terraform commands needed — first-time
13
+ deploys just work. This is a one-time bootstrap; subsequent deploys run normally since
14
+ the certificate already exists.
15
+
3
16
  ## 0.4.7
4
17
 
5
18
  ### Bug Fix
@@ -731,9 +731,87 @@ module Belt
731
731
 
732
732
  def run_plan
733
733
  puts '━━━ terraform plan ━━━'
734
- success = system('terraform', 'plan', '-out=tfplan', *@extra_args)
735
- abort "\n✗ terraform plan failed" unless success
734
+
735
+ stderr_buffer = run_terraform_plan
736
+ return if stderr_buffer.nil? # Success
737
+
738
+ # If ACM for_each error, auto-bootstrap and retry
739
+ return if acm_for_each_error?(stderr_buffer) && acm_bootstrap_succeeded?
740
+
741
+ abort "\n✗ terraform plan failed"
742
+ end
743
+
744
+ # Returns nil on success, stderr buffer on failure
745
+ def run_terraform_plan
746
+ require 'open3'
747
+ stderr_buffer = +''
748
+
749
+ Open3.popen3('terraform', 'plan', '-out=tfplan', *@extra_args) do |_stdin, stdout, stderr, wait_thr|
750
+ stdout_thread = Thread.new do
751
+ while (line = stdout.gets)
752
+ print line
753
+ end
754
+ end
755
+
756
+ stderr_thread = Thread.new do
757
+ while (line = stderr.gets)
758
+ stderr_buffer << line
759
+ $stderr.print line
760
+ end
761
+ end
762
+
763
+ stdout_thread.join
764
+ stderr_thread.join
765
+
766
+ return nil if wait_thr.value.success?
767
+ end
768
+
769
+ stderr_buffer
770
+ end
771
+
772
+ def acm_for_each_error?(output)
773
+ # Detect the ACM certificate for_each chicken-and-egg error
774
+ output.include?('for_each') &&
775
+ output.include?('domain_validation_options') &&
776
+ output.include?('cannot be determined until apply')
777
+ end
778
+
779
+ # Returns true if bootstrap succeeded and retry plan passed
780
+ def acm_bootstrap_succeeded?
781
+ puts ''
782
+ puts '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
783
+ puts ' ACM CERTIFICATE BOOTSTRAP'
784
+ puts '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
785
+ puts ''
786
+ puts ' First-time deploy detected. Terraform needs the ACM certificate'
787
+ puts ' to exist before it can create DNS validation records.'
788
+ puts ''
789
+ puts ' Creating certificate now...'
736
790
  puts ''
791
+
792
+ # Phase 1: Create the certificate only
793
+ success = system('terraform', 'apply', '-target=module.app.aws_acm_certificate.app', '-auto-approve')
794
+ unless success
795
+ puts ''
796
+ puts ' ✗ Certificate creation failed.'
797
+ return false
798
+ end
799
+
800
+ puts ''
801
+ puts ' ✓ Certificate created. Re-running plan...'
802
+ puts ''
803
+
804
+ # Phase 2: Retry the plan
805
+ stderr_buffer = run_terraform_plan
806
+ if stderr_buffer.nil?
807
+ puts ''
808
+ return true # Success!
809
+ end
810
+
811
+ # Still failing - something else is wrong
812
+ puts ''
813
+ puts ' ✗ Plan still failing after bootstrap. Check the errors above.'
814
+ false
737
815
  end
738
816
 
739
817
  def confirm_apply?
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.4.7'
4
+ VERSION = '0.4.8'
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.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla