Help for the VSCode editor.
-
Which of the following is not a valid variable type?
Refer: https://developer.hashicorp.com/terraform/language/expressions/types
item
-
Which one of the below is not a valid data type in terraform?
Referring to the same documentation...
array
In terraform, we refer to array-like types as
list
-
Navigate to the directory /root/terraform-projects/variables. Which type does the variable called number belong to?
- In the Explorer pane, navigate the the indicated file and click to open.
- find
variable "number"
and examine thetype
attribute
bool
-
How would you fetch the value of the key called slow from the variable called hard_drive in a terraform configuration?
Examine the
variables.tf
file. See the variable"hard_drive"
. This is a map type with strings as keys. It is also initialized with a default value which has the two key-value pairsslow
andfast
.Know that when referencing a variable, we must use the prefix
var.
, and when accessing a key in a map we use[]
with the key name within.var.hard_drive["slow"]
-
What is the index of the element called Female in the variable called gender?
Examine the variable
"gender"
in the file. It is a list of strings with a default value.Know that when indexing a list, the first element is at index zero.
1
-
What is the type of variable called users?
This is the same as Q3. Examine the
type
attribute of theusers
variable.set(string)
-
However, this variable has been defined incorrectly! Identify the mistake.
Know that the definition of a
set
is that its values must be unique. Examine the values closely with this in mind.duplicate elements
-
Information only.
-
What is the value for the argument called content used in the resource block for the resource jedi?
Look in
main.tf
. Identify the value of the attributephanius
-
Now, let's update this resource and add variables instead. Use the default value declared in the variable called jedi.
-
Inspect
variables.tf
. Find thejedi
variable. -
This variable, like the
hard_drive
variable is a map keyed with strings. Therefore we need to make expressions like the answer to Q4. -
Modify the
jedi
resource accordinglyReveal
resource "local_file" "jedi" { filename = var.jedi["filename"] content = var.jedi["content"] }
Ingnore it if you get a red underline in the file. Possible bug in the VSCode terraform plugin.
-
Deploy the resource
cd /root/terraform-projects/variables terraform init terraform plan terraform apply
-