terraform saving output to file

Viewed 19101

I am using terraform to gnerate certificates. Looking for information on how to dump pem and cert values to disk file using terrafrom. here is the output variable. i want to dump them to variable. any reference code snippet ??

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

One way would be to use local_file. For example:

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

This is an old question but let me drop my answer here incase anyone runs into thesame issue. You can send all your outputs to a file like this

 terraform output > file.txt

where file.txt is the file that contains the outputs

Related