Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

terraform saving output to file

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
}
'''
like image 653
CharlesDeeZee Avatar asked Sep 11 '20 11:09

CharlesDeeZee


People also ask

How do I save my Terraform plan output?

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.

Does Terraform plan show output?

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.

How do you pass output value in Terraform?

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.

Can I use Terraform output as input?

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.

How do I use terraform output?

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.

How do I use terraform to query the database password?

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.

What is the difference between terraform root and child modules?

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.

What is the value argument in TerraForm?

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:


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"
}
like image 155
Marcin Avatar answered Nov 15 '22 01:11

Marcin


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

like image 38
Precious Okwu Avatar answered Nov 15 '22 01:11

Precious Okwu