在终端中打印terraform模板渲染输出?

Tho*_*ggi 8 terraform

在terraform文档中,它显示了如何使用模板.有没有办法将此渲染输出记录到控制台?

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

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

output "rendered" {
  value = "${template_file.example.rendered}"
}
Run Code Online (Sandbox Code Playgroud)

Tho*_*ggi 7

你需要运行terraform applyterraform 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!
Run Code Online (Sandbox Code Playgroud)

  • 注意`terraform refresh`就足够了; 你没有'terraform apply`. (5认同)

小智 5

仔细观察,这是数据而不是资源

data "template_file" "example" {
template = "${file("templates/greeting.tpl")}"
  vars {
  hello = "goodnight"
  world = "moon"
  }
}

output "rendered" {
  value = "${data.template_file.example.rendered}"
}
Run Code Online (Sandbox Code Playgroud)