terraform 将输出保存到文件

terraform saving output to file

我正在使用 terraform 生成证书。查找有关如何使用 terrafrom 将 pem 和证书值转储到磁盘文件的信息。这是输出变量。我想将它们转储到变量中。任何参考代码片段??

output "private_key" {
  description = "The venafi private key"
  value       = venafi_certificate.this.private_key_pem
}

output "certificate_body" {
  description = "The acm certificate body"
  value       = venafi_certificate.this.certificate
}

output "certificate_chain" {
  description = "The acm certificate chain"
  value       = venafi_certificate.this.chain
}
'''

一种方法是使用 local_file。例如:

resource "local_file" "private_key" {
    content  = venafi_certificate.this.private_key_pem
    filename = "private_key.pem"
}

这是一个老问题,但让我把我的答案放在这里,以防有人遇到同样的问题。 您可以将所有输出发送到这样的文件中

 terraform output > file.txt

其中 file.txt 是包含输出的文件