gpt4 book ai didi

terraform - 如何将 terraform 状态集成到 github 操作工作流中?

转载 作者:行者123 更新时间:2023-12-04 08:44:32 24 4
gpt4 key购买 nike

我有 github 操作工作流,其中概述了启动 terraform 以在 Azure 中创建资源的简单过程。我缺少的是如何集成 terraform 状态文件,以便在此工作流的顺序运行时,它应该将当前状态与 main.tf 文件进行比较,并且只允许净更改。目前如果我按顺序运行它,第二次总是会失败,因为资源已经在 Azure 中创建了。
我如何配置下面的 github 工作流以允许 terraform 状态文件比较?,我还没有找到这样做的单一来源
github 仓库布局:
enter image description here
github Action 工作流程:

name: Terraform deploy to Azur

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: "Checkout"
uses: actions/checkout@master

- name: "Terraform Init"
uses: hashicorp/terraform-github-actions@master
with:
tf_actions_version: 0.12.13
tf_actions_subcommand: "init"

- name: "Terraform Plan"
uses: hashicorp/terraform-github-actions@master
with:
tf_actions_version: 0.12.13
tf_actions_subcommand: "plan"
args: -var="client_secret=${{ secrets.clientSecret }}"
-var="client_id=${{ secrets.clientId }}"
-var="tenant_id=${{ secrets.tenantId }}"
-var="sub=${{ secrets.sub }}"

- name: "Terraform Apply"
uses: hashicorp/terraform-github-actions@master
with:
tf_actions_version: 0.12.13
tf_actions_subcommand: "apply"
args: -var="client_secret=${{ secrets.clientSecret }}"
-var="client_id=${{ secrets.clientId }}"
-var="tenant_id=${{ secrets.tenantId }}"
-var="sub=${{ secrets.sub }}"

最佳答案

您需要add a backend configuration到您的 Terraform,以便它将状态文件存储在外部某处,以便在每次运行时引用和更新。

关于terraform - 如何将 terraform 状态集成到 github 操作工作流中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64397938/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com