0
0
Terraformcloud~10 mins

File functions (file, templatefile) in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read the contents of a file named "config.txt".

Terraform
content = file("[1]")
Drag options to blanks, or click blank then click option'
Atemplate.tpl
Bconfig.txt
Cdata.txt
Dconfig.json
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong file name.
Confusing file with templatefile.
2fill in blank
medium

Complete the code to load a template file named "server.tpl".

Terraform
template_content = templatefile("[1]", { port = 8080 })
Drag options to blanks, or click blank then click option'
Adata.json
Bconfig.txt
Cserver.tpl
Dmain.tf
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-template file with templatefile.
Misspelling the file name.
3fill in blank
hard

Fix the error in the code to correctly read a file named "data.json".

Terraform
data = file([1])
Drag options to blanks, or click blank then click option'
A"data.json"
Bdata.json
Cdata
D'data.json'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the file name without quotes.
Using single quotes instead of double quotes.
4fill in blank
hard

Fill both blanks to read a template file "app.tpl" and pass the variable "version" with value "1.2.3".

Terraform
app_config = templatefile("[1]", { [2] = "1.2.3" })
Drag options to blanks, or click blank then click option'
Aapp.tpl
Bversion
Cconfig.tpl
Drelease
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong file name.
Using incorrect variable names.
5fill in blank
hard

Fill all three blanks to read a file "settings.conf", read a template "deploy.tpl", and pass variable "env" with value "prod".

Terraform
settings = file("[1]")
deploy_script = templatefile("[2]", { [3] = "prod" })
Drag options to blanks, or click blank then click option'
Asettings.conf
Bdeploy.tpl
Cenv
Dconfig.json
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing file names between file and templatefile.
Using wrong variable names.