Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 144


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?

Show Answer
Correct Answer: D

To read the contents of a local file as a string in a Terraform configuration, you can use the built-in function `file()`. This function reads the contents of a file at the given path and returns them as a string, making it suitable for reading the contents of the file `id_rsa.pub`.

Discussion

11 comments
Sign in to comment
Uma10Option: D
Mar 1, 2023

file reads the contents of a file at the given path and returns them as a string. Source: https://www.terraform.io/language/functions/file

BurakkoOption: D
Mar 2, 2023

"file reads the contents of a file at the given path and returns them as a string." file(path)

far12Option: D
Mar 13, 2023

the correct answer is D , explain : - file reads the contents of a file at the given path and returns them as a string. - filebase64 also reads the contents of a given file, but returns the raw bytes in that file Base64-encoded. -templatefile renders using a file from disk as a template.

NashP
Aug 2, 2024

D. file("id_rsa.pub") Explanation:To read the contents of a local file as a string in Terraform, you can use the file function. The correct syntax is: variable "public_key" { type = string default = file("id_rsa.pub") } This will read the contents of the "id_rsa.pub" file and assign it to the variable "public_key" as a string.

keiffo2
Mar 6, 2023

https://www.terraform.io/language/functions/file Answer D

shopkittyOption: D
Mar 10, 2023

fileset returning file name with full path, file will read the content of the files.

Pinky0289
Mar 14, 2023

file ("file_path") reads the contents of the file and returns the string, so option D is corret.

RVivekOption: D
Mar 27, 2023

https://www.terraform.io/language/functions/file https://www.terraform.io/language/functions/fileset

campsOption: D
Sep 30, 2023

D. file("id_rsa.pub"). The file function is a built-in Terraform function that can be used to read the contents of a local file and return the contents as a string. The file function takes a single argument, which is the path to the file to read.

BereOption: D
Jul 17, 2024

Example: resource "aws_key_pair" "example" { key_name = "my-key-pair" public_key = file("${path.module}/id_rsa.pub") }

ravi135
Aug 8, 2024

D is right