【发布时间】:2021-04-17 01:34:29
【问题描述】:
我想将 terraform 状态文件推送到 github 存储库。 Terraform 中的文件功能无法读取 .tfstate 文件,因此我需要先将其扩展名更改为 .txt。现在为了自动化它,我创建了一个空资源,它有一个配置程序来运行命令以将 tfstate 文件复制为同一目录中的 txt 文件。我遇到了这个“depends_on”参数,它可以让你指定在运行当前资源之前是否需要先制作特定资源。但是,它不起作用,当文件功能需要它时,我立即收到“terraform.txt”文件不退出的错误。
provider "github" {
token = "TOKEN"
owner = "USERNAME"
}
resource "null_resource" "tfstate_to_txt" {
provisioner "local-exec" {
command = "copy terraform.tfstate terraform.txt"
}
}
resource "github_repository_file" "state_push" {
repository = "TerraformStates"
file = "terraform.tfstate"
content = file("terraform.txt")
depends_on = [null_resource.tfstate_to_txt]
}
【问题讨论】:
-
将状态文件添加到 git repo(希望不是公开的)不是一个好习惯。你能澄清你想达到什么目标吗?也许有更好的方法?
-
@Marcin 是的,这是一个私人仓库。我只想在将某些内容推送到 git 之前在 terraform 中运行一个脚本。它可以是任何文件,不一定是 tfstate。
标签: terraform