【问题标题】:terraform saving output to fileterraform 将输出保存到文件
【发布时间】:2020-12-29 21:53:09
【问题描述】:

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

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
}
'''

【问题讨论】:

    标签: terraform terraform-provider-aws


    【解决方案1】:

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

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

    【讨论】:

    • 将尝试这个“local_file”资源。干杯马辛!
    • @CharlesD 没问题。很高兴我能帮忙:-)
    • 问题在于“local_file”是在“terraform apply”期间将消失的文件
    【解决方案2】:

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

     terraform output > file.txt
    

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

    【讨论】:

    • 如果文件还没有创建怎么办?这个命令会自动创建这个文件吗?
    • 是的,它会创建它。
    • 这会将“terraform output”的全部内容输出到file.txt。如果需要一个或多个单独的输出,例如证书正文或私钥,请使用@Marcin 上面所说的资源块
    猜你喜欢
    • 1970-01-01
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多