jal*_*aix 7 gitlab gitlab-ci terraform
我使用 Gitlab CI/CD 通过 Terraform 来配置基础设施。我目前有一个 3 阶段管道(init、plan、apply),非常适合手动应用作业。计划作业与应用作业共享计划工件。
有时计划是空的(没有资源可以更改),但申请工作仍然是强制性的。您知道如何避免在计划为空时运行应用作业吗?或者当计划为空时自动(而不是手动)运行应用作业?
最简单的实现方法是-detailed-exitcode在 Terraform 计划步骤中使用。根据 Terraform 文档:
-detailed-exitcode Return detailed exit codes when the command exits. This
will change the meaning of exit codes to:
0 - Succeeded, diff is empty (no changes)
1 - Errored
2 - Succeeded, there is a diff
Run Code Online (Sandbox Code Playgroud)
例如,在终端中运行该计划:
terraform plan -detailed-exitcode
Run Code Online (Sandbox Code Playgroud)
然后在你的终端中运行:
echo $?
Run Code Online (Sandbox Code Playgroud)
如果计划包含任何更改,您的价值将不会为零。您只需使用 If 语句评估 CI/CD 中的该值即可决定是否要运行 apply 。
| 归档时间: |
|
| 查看次数: |
2268 次 |
| 最近记录: |