TA-002-P · Question #10
You have deployed a new webapp with a public IP address on a clod provider. However, you did not create any outputs for your code. What is the best method to quickly find the IP address of the resourc
The correct answer is C. Run terraform state list to find the name of the resource, then terraform state show to find. To find a specific attribute like a public IP address for a resource when no outputs are defined, you should inspect the Terraform state file directly.
Question
You have deployed a new webapp with a public IP address on a clod 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?
Options
- ARun terraform output ip_address to view the result
- BIn a new folder, use the terraform_remote_state data source to load in the state file, then
- CRun terraform state list to find the name of the resource, then terraform state show to find
- DRun terraform destroy then terraform apply and look for the IP address in stdout
How the community answered
(44 responses)- A7% (3)
- B2% (1)
- C89% (39)
- D2% (1)
Why each option
To find a specific attribute like a public IP address for a resource when no outputs are defined, you should inspect the Terraform state file directly.
`terraform output ip_address` would only work if an output named `ip_address` had been explicitly defined in the Terraform configuration, which the question states was not done.
Using `terraform_remote_state` in a new folder is for accessing state from *another* configuration, not for directly querying the *current* configuration's state file for an existing resource's attribute.
`terraform state list` allows you to identify the specific resource name in the state file. Once identified, `terraform state show <resource_name>` will display all attributes of that resource, including its public IP address, as recorded in the state.
Running `terraform destroy` and then `terraform apply` is an extreme and disruptive method that rebuilds infrastructure, it is not a quick or appropriate way to simply query an existing resource's attribute.
Concept tested: Inspecting Terraform state for resource attributes
Source: https://developer.hashicorp.com/terraform/cli/commands/state/show
Topics
Community Discussion
No community discussion yet for this question.