You are reading contents of a local file in a Terraform configuration. Which built-in function should you use to import the file's contents as a string?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

You are reading contents of a local file in a Terraform configuration. Which built-in function should you use to import the file's contents as a string?

Explanation:
Reading a local file’s contents as a string in Terraform is done with the file() function. It takes the file path and returns the raw text contents, so using file("id_rsa.pub") loads that file into a string for use in your configuration. The other options don’t fit: fileset returns a set of filenames rather than contents; templatefile processes a template and requires placeholders to render; filebase64 returns the base64-encoded contents, not the plain string. So for a plain string read, the best choice is file("id_rsa.pub").

Reading a local file’s contents as a string in Terraform is done with the file() function. It takes the file path and returns the raw text contents, so using file("id_rsa.pub") loads that file into a string for use in your configuration. The other options don’t fit: fileset returns a set of filenames rather than contents; templatefile processes a template and requires placeholders to render; filebase64 returns the base64-encoded contents, not the plain string. So for a plain string read, the best choice is file("id_rsa.pub").

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy