TA-002-P · Question #401
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?
The correct answer is D. file("id_rsa.pub"). The file() function reads a local file and returns its contents as a string, making it ideal for importing public keys or other text files into Terraform configurations.
Question
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?
Options
- Afileset("id_rsa.pub")
- Bfilebase64("id_rsa.pub")
- Ctemplatefile("id_rsa.pub")
- Dfile("id_rsa.pub")
How the community answered
(54 responses)- A4% (2)
- C2% (1)
- D94% (51)
Why each option
The file() function reads a local file and returns its contents as a string, making it ideal for importing public keys or other text files into Terraform configurations.
fileset() returns a set of file paths matching a glob pattern within a directory, not the contents of a single file.
filebase64() reads a file and returns its contents encoded as a Base64 string, not a plain string.
templatefile() renders a template file by substituting variable expressions and requires a variables map as a second argument; it is not used for simple file import.
The file() function reads the contents of a file at the given path and returns it as a string. It is the standard Terraform built-in for importing raw file content - such as an SSH public key - directly into a resource argument like aws_key_pair.public_key.
Concept tested: Terraform file() built-in function usage
Source: https://developer.hashicorp.com/terraform/language/functions/file
Topics
Community Discussion
No community discussion yet for this question.