Terraform 提供以下退出代碼:
0 = Succeeded with empty diff (no changes)
1 = Error
2 = Succeeded with non-empty diff (changes present)
terraform apply僅當需要添加任何新資源或需要應用任何更改時,我才需要執行。
if [ $? -eq 0 ]; then
echo "No changes, not applying"
elif [ $? -eq 1 ]; then
echo "Terraform plan failed"
exit 1
elif [ $? -eq 2 ]; then
echo "Terraform apply needed"
fi
但是我得到了退出代碼0,即使是一個terraform plan輸出命令:
Plan: 9 to add, 0 to change, 0 to destroy.
問題是什么?
uj5u.com熱心網友回復:
對于terraform plan回傳的退出代碼,你必須提供-detailed-exitcode的詳細說明中選擇檔案。
-detailed-exitcode - 當命令退出時回傳詳細的退出代碼。
這應該是您的terraform plan命令的樣子,否則0無論輸出如何,您都會得到退出代碼:
terraform plan -detailed-exitcode ...
uj5u.com熱心網友回復:
誠實的問題,與其檢查 是否plan已更改,然后再運行 a terraform apply,為什么不能運行以下內容:
terraform apply --auto-approve
因此,無論狀態是否發生變化,terraform 都會運行apply,如果需要添加或洗掉任何資源,它都會起作用。
(對不起,我想把它作為評論發送,但我沒有足夠的積分)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/315322.html
