Skip to content

Latest commit

 

History

History
108 lines (65 loc) · 2.88 KB

01-terraform-state.md

File metadata and controls

108 lines (65 loc) · 2.88 KB

Lab: Terraform State

Help for the VSCode editor.

  1. Which location is the terraform state file stored by default?

    Inside the configuration directory.

    This keeps it associated with the configuration.

  2. Which option should we use to disable state?

    We cannot disable state!

    State is the thing which makes terraform possible. Without it we have nothing.

  3. Which format is the state file stored in by default?

    JSON

  4. Which of the following commands does NOT refresh the state?

    terraform init

    • plan refreshes the state with the state of currently deployed resources, if you have previously applied the configuration.
    • apply updates the state with any changes made.
  5. What is the name of the state file that is created by default?

    terraform.tfstate

  6. Navigate to the configuration directory /root/terraform-projects/project-flash we have created a few configuration files here.

    The directory has been initialized and the provider plugins downloaded inside the .terraform directory. However, there is no terraform.tfstate file created. Why is that?

    terraform apply was not run

    Until some resources have actually been deployed, there is no state.

  7. Run the terraform show command and identify the id created for the resource called speed_force.
    cd /root/terraform-projects/project-flash/
    terraform show

    No details printed. There is no state.

    We haven't applied anything yet.

  8. Now, run terraform apply in this directory.
    terraform apply
  9. Now, check terraform show again. What is the value of id for the resource called speed_force?
    terraform show

    Locate the id attribute of the speed_force resource

  10. Information only

  11. Inspect the terraform.tfstate file or run terraform show command. You will notice that all the attribute details for all the resources created by this configuration is now printed on the screen!
    Among them is an EC2 Instance which is created by the resource called dev-server. See if you can find out the private_ip for the instance that was created.
    cd /root/terraform-projects/project-flash/
    terraform show

    Locate the private_ip attribute of the aws_instance.dev-server resource

  12. Information only