mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
docs: update template_file examples
Use the new non-deprecated style. refs #4025
This commit is contained in:
parent
047ac8e534
commit
bd23ab35bf
@ -178,29 +178,22 @@ A template resource looks like:
|
|||||||
|
|
||||||
```
|
```
|
||||||
resource "template_file" "example" {
|
resource "template_file" "example" {
|
||||||
filename = "template.txt"
|
template = "${hello} ${world}!"
|
||||||
vars {
|
vars {
|
||||||
hello = "goodnight"
|
hello = "goodnight"
|
||||||
world = "moon"
|
world = "moon"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output "rendered" {
|
output "rendered" {
|
||||||
value = "${template_file.example.rendered}"
|
value = "${template_file.example.rendered}"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Assuming `template.txt` looks like this:
|
|
||||||
|
|
||||||
```
|
|
||||||
${hello} ${world}!
|
|
||||||
```
|
|
||||||
|
|
||||||
Then the rendered value would be `goodnight moon!`.
|
Then the rendered value would be `goodnight moon!`.
|
||||||
|
|
||||||
You may use any of the built-in functions in your template.
|
You may use any of the built-in functions in your template.
|
||||||
|
|
||||||
|
|
||||||
### Using Templates with Count
|
### Using Templates with Count
|
||||||
|
|
||||||
Here is an example that combines the capabilities of templates with the interpolation
|
Here is an example that combines the capabilities of templates with the interpolation
|
||||||
@ -220,8 +213,8 @@ variable "hostnames" {
|
|||||||
|
|
||||||
resource "template_file" "web_init" {
|
resource "template_file" "web_init" {
|
||||||
// here we expand multiple template_files - the same number as we have instances
|
// here we expand multiple template_files - the same number as we have instances
|
||||||
count = "${var.count}"
|
count = "${var.count}"
|
||||||
filename = "templates/web_init.tpl"
|
template = "${file("templates/web_init.tpl")}"
|
||||||
vars {
|
vars {
|
||||||
// that gives us access to use count.index to do the lookup
|
// that gives us access to use count.index to do the lookup
|
||||||
hostname = "${lookup(var.hostnames, count.index)}"
|
hostname = "${lookup(var.hostnames, count.index)}"
|
||||||
|
Loading…
Reference in New Issue
Block a user