terraspace 2.2.8 → 2.2.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5477cf33cd5e864e5b7117cdc129d4aaa96a9f6ff9255093e9499180e67068f8
4
- data.tar.gz: 3dc0b9113b44f7e0d10019aeb22898b8045f8de0be3c60a756d9bda588847184
3
+ metadata.gz: 868708d6fa642b4d3d594202aeadff28af0e2ec106628a0e7853f83b0ad27824
4
+ data.tar.gz: b03c9dff474ed98d929a54ef85598df335870c1e668aa39004ebada3e7115cfc
5
5
  SHA512:
6
- metadata.gz: 15da8006c07825c64446444c58e2efa4c22baeeda85da0abcf5d2d54e16e35e9929c6a636885a969fc12a9918ff74df90b34f88147141f0bc53c170061be0964
7
- data.tar.gz: 499ebbabe6e904e6d3800c7d18b8b830c1130aee5faf07a317159d63e63eeeb96bf9483416efcf59a9d8753f5b0f09648b1595da56591751ce389d6d7710c3d7
6
+ metadata.gz: 66d7030cc8995f2524f651bc5d0a8e3a3a42cbbde5c14e869f5f49b7a86dfb157c2ba7f6d81f3515f1a151252f62edc9f206b66303b3d30eb0d76d683dd4ee28
7
+ data.tar.gz: '0910ebbc15e648c59682af6b014e73a3e54f54daac34c5975bebf4878f3751f43f9f3085b04e9aa6810307f69b290fe14d970b69295f4b54452795ffd43db7f4'
data/CHANGELOG.md CHANGED
@@ -3,6 +3,13 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [2.2.10] - 2023-08-23
7
+ - [#324](https://github.com/boltops-tools/terraspace/pull/324) terraspace check
8
+
9
+ ## [2.2.9] - 2023-08-23
10
+ - [#323](https://github.com/boltops-tools/terraspace/pull/323) Restrict terraform version due to terraform BSL license change
11
+ - send terraform version to all terraspace cloud requests
12
+
6
13
  ## [2.2.8] - 2023-06-27
7
14
  - Fix exit status for fmt
8
15
 
@@ -23,7 +23,7 @@ module Terraspace
23
23
 
24
24
  def run
25
25
  return if @options[:build] == false
26
- Terraspace::CLI::Setup::Check.check!
26
+ Terraspace::Check.check!
27
27
  check_allow!
28
28
  @mod.root_module = true
29
29
  clean
@@ -0,0 +1,142 @@
1
+ module Terraspace
2
+ class Check
3
+ extend Memoist
4
+
5
+ attr_reader :min_terraform_version, :max_terraform_version
6
+ def initialize(options={})
7
+ @options = options
8
+ # Terraspace requires this terraform version or a fork
9
+ @min_terraform_version = "0.12"
10
+ @max_terraform_version = "1.5.5"
11
+ end
12
+
13
+ # Used for the CLI
14
+ def run
15
+ puts "terraspace version: #{Terraspace::VERSION}"
16
+ if terraform_bin
17
+ puts "#{terraform_bin_name} bin: #{terraform_bin}"
18
+ puts "#{terraform_bin_name} version: #{terraform_version}"
19
+ # check for allowed version of terraform
20
+ if allowed_terraform_version?
21
+ puts "You're all set!".color(:green)
22
+ else
23
+ puts "terraspace requires terraform between v#{@min_terraform_version}.x and #{@max_terraform_version}".color(:red)
24
+ puts <<~EOL
25
+ This is because newer versions of terraform has a BSL license
26
+ If your usage is allowed by the license, you can bypass this check with:
27
+
28
+ export TS_VERSION_CHECK=0
29
+
30
+ Note: If you're using Terraspace Cloud, you won't be able to bypass this check.
31
+ See: https://terraspace.cloud/docs/terraform/license/
32
+ EOL
33
+ exit 1
34
+ end
35
+ else
36
+ puts terraform_is_not_installed
37
+ exit 1
38
+ end
39
+ end
40
+ alias ok! run
41
+
42
+ # aliased with ok?
43
+ def allowed_terraform_version?
44
+ return true if ENV['TS_VERSION_CHECK'] == '0' && Terraspace.cloud?
45
+ return false unless terraform_bin
46
+ return true if !terraform_bin.include?("terraform") # IE: allow any version of terraform forks
47
+
48
+ major, minor, patch = terraform_version.split('.').map(&:to_i)
49
+ min_major, min_minor, _ = @min_terraform_version.split('.').map(&:to_i)
50
+ max_major, max_minor, max_patch = @max_terraform_version.split('.').map(&:to_i)
51
+
52
+ # must be between min and max
53
+ min_ok = major > min_major ||
54
+ (major == min_major && minor >= min_minor)
55
+ max_ok = major < max_major ||
56
+ (major == max_major && minor == max_minor && patch <= max_patch)
57
+
58
+ min_ok && max_ok
59
+ end
60
+ alias ok? allowed_terraform_version?
61
+
62
+ def terraform_is_not_installed
63
+ <<~EOL
64
+ Terraform not installed. Unable to detect a terraform command.
65
+ Please double check that an allowed version of terraform is installed.
66
+ See: https://terraspace.cloud/docs/install/terraform/
67
+ EOL
68
+ end
69
+
70
+ # Note opentf is not an official fork yet. Mocked it out for testing.
71
+ # Should be ready to swap out the official fork name when it is ready.
72
+ BINS = %w[opentf terraform]
73
+ @@terraform_bin = nil
74
+ def terraform_bin
75
+ return @@terraform_bin if @@terraform_bin.present?
76
+ BINS.each do |bin|
77
+ if Gem.win_platform?
78
+ out = "is #{bin}.exe".strip
79
+ else
80
+ out = `type #{bin} 2>&1`.strip
81
+ next unless $?.success?
82
+ end
83
+ md = out.match(/is (.*)/)
84
+ if md
85
+ @@terraform_bin = md[1]
86
+ break
87
+ end
88
+ end
89
+ @@terraform_bin
90
+ end
91
+ memoize :terraform_bin
92
+
93
+ def terraform_bin_name
94
+ terraform_bin ? File.basename(terraform_bin) : "terraform"
95
+ end
96
+
97
+ # Sometimes Terraform shows the version info on the first line and sometimes on the bottom line.
98
+ # Account for that by finding the line.
99
+ #
100
+ # $ terraform --version
101
+ # Terraform v0.12.24
102
+ #
103
+ # Your version of Terraform is out of date! The latest version
104
+ # is 0.12.26. You can update by downloading from https://www.terraform.io/downloads.html
105
+ #
106
+ # Another example
107
+ #
108
+ # $ opentf --version
109
+ # OpenTF v0.12.24
110
+ #
111
+ # Note: The -json option is only available in v0.13+
112
+ def terraform_version
113
+ out = `#{terraform_bin} --version`
114
+ regexp = /(\d+\.\d+\.\d+)/
115
+ line = out.split("\n").find { |l| l =~ regexp }
116
+ version = line.match(regexp)[1] if line
117
+ end
118
+ memoize :terraform_version
119
+
120
+ def terraspace_version
121
+ Terraspace::VERSION
122
+ end
123
+
124
+ def versions
125
+ {
126
+ terraspace_version: terraspace_version,
127
+ terraform_version: terraform_version,
128
+ terraform_command: terraform_bin_name,
129
+ }
130
+ end
131
+
132
+ class << self
133
+ # Used as library call
134
+ def check!
135
+ setup = new
136
+ return if setup.ok?
137
+ # run meth designed for CLI and will puts out informative messages about installed version and exit 1 when version is not ok
138
+ setup.run
139
+ end
140
+ end
141
+ end
142
+ end
@@ -32,7 +32,7 @@ class Terraspace::CLI::Fmt
32
32
  end
33
33
 
34
34
  def terraform_fmt
35
- sh "terraform fmt"
35
+ sh "#{Terraspace.terraform_bin} fmt"
36
36
  end
37
37
 
38
38
  def sh(command)
@@ -3,7 +3,13 @@ class Terraspace::CLI
3
3
  desc "check", "Check setup is ok"
4
4
  long_desc Help.text("setup/check")
5
5
  def check
6
- Check.new(options).run
6
+ puts <<~EOL
7
+ DEPRECATED: The terraspace setup check command is deprecated. Instead use:
8
+
9
+ terraspace check
10
+
11
+ EOL
12
+ Terraspace::Check.new(options).run
7
13
  end
8
14
  end
9
15
  end
@@ -66,16 +66,22 @@ module Terraspace
66
66
  Bundle.new(options.merge(args: args)).run
67
67
  end
68
68
 
69
+ desc "check", "Check setup.", hide: true
70
+ long_desc Help.text(:check_setup)
71
+ def check
72
+ Check.new(options).run
73
+ end
74
+
69
75
  desc "check_setup", "Check setup.", hide: true
70
76
  long_desc Help.text(:check_setup)
71
77
  def check_setup
72
78
  puts <<~EOL
73
79
  DEPRECATED: The terraspace check_setup command is deprecated. Instead use:
74
80
 
75
- terraspace setup check
81
+ terraspace check
76
82
 
77
83
  EOL
78
- Setup::Check.new(options).run
84
+ Check.new(options).run
79
85
  end
80
86
 
81
87
  desc "console STACK", "Run console in built terraform project."
@@ -7,6 +7,11 @@ class Terraspace::Cloud::Api
7
7
  def request(klass, path, data={})
8
8
  exit_on_error = data.delete(:exit_on_error) # for cani logic
9
9
  url = url(path)
10
+ unless check.ok?
11
+ puts "ERROR: terraspace cloud requires terraform between v#{check.min_terraform_version}.x and #{check.max_terraform_version}".color(:red)
12
+ exit 1
13
+ end
14
+ data = data.merge(versions: check.versions)
10
15
  req = build_request(klass, url, data)
11
16
  retries = 0
12
17
  begin
@@ -117,5 +122,10 @@ class Terraspace::Cloud::Api
117
122
  def delete(path, data={})
118
123
  request(Net::HTTP::Delete, path, data)
119
124
  end
125
+
126
+ def check
127
+ Terraspace::Check.new
128
+ end
129
+ memoize :check
120
130
  end
121
131
  end
@@ -1,5 +1,6 @@
1
1
  module Terraspace::Cloud
2
2
  class Api
3
+ extend Memoist
3
4
  include Context
4
5
  include HttpMethods
5
6
 
@@ -18,8 +18,6 @@ module Terraspace::Cloud
18
18
  attrs = {
19
19
  status: status,
20
20
  kind: @kind,
21
- terraspace_version: check.terraspace_version,
22
- terraform_version: check.terraform_version,
23
21
  }
24
22
  attrs.merge!(@vcs_vars)
25
23
  attrs
@@ -38,11 +36,6 @@ module Terraspace::Cloud
38
36
  end
39
37
  end
40
38
 
41
- def check
42
- Terraspace::CLI::Setup::Check.new
43
- end
44
- memoize :check
45
-
46
39
  def sh(command, exit_on_fail: true)
47
40
  logger.debug "=> #{command}"
48
41
  system command
@@ -26,8 +26,6 @@ module Terraspace::Cloud
26
26
  {
27
27
  provider: provider.name, # IE: infracost
28
28
  provider_version: provider.version,
29
- terraspace_version: check.terraspace_version,
30
- terraform_version: check.terraform_version,
31
29
  }
32
30
  end
33
31
 
@@ -53,7 +53,7 @@ module Terraspace::Cloud
53
53
  FileUtils.cp(out_option_root_path, plan_path)
54
54
 
55
55
  json = plan_path.sub('.binary','.json')
56
- sh "terraform show -json #{plan_path} > #{json}"
56
+ sh "#{Terraspace.terraform_bin} show -json #{plan_path} > #{json}"
57
57
  end
58
58
  end
59
59
 
@@ -24,8 +24,8 @@ module Terraspace::Cloud
24
24
  IO.write("#{cache2_path}/update.log", Terraspace::Logger.logs)
25
25
  return unless success
26
26
 
27
- sh "terraform state pull > #{cache2_path}/state.json"
28
- sh "terraform output -json > #{cache2_path}/output.json"
27
+ sh "#{Terraspace.terraform_bin} state pull > #{cache2_path}/state.json"
28
+ sh "#{Terraspace.terraform_bin} output -json > #{cache2_path}/output.json"
29
29
  end
30
30
  end
31
31
 
@@ -2,6 +2,11 @@ module Terraspace
2
2
  module Core
3
3
  extend Memoist
4
4
 
5
+ def terraform_bin
6
+ # basename so command shows up as a prettier short name in the output
7
+ File.basename(Terraspace::Check.new.terraform_bin)
8
+ end
9
+
5
10
  def app
6
11
  ENV['TS_APP'] unless ENV['TS_APP'].blank?
7
12
  end
@@ -45,7 +45,7 @@ module Terraspace::Terraform
45
45
  current_dir_message # only show once
46
46
 
47
47
  params = args.flatten.join(' ')
48
- command = "terraform #{name} #{params}".squish
48
+ command = "#{Terraspace.terraform_bin} #{name} #{params}".squish
49
49
  @shell_exception = nil
50
50
  run_hooks("terraform.rb", name) do
51
51
  Backend.new(@mod).create
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "2.2.8"
2
+ VERSION = "2.2.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.8
4
+ version: 2.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-27 00:00:00.000000000 Z
11
+ date: 2023-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -528,6 +528,7 @@ files:
528
528
  - lib/terraspace/builder/allow/stack.rb
529
529
  - lib/terraspace/builder/children.rb
530
530
  - lib/terraspace/bundle.rb
531
+ - lib/terraspace/check.rb
531
532
  - lib/terraspace/cli.rb
532
533
  - lib/terraspace/cli/all.rb
533
534
  - lib/terraspace/cli/base.rb
@@ -636,7 +637,6 @@ files:
636
637
  - lib/terraspace/cli/plan.rb
637
638
  - lib/terraspace/cli/seed.rb
638
639
  - lib/terraspace/cli/setup.rb
639
- - lib/terraspace/cli/setup/check.rb
640
640
  - lib/terraspace/cli/state.rb
641
641
  - lib/terraspace/cli/summary.rb
642
642
  - lib/terraspace/cli/test.rb
@@ -965,7 +965,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
965
965
  - !ruby/object:Gem::Version
966
966
  version: '0'
967
967
  requirements: []
968
- rubygems_version: 3.4.10
968
+ rubygems_version: 3.4.17
969
969
  signing_key:
970
970
  specification_version: 4
971
971
  summary: 'Terraspace: The Terraspace Framework'
@@ -1,114 +0,0 @@
1
- class Terraspace::CLI::Setup
2
- class Check
3
- extend Memoist
4
-
5
- # Terraspace requires at least this version of terraform
6
- REQUIRED_TERRAFORM_VERSION = "0.12"
7
-
8
- def initialize(options={})
9
- @options = options
10
- end
11
-
12
- # Used for the CLI
13
- def run
14
- puts "Detected Terraspace version: #{Terraspace::VERSION}"
15
- if terraform_bin
16
- puts "Detected Terraform bin: #{terraform_bin}"
17
- puts "Detected #{terraform_version_message}"
18
- check_required_version!
19
- else
20
- puts terraform_is_not_installed
21
- exit 1
22
- end
23
- end
24
-
25
- def check_required_version!
26
- puts "Terraspace requires Terraform v#{REQUIRED_TERRAFORM_VERSION}.x and above"
27
- if ok?
28
- puts "You're all set!"
29
- else
30
- puts "The installed version of terraform may not work with terraspace."
31
- puts "Recommend using at least terraform v#{REQUIRED_TERRAFORM_VERSION}.x"
32
- puts "If you would like to bypass this check. Use TS_VERSION_CHECK=0" unless check_command?
33
- exit 1 unless ENV['TS_VERSION_CHECK'] == '0'
34
- end
35
- end
36
-
37
- def check_command?
38
- Terraspace.argv[0] == "check_setup"
39
- end
40
-
41
- def terraform_is_not_installed
42
- <<~EOL
43
- Terraform not installed. Unable to detect a terraform command. Please double check that terraform is installed.
44
- See: https://terraspace.cloud/docs/install/terraform/
45
- EOL
46
- end
47
-
48
- def ok?
49
- unless terraform_bin
50
- puts terraform_is_not_installed
51
- exit 1
52
- end
53
-
54
- version = terraform_version_message.sub(/.*v/,'') # => 0.12.24
55
- unless version.match(/\d+\.\d+\.\d+/) # just parse did not find the version number
56
- puts "WARN: Unable to get the terraform version".color(:yellow)
57
- return true
58
- end
59
- major, minor, _ = version.split('.')
60
- required_major, required_minor = REQUIRED_TERRAFORM_VERSION.split('.')
61
- return true if major.to_i > required_major.to_i
62
- x = major.to_i >= required_major.to_i
63
- y = minor.to_i >= required_minor.to_i
64
- x && y
65
- end
66
-
67
- def terraform_bin
68
- if Gem.win_platform?
69
- out = "is terraform.exe".strip
70
- else
71
- out = `type terraform 2>&1`.strip
72
- return unless $?.success?
73
- end
74
- md = out.match(/is (.*)/)
75
- md[1] if md
76
- end
77
- memoize :terraform_bin
78
-
79
- # Sometimes Terraform shows the version info on the first line and sometimes on the bottom line.
80
- # Account for that by finding the line.
81
- #
82
- # $ terraform --version
83
- # Terraform v0.12.24
84
- #
85
- # Your version of Terraform is out of date! The latest version
86
- # is 0.12.26. You can update by downloading from https://www.terraform.io/downloads.html
87
- #
88
- # Note: The -json option is only available in v0.13+
89
- def terraform_version_message
90
- out = `terraform --version`
91
- version = out.split("\n").find { |l| l =~ /^Terraform / }
92
- version.strip if version
93
- end
94
- memoize :terraform_version_message
95
-
96
- def terraform_version
97
- terraform_version_message.sub(/.*v/,'')
98
- end
99
-
100
- def terraspace_version
101
- Terraspace::VERSION
102
- end
103
-
104
- class << self
105
- # Used as library call
106
- def check!
107
- setup = new
108
- return if setup.ok?
109
- # run meth designed for CLI and will puts out informative messages about installed version and exit 1 when version is not ok
110
- setup.run
111
- end
112
- end
113
- end
114
- end