Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print terraform template rendered output in terminal?

Tags:

terraform

In the terraform docs it shows how to use a template. Is there any way to log this rendered output the console?

https://www.terraform.io/docs/configuration/interpolation.html#templates

data "template_file" "example" {
  template = "${hello} ${world}!"
  vars {
    hello = "goodnight"
    world = "moon"
  }
}

output "rendered" {
  value = "${template_file.example.rendered}"
}
like image 323
ThomasReggi Avatar asked Jun 17 '16 18:06

ThomasReggi


People also ask

What format does a rendered template take in terraform?

The template_file data source renders a template from a template string, which is usually loaded from an external file. In Terraform 0.12 and later, the templatefile function offers a built-in mechanism for rendering a template from a file.

What does rendered mean in terraform?

rendered - The final rendered template. The value of the policy will be the content of the template after terraform renders it.

What is Template Provider terraform?

The template provider exposes data sources to use templates to generate strings for other Terraform resources or outputs. Use the navigation to the left to read about the available data sources.


1 Answers

You need to run terraform apply then terraform output rendered

$ terraform apply
 template_file.example: Creating...
   rendered:   "" => "<computed>"
   template:   "" => "${hello} ${world}!"
   vars.#:     "" => "2"
   vars.hello: "" => "goodnight"
   vars.world: "" => "moon"
 template_file.example: Creation complete

 Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

 The state of your infrastructure has been saved to the path
 below. This state is required to modify and destroy your
 infrastructure, so keep it safe. To inspect the complete state
 use the `terraform show` command.

 State path: terraform.tfstate

 Outputs:

   rendered = goodnight moon!
 $ terraform output rendered
 goodnight moon!
like image 185
ThomasReggi Avatar answered Oct 12 '22 13:10

ThomasReggi