automaticly get terraform version

This commit is contained in:
yupwei 2020-03-23 15:14:10 +08:00
Родитель bddad9ca69
Коммит ff118e1cce
2 изменённых файлов: 20 добавлений и 11 удалений

Просмотреть файл

@ -1,16 +1,23 @@
require 'colorize'
require 'fileutils'
# To use Terraform 0.12 syntax, set ENV variable TERRAFORM_VERSION to 0.12.*
def get_version_tf
message = `terraform -version`
mlist = message.split(" ")
if mlist.size>2
return mlist[1]
else
raise "ERROR: Get Terraform Version failed!\n#{message}\n".red
end
end
def lint_tf
# Do the linting on current working folder.
print "INFO: Linting Terraform configurations...\n".yellow
if ENV['TERRAFORM_VERSION'].nil? || ENV['TERRAFORM_VERSION'].start_with?("0.11.")
tf_version = get_version_tf
if tf_version.start_with?("v0.11.")
message = `terraform validate -check-variables=false 2>&1`
elsif ENV['TERRAFORM_VERSION'].start_with?("0.12.")
elsif tf_version.start_with?("v0.12.")
success = system ("terraform init")
if not success
raise "ERROR: terraform init failed!\n".red
@ -29,9 +36,10 @@ end
def style_tf
# Do the style checking on current working folder.
print "INFO: Styling Terraform configurations...\n".yellow
if ENV['TERRAFORM_VERSION'].nil? || ENV['TERRAFORM_VERSION'].start_with?("0.11.")
tf_version = get_version_tf
if tf_version.start_with?("v0.11.")
message = `terraform fmt -check=true 2>&1`
elsif ENV['TERRAFORM_VERSION'].start_with?("0.12.")
elsif tf_version.start_with?("v0.12.")
message = `terraform fmt -check 2>&1`
end
@ -46,9 +54,10 @@ end
def format_tf
# Apply the canonical format and style on current working folder.
print "INFO: Formatting Terraform configurations...\n".yellow
if ENV['TERRAFORM_VERSION'].nil? || ENV['TERRAFORM_VERSION'].start_with?("0.11.")
tf_version = get_version_tf
if tf_version.start_with?("v0.11.")
message = `terraform fmt -diff=true 2>&1`
elsif ENV['TERRAFORM_VERSION'].start_with?("0.12.")
elsif tf_version.start_with?("v0.12.")
message = `terraform fmt -diff 2>&1`
end

Просмотреть файл

@ -1,4 +1,4 @@
version = "0.4.0"
version = "0.5.0"
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY