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
}
'''
You can use the optional -out=FILE option to save the generated plan to a file on disk, which you can later execute by passing the file to terraform apply as an extra argument. This two-step workflow is primarily intended for when running Terraform in automation.
The terraform show command is used to provide human-readable output from a state or plan file. This can be used to inspect a plan to ensure that the planned operations are expected, or to inspect the current state as Terraform sees it. Machine-readable output is generated by adding the -json command-line flag.
Terraform Output Command To get the raw value without quotes, use the -raw flag. To get the JSON-formatted output, we can use the -json flag. This is quite useful when we want to pass the outputs to other tools for automation since JSON is way easier to handle programmatically.
Terraform output variables are used within the same parent or child module to print specific values in the command line output and are also used as inputs to create resources using the terraform apply command.
The terraform output command is used to extract the value of an output variable from the state file. With no additional arguments, output will display all the outputs for the root module. If an output NAME is specified, only the value of that output is printed. The command-line flags are all optional.
Notice that Terraform redacts the values of the outputs marked as sensitive. Use terraform output to query the database password by name, and notice that Terraform will not redact the value when you specify the output by name. Output values are stored as plain text in your state file — including those flagged as sensitive.
Even more, from a root module, we can print outputs in the command line or pass these output values to external systems for automation purposes. When we use a remote state, we can access the root module outputs by other configurations using the terraform_remote_state data source. Output values from child modules aren’t accessible.
The value argument, which is the returned output value, takes an expression referencing other resources or module attributes. Terraform only renders and displays outputs when executing terraform apply and not when executing terraform plan. To use outputs of nested modules from parent modules, we have to reference them as:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With