Help for the VSCode editor.
-
Information only
-
Navigate to the directory /root/terraform-projects/HCL. There is a file present in this location. What is the file extension used by this file?
-
Open the VSCode terminal.
-
In the terminal, do
cd /root/terraform-projects/HCL ls
We see
main.tf
. The file name ismain
and the file extension is.tf
-
-
Information only
-
What is the resource type specified in this file?
Inspect with VSCode:
-
Click on
terraform-projects
in the explorer pane -
Click on the revealed
main.tf
to open the file -
Examine the
resource
line. The first argument is thetype
and the second argument is thename
, therefore the answer islocal_file
-
-
What is the resource name used for the local_file resource in this configuration file?
Following on from the above, the answer is
games
-
What is the name of the provider for which we are creating this resource?
Know that the format of a resource type when decalring a resource is generally
provider_type
, therefore givenlocal_file
we havelocal
- name of the provider.file
- resource provided by the provider.
So the answer is
local
-
Which one of the below is not an example of an argument used within the resource block?
Know that arguments are what appears between
{
and}
in a resource block and are of the formargument = value
This resource has two arguments:
filename
andcontent
therefore the answer is the one that is not one of these two argumentsresource_type = "local_file"
-
If you run a terraform plan now? Would it work?
No
Go ahead and try it in the terminal and note the errors.
Why? We cannot plan or apply resources without first doing
terraform init
. For a new configuration, we must init the configuration to ensure all the correct providers are installed. -
Run a terraform init inside the configuration directory: /root/terraform-projects/HCL
-
If the terminal is closed, reopen it
-
Run the following commands
cd /root/terraform-projects/HCL terraform init
-
-
What was the version of the local provider plugin that was downloaded?
Inspect the output from
terraform init
. It lists the names and versions of all providers that were initialized. -
Now, try to run a terraform plan.
In the terminal run
terraform plan
This will either print an execution plan, or it will print a list of errors.
-
Why did the command fail?
Inspect the error produced when the command was run. If unsure, refer to the documentation.
We can see that it is complaining about arguments.
-
Which of the following is not a valid argument for the local_file resource?
Check the
Unsupported argument
error in the plan output. The argument that is "not expected here" is the invalid argument. -
Fix the argument in the configuration file and then run a terraform plan followed by terraform apply to create the local_file resource called games.
Check the
Missing required argument
error in the plan output. This gives you the correct name for the invalid argument.-
Edit
file
to befilename
-
Run
terraform plan terraform apply
-
-
What is the new argument that we have added?
There are now three arguments to the resource. Two of them were there before (although the values were different), and one of them is new.
sensitive_content
The values of sensitive fields do not show up in normal execution plans.
-
If we run terraform plan or terraform apply now we see an error!
Identify and fix the issue.You may ignore the deprecation warning.
The error here is "Invalid attribute combination". This means we have specified more than one argument in a mutually exclusive argument group. The list of mutually exclusive arguments is provided in the message:
[content,sensitive_content,content_base64]
You are asked to ensure the file content does not show up in the execution plan, so you must remove the argument that is not sensitive, i.e.
content
Remove this, then run
terraform plan terraform apply
Unfortunately the sensitive content still shows up in the deprecation warning. Hashicorp should really fix that! It does not however show up in the execution plan itself.
-
Information only
-
Finally, destroy this resource using terraform destroy.
Run
terraform destroy