Method: TFWrapper::RakeTasks#check_tf_version
- Defined in:
- lib/tfwrapper/raketasks.rb
#check_tf_version ⇒ Object
Check that the terraform version is compatible
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/tfwrapper/raketasks.rb', line 428 def check_tf_version # run: terraform -version all_out_err, exit_status = TFWrapper::Helpers.run_cmd_stream_output( 'terraform version', @tf_dir ) unless exit_status.zero? raise StandardError, "ERROR: 'terraform -version' exited " \ "#{exit_status}: #{all_out_err}" end all_out_err = all_out_err.strip # Find the terraform version string m = /Terraform v(\d+\.\d+\.\d+).*/.match(all_out_err) unless m raise StandardError, 'ERROR: could not determine terraform version ' \ "from 'terraform -version' output: #{all_out_err}" end # the version will be a string like: # Terraform v0.9.2 # or: # Terraform v0.9.3-dev (<GIT SHA><+CHANGES>) tf_ver = Gem::Version.new(m[1]) unless tf_ver >= min_tf_version raise StandardError, "ERROR: tfwrapper #{TFWrapper::VERSION} is only " \ "compatible with Terraform >= #{min_tf_version} but your terraform " \ "binary reports itself as #{m[1]} (#{all_out_err})" end puts "Running with: #{all_out_err}" tf_ver end |