Skip to content

Latest commit

 

History

History
131 lines (82 loc) · 3.81 KB

02-terraform-state-commands.md

File metadata and controls

131 lines (82 loc) · 3.81 KB

Lab: Terraform State Commands

Help for the VSCode editor.

  1. 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?
    1. Navigate to indicated directory in Explorer pane.

    2. Open the terraform.tfstate file and examine the resources. There are four.

    3. Find the one that isn't in there

      Reveal

      super_pets

  2. 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

  3. 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
  4. 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
  5. 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.
    1. Navigate to indicated directory in Explorer pane.
    2. Inspect main.tf - you will see two resources of the same type.
  6. 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.

  7. 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

  8. Rename the resource from super_pet_1 to ultra_pet.

    Use terraform state mv to do this, then update it in main.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