Help for the VSCode editor.
-
A data source once created, can be used to create, update, and destroy infrastructure?
FALSE
A datasource can only read resource data and use that information within terraform.
-
A data source can be created using the data block.
'TRUE'
-
A new configuration directory has been created at /root/terraform-projects/project-lexcorp. A data source block is defined in the main.tf file to read the contents of an existing file.
There is also an output variable that uses reference expression to print the file content using this data source. However, there is something wrong!
Troubleshoot and fix the issue.-
We can immediately see the first issue based on the onswer to the previous question. There is no such block as
datasource
. Correct this. -
Let's see if we fixed it
cd /root/terraform-projects/project-lexcorp terraform init terraform plan
-
There is another error at line 2
A data resource "local_file" "content" has not been declared in the root module.
The value reference at this line is incorrectly looking for
data "local_file" "content" { ... }
so there is a mistake in the reference expression. A reference expression for a data block is:
data.type.name.attribute
We know from previous labs that the
local_file
resource has an attributecontent
, therefore we are missing the resource name from the reference. Correct it:data.local_file.os.content
-
Deploy
terraform plan terraform apply
-
-
Information only.
-
We have now created a new configuration file called ebs.tf within the same configuration directory we have been working on.
What is the resource type that we are working with here?The first property of the
data
block is the resource type, just as it is forresource
aws_ebs_volume
-
Once this data source is created, how do we fetch the Volume Id for the resource that is created in AWS?
Refer to the documentation and look in the Attributes Reference section.
Choose the correct attribute from those given. Attribute names are case sensistive.
-
Another file called s3.tf has now been created. It too has a data source that will be used to read data of an existing s3 bucket.
However, there is a mistake in the argument used. What is wrong here?This data source has an argument, which is the name of the bucket to get information on.
Refer to the documentation and look in the Argument Reference section. You will see that there is only one argument, and it's not in agreement with what is in
s3.tf
, therefore the answer must bebucket_name is not a valid argument
-
Information only.