1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-04 17:47:00 +03:00

M #-: add Terraform debug log messages (#1013)

This commit is contained in:
Alejandro Huertas Herrero 2021-03-23 12:58:43 +01:00 committed by GitHub
parent bf61c17457
commit 9c411e2c85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 2 deletions

View File

@ -211,6 +211,17 @@ module CLIHelper
end
end
# Get text in green colour
#
# @param text [String] String to print
def self.green(text)
if $stdout.tty?
ANSI_GREEN + text + ANSI_RESET
else
state
end
end
# Print header
#
# @param str [String] String with header content

View File

@ -129,9 +129,11 @@ CommandParser::CmdParser.new(ARGV) do
STDERR.puts rc.message
exit(-1)
elsif rc.to_i < 0
puts CLIHelper.green('Provision successfully created')
puts "ID: #{rc}"
rc
else
puts CLIHelper.green('Provision successfully created')
puts "ID: #{rc}"
0
end

View File

@ -98,6 +98,15 @@ module OneProvision
instance.logger.warn(msg)
end
# Gets Terraform log level
def self.tf_log
if instance.logger.level == 0
'DEBUG'
else
'INFO'
end
end
end
# Singleton running mode

View File

@ -147,7 +147,9 @@ module OneProvision
# Apply
Driver.retry_loop("Driver action 'tf deploy' failed", provision) do
_, e, s = Driver.run(
"cd #{tempdir}; terraform apply -auto-approve"
"cd #{tempdir}; " \
"export TF_LOG=#{OneProvisionLogger.tf_log}; " \
'terraform apply -auto-approve'
)
unless s && s.success?
@ -224,7 +226,9 @@ module OneProvision
# Destroy
Driver.retry_loop("Driver action 'tf destroy' failed", provision) do
_, e, s = Driver.run(
"cd #{tempdir}; terraform refresh; " \
"cd #{tempdir}; " \
"export TF_LOG=#{OneProvisionLogger.tf_log}; " \
'terraform refresh; ' \
"terraform destroy #{target} -auto-approve"
)