我有一个Terraform脚本,该脚本创建一个config.json
文件,然后运行使用该config.json
的命令:
resource "local_file" "config" {
# Output vars to config
filename = "config.json"
content = "..."
# Deploy using config
provisioner "local-exec" {
command = "deploy"
}
}
这一切都很好,但是当我运行terraform destroy
时,我想运行另一个命令-我尝试通过添加以下内容来在null_resource
中使用销毁时间供应器来执行此操作:
resource "null_resource" "test" {
provisioner "local-exec" {
when = "destroy"
command = "delete"
}
}
脚本已运行,但是在删除配置文件后运行-它出错,因为它需要该配置文件存在才能知道要删除什么。
我该如何解决?
谢谢!
答案 0 :(得分:0)
我将销毁时间供应商移至原始资源,并且效果很好:
resource "local_file" "config" {
# Output vars to config
filename = "config.json"
content = "..."
# Deploy using config
provisioner "local-exec" {
command = "deploy"
}
# Delete on_destroy
provisioner "local-exec" {
when = "destroy"
command = "delete"
}
}