Use case:
You need to look up something in your statefile to confirm a resource setting and do not want to take the trouble to log into your AWS account. This assumes you have the access you need to access the statefile from your local machine.
Process:
If you run…
terraform state show
You will see this:
Multiple instances found for the given pattern! This command requires that the pattern match exactly one instance of a resource. To view the matched instances, use "terraform state list". Please modify the pattern to match only a single instance.
Suppose we are looking for a particular setting in a launch configuration. We would do something like this:
terraform state list | grep launch_configuration
We might see a result that resembles something like this:
module.activecollab.aws_launch_configuration.activecollab_launch_config module.grafana2.aws_launch_configuration.grafana2_launch_config module.logstash.aws_launch_configuration.logstash_launch_config module.pritunl-vpn.aws_launch_configuration.pritunl_launch_config module.prometheus.aws_launch_configuration.prometheus_launch_config
From here we would run the following and the results would look similar to this:
terraform state show module.pritunl-vpn.aws_launch_configuration.pritunl_launch_config id = pritunl-lc-20190001 associate_public_ip_address = true ebs_block_device.# = 0 ebs_optimized = false enable_monitoring = true ephemeral_block_device.# = 0 iam_instance_profile = pritunl_instance_profile image_id = ami-833XXX92725nck73c instance_type = t2.medium key_name = pritunl name = pritunl-lc-20190001 name_prefix = pritunl-lc- root_block_device.# = 1 root_block_device.0.delete_on_termination = true root_block_device.0.iops = 0 root_block_device.0.volume_size = 20 root_block_device.0.volume_type = standard security_groups.# = 1 security_groups.2564468536 = sg-3XXX92725nc9f9fd72ab spot_price = user_data = dac1X92725nc9f9fdc3fabad3b717a6648 vpc_classic_link_id = vpc_classic_link_security_groups.# = 0
From here looking at these results we can see what setting we needed to look up with just a few commands rather than having to take the time to log into our AWS account and click around for what we need.