Reputation: 42576
I am using terraform 0.12.9 and state is saved on s3 bucket. I'd like to list all resources by terraform state list
. Based on this document, https://www.terraform.io/docs/commands/state/list.html, it says -state=path - Path to the state file. Defaults to "terraform.tfstate". Ignored when remote state is used.
. How can I pass the state file if it is on remote s3 bucket?
Upvotes: 2
Views: 10753
Reputation: 1396
In my case it was my custom module, so I used:
terraform state list
Followed by state show
terraform state show 'module.sapsystem.azurerm_lb_backend_address_pool_address.backend_nodes["my-lovely-lb-bepool-node"]'
Upvotes: 0
Reputation: 730
terraform init
terraform workspace list
# show all workspacesterraform workspace select {env}
# select the workspace which you want list resourcesterraform state list
# list all resources. Could return nothing if there is no resource in the workspaceterraform state show '{resource}'
# show the attributes of a single resourceUpvotes: 2
Reputation: 4679
You need to configure the tfstate bucket path in your terraform.tf
file:
terraform {
backend "s3" {
bucket = "bucket_name"
key = "my/key/location/terraform.tfstate"
region = "bucket region"
}
}
and later you need to run terraform init
so that terraform would fetch the state from the remote bucket
Upvotes: 2