HashiCorp Certified: Terraform Associate — Question 256
You're writing a Terraform configuration that needs to read input from a local file called id_rsa.pub.
Which built-in Terraform function can you use to import the file's contents as a string?
Answer options
- A. fileset("id_rsa.pub")
- B. filebase64("id_rsa.pub")
- C. templatefile("id_rsa.pub")
- D. file("id_rsa.pub")
Correct answer: D
Explanation
The correct function to read a file's content as a string in Terraform is 'file', which directly returns the file's contents. The 'fileset' function is used for getting a list of files in a directory, 'filebase64' reads a file and encodes it in base64, and 'templatefile' is for processing template files, none of which serve the purpose of reading the file as a plain string.