gpt4 book ai didi

automation - 在 terraform 中使用工作空间时如何更改本地后端状态的路径?

转载 作者:行者123 更新时间:2023-12-03 08:54:57 25 4
gpt4 key购买 nike

使用 terraform 的预期配置是什么 workspaceslocal backend

本地后端支持工作空间,但您似乎对实际状态的存储位置没有太多控制权。

当您不使用工作区时,您可以向本地后端提供 path 参数来控制状态文件的存储位置。

# Either in main.tf
terraform {
backend "local" {
path = "/path/to/terraform.tfstate
}
}

# Or as a flag
terraform init -backend-config="path=/path/to/terraform.tfstate"

我期望使用工作区时具有类似的功能,因为您将为 path 提供一个目录,并且工作区将在该目录下创建

例如:

terraform new workspace first
terraform init -backend-config="path=/path/to/terraform.tfstate.d"
terraform apply
terraform new workspace second
terraform init -backend-config="path=/path/to/terraform.tfstate.d"
terraform apply

会导致状态

/path/to/terraform.tfstate.d/first/terraform.tfstate
/path/to/terraform.tfstate.d/second/terraform.tfstate

然而,情况似乎并非如此。看来本地后端忽略了路径参数,并将工作区配置放在工作目录中。

我是否遗漏了什么或者您无法控制本地后端工作区状态?

最佳答案

本地后端 workspace_dir 有一个未记录的标志可以解决此问题。

文档任务已跟踪 here

terraform {
backend "local" {
workspace_dir = "/path/to/terraform.tfstate.d"
}
}

关于automation - 在 terraform 中使用工作空间时如何更改本地后端状态的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56259141/

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