HashiCorp Certified: Terraform Associate — Question 1
You have deployed a new webapp with a public IP address on a cloud provider. However, you did not create any outputs for your code.
What is the best method to quickly find the IP address of the resource you deployed?
Answer options
- A. Run terraform output ip_address to view the result
- B. In a new folder, use the terraform_remote_state data source to load in the state file, then write an output for each resource that you find the state file
- C. Run terraform state list to find the name of the resource, then terraform state show to find the attributes including public IP address
- D. Run terraform destroy then terraform apply and look for the IP address in stdout
Correct answer: C
Explanation
The correct answer is C because running 'terraform state list' allows you to identify the deployed resource, and 'terraform state show' provides detailed attributes including the public IP address. Option A is incorrect since it requires outputs, which were not created. Option B is not the quickest method as it involves additional steps to access the state file. Option D is not advisable as it destroys the existing infrastructure, which is unnecessary just to retrieve the IP address.