A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.hashicorp.com/terraform/language/functions/templatestring below:

templatestring - Functions - Configuration Language | Terraform

templatestring function reference

This topic provides reference information about the templatestring function. The templatestring function renders a string defined elsewhere in the module as a template using a set of variables.

The primary use case for the templatestring function is to render templates fetched as a single string from remote locations. The function enables advanced use cases where a string template expression is insufficient, such as when the template is available from a named object declared in the current module. Refer to Dynamic template construction for additional information.

To render a template from a file, use the templatefile function.

Write templatestring functions using the following syntax:

templatestring(ARG1, ARG2, . . .)

Specify the following arguments:

In the following example, the function renders the string value located at data.aws_s3_object.example.body as the template:

templatestring(data.aws_s3_object.example.body, {
  name = var.name
})

For information about the syntax you can use for the variables arguments, refer to Strings and Templates.

The following example retrieves a template from S3 and dynamically renders it:

data "aws_s3_object" "example" {
  bucket = "example-example"
  key    = "example.tmpl"
}

output "example" {
  value = templatestring(data.aws_s3_object.example.body, {
    name = var.name
  })
}

For more examples of how to use templates, refer to the documentation for the templatefile function.

You can write an expression that builds a template dynamically and then assigns it to a local value. You can then use a reference to that local value as the first argument to the templatestring function.

Note that you should only dynamically construct templates in this way when no other alternative is feasible. This is because the result can be difficult to understand and maintain and is susceptible to unexpected inputs. Built-in Terraform functions may interact with the local filesystem. As a result, the inputs may produce a template that includes data from arbitrary files on the system where Terraform is running.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4