【问题标题】:Integrating the Terraform Plan output into Jenkins将 Terraform Plan 输出集成到 Jenkins
【发布时间】:2023-04-07 22:48:02
【问题描述】:

我在 repo 的根目录中使用 Jenkinsfile 编写了一个声明性管道。管道非常简单。它提供了一个terraform plan 和一个terraform apply

是否可以将terraform plan 的输出显示在 Jenkins GUI 中,然后询问用户是否愿意继续使用terraform apply?

【问题讨论】:

    标签: jenkins jenkins-pipeline terraform devops


    【解决方案1】:

    从未尝试过,但 Jenkins 确实有一个 input step 作为管道插件的一部分。

    此外,terraform 允许您 to store the output of a plan,然后在运行 terraform apply 时使用保存的输出。 -auto-approve flag 表示您可以跳过应用时用户输入的需要。

    我认为不可能在terraform apply中间要求用户输入,因为输入步骤是一个步骤。

    所以我认为管道必须如下所示:

    pipeline {
        agent { ... }
        stages {
            stage('build') {
                steps {
                    sh 'terraform plan -out=./my-plan'
                    input message: "Apply plan?"
                    sh 'terraform apply -auto-approve ./my-plan' 
                }
            }
        }
    }
    

    如果在计划和申请之间更改了基础架构,则会出现问题。

    【讨论】:

    • 如果基础架构在计划和应用之间发生变化,那么应用会在刷新之前安全失败(状态被锁定),这样应该没问题。
    • @theonlyra 给出的答案是正确的。我添加了以下链接,因为它提供了一个完整的解决方案,以防它对有相同问题的其他人有用:Terraform Pipeline using Jenkins
    猜你喜欢
    • 1970-01-01
    • 2019-05-13
    • 2021-08-29
    • 1970-01-01
    • 2021-05-24
    • 2021-07-22
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多