Help for the VSCode editor.
-
We have created a few resources in the configuration directory /root/terraform-projects/project-anime. Inspect it.
Which of the following resources names are not part of the terraform state?-
Navigate to indicated directory in Explorer pane.
-
Open the
terraform.tfstate
file and examine the resources. There are four. -
Find the one that isn't in there
Reveal
super_pets
-
-
Which command would you use to show the attributes of the resource called classics stored in the terraform state?
Reveal
cd /root/terraform-projects/project-anime terraform state show local_file.classics
We can pick individual resources by using the same reference syntax to identify a resource:
resource_type.resource_name
-
What is the value of the attribute called id that is created for the local file resource called top10?
We can again use
terrform state show
to see the attribute details.Reveal
cd /root/terraform-projects/project-anime terraform state show local_file.top10
-
We no longer wish to manage the file located at /root/anime/hall-of-fame.txt by Terraform. Remove the resource responsible for this file completely from the management of terraform.
Determine which resource represents the given file and use the
terraform state rm
command. Don't forget to also remove it from the configuration file, or terraform will attempt to recreate it at the next apply.Reveal
cd /root/terraform-projects/project-anime terraform state rm local_file.hall_of_fame
-
Now navigate to the directory /root/terraform-projects/super-pets. Just like the previous configuration directory, we have already created the resource. Inspect the configuration and identify the only resource type used.
- Navigate to indicated directory in Explorer pane.
- Inspect
main.tf
- you will see two resources of the same type.
-
Within this configuration the terraform state commands are working (Try it!) but there is no terraform.tfstate file present!
What is the reason for this behavior?Examine
teraform.tf
. What do you notice about the backend configuration?Reveal
We are using remote state
Yes, the backend is in S3.
terrafrom state
is interrogating the remote state directly. -
What is the id of the random_pet resource called super_pet_2 in the state file?
We can again use
terrform state show
to see the attribute details.Reveal
cd /root/terraform-projects/super-pets terraform state show random_pet.super_pet_2
Inspect the
id
-
Rename the resource from super_pet_1 to ultra_pet.
Use
terraform state mv
to do this, then update it inmain.tf
or the next apply will put if back as it was.Reveal
cd /root/terraform-projects/super-pets terraform state mv random_pet.super_pet_1 random_pet.ultra_pet