terraspace 2.2.8 → 2.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/terraspace/builder.rb +1 -1
- data/lib/terraspace/check.rb +142 -0
- data/lib/terraspace/cli/fmt/runner.rb +1 -1
- data/lib/terraspace/cli/setup.rb +1 -1
- data/lib/terraspace/cli.rb +1 -1
- data/lib/terraspace/cloud/api/http_methods.rb +10 -0
- data/lib/terraspace/cloud/api.rb +1 -0
- data/lib/terraspace/cloud/base.rb +0 -7
- data/lib/terraspace/cloud/cost.rb +0 -2
- data/lib/terraspace/cloud/plan.rb +1 -1
- data/lib/terraspace/cloud/update.rb +2 -2
- data/lib/terraspace/core.rb +5 -0
- data/lib/terraspace/terraform/runner.rb +1 -1
- data/lib/terraspace/version.rb +1 -1
- metadata +4 -4
- data/lib/terraspace/cli/setup/check.rb +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ec502639ef9e51eaabc15f2446b607813740cde82fe190f1e5c011c6efe66af
|
4
|
+
data.tar.gz: 1a0190a3a0847b876a55e8db5bbeb16263977a06f20006fc5daccad4b3bd2ec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2285bf67d8d46f3e022e4603cb1c5bfedbb9a2da845b7472d02e6497b987e4dfc8335412a4495bda1139ea9b2395d2a505438b33ff44087a9e50504fb216086
|
7
|
+
data.tar.gz: 51c7376367e60d407f550d364f8786b0609da2115bae4c828c7611bbcf0f35db9e04fd5327593f6e5f02b2b8c381769b6e226659ca17e949901b6c97a23d35a0
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@
|
|
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.9] - 2023-08-23
|
7
|
+
- [#323](https://github.com/boltops-tools/terraspace/pull/323) Restrict terraform version due to terraform BSL license change
|
8
|
+
- send terraform version to all terraspace cloud requests
|
9
|
+
|
6
10
|
## [2.2.8] - 2023-06-27
|
7
11
|
- Fix exit status for fmt
|
8
12
|
|
data/lib/terraspace/builder.rb
CHANGED
@@ -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
|
data/lib/terraspace/cli/setup.rb
CHANGED
data/lib/terraspace/cli.rb
CHANGED
@@ -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
|
data/lib/terraspace/cloud/api.rb
CHANGED
@@ -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
|
@@ -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 "
|
28
|
-
sh "
|
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
|
|
data/lib/terraspace/core.rb
CHANGED
@@ -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 = "
|
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
|
data/lib/terraspace/version.rb
CHANGED
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.
|
4
|
+
version: 2.2.9
|
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-
|
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.
|
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
|