terraform 将输出保存到文件

Cha*_*Zee 8 terraform terraform-provider-aws

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

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
}
'''
Run Code Online (Sandbox Code Playgroud)

Mar*_*cin 11

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

resource "local_file" "private_key" {
    content  = venafi_certificate.this.private_key_pem
    filename = "private_key.pem"
}
Run Code Online (Sandbox Code Playgroud)


Pre*_*kwu 10

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

 terraform output > file.txt
Run Code Online (Sandbox Code Playgroud)

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

  • 这不适用于敏感输出。`terraform output -raw myvariable` 输出单个变量,即使它被标记为敏感。`terraform output -json` 将所有变量输出为 json,即使标记为敏感也是如此。 (2认同)