Hashicorp Certified Terraform Associate 003 · Free Practice Question Easy

Question 8

Steve is a developer who is deploying resources to AWS using Terraform. Steve needs to gather detailed information about an EC2 instance that he deployed earlier in the day. What command can Steve use to view this detailed information?

  • A

    terraform state list

  • B

    terraform state show aws_instance.frontend

  • C

    terraform state pull

  • D

    terraform state rm aws_instance.frontend

Reveal correct answer

Correct answer: B

Explanation

All resources that are managed by Terraform are referenced in the state file, including detailed information about the resource. Terraform uses the state to map your configuration to the real-world resources that are deployed and managed on the backend platform (AWS, GCP, F5, Infoblox, etc.). You can use the terraform state commands to view and manipulate Terraform state if needed.

terraform state show <resource address> will show you a lot of details on the resource, including things like the ID, IP address, the state of the resource, and lots more.


WRONG ANSWERS:

terraform state list will just show you a list of the resources being managed by Terraform, but it won't show you details on each of those resources

terraform state rm aws_instance.frontend would remove the resource from state. This would not destroy the resource on the public cloud, but it would tell Terraform to stop managing it.

terraform state pull will download the state from its current location, upgrade the local copy to the latest state file version that is compatible with locally-installed Terraform, and output the raw format to stdout

https://developer.hashicorp.com/terraform/cli/commands/state/show#example-show-a-resource

https://developer.hashicorp.com/terraform/cli/commands/state/rm

A. The command "terraform state list" does not provide detailed information about a specific resource like an EC2 instance. Instead, it lists all the resources managed by Terraform in the state file. It does not fulfill Steve's requirement of viewing detailed information about a specific EC2 instance.

B. The command "terraform state show aws_instance.frontend" is the correct choice as it allows Steve to view detailed information about a specific resource, in this case, an EC2 instance named "frontend" that he deployed earlier. This command displays the attributes and current state of the resource in Terraform.

C. The command "terraform state pull" is used to download and output the state from a remote state file. It does not provide detailed information about a specific resource like an EC2 instance. Steve needs to use the "terraform state show" command to view detailed information about the EC2 instance he deployed.

D. The command "terraform state rm aws_instance.frontend" is used to remove a resource from the Terraform state. It does not help Steve in gathering detailed information about the EC2 instance he deployed earlier. Using this command would result in the deletion of the resource from the state file.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need