The Magical `terraform console` Command


I was lurking in /r/Terraform on Reddit as I tend to do when I discovered someone commenting about the Terraform Console I had not heard of that previously so I started digging in.

It comes bundled with the Terraform cli by default. And allows you to browse the current state of your various resources and modules.

> aws_api_gateway_rest_api.api_gateway
{
  "api_key_source" = "HEADER"
  "arn" = "arn:aws:apigateway:us-east-1::/restapis/psnflsr6ha"
  "binary_media_types" = tolist([])
  "body" = "{\"info\":{\"title\":\"example\",\"version\":\"1.0\"},\"openapi\":\"3.0.1\",\"paths\":{}}"
  "created_date" = "2023-06-12T15:07:34Z"
  "description" = ""
  "disable_execute_api_endpoint" = false
  "endpoint_configuration" = tolist([
    {
      "types" = tolist([
        "REGIONAL",
      ])
      "vpc_endpoint_ids" = toset([])
    },
  ])
  "execution_arn" = "arn:aws:execute-api:us-east-1:368590945923:psnflsr6ha"
  "fail_on_warnings" = tobool(null)
  "id" = "psnflsr6ha"
  "minimum_compression_size" = ""
  "name" = "schematical-terraform-v1"
  "parameters" = tomap(null) /* of string */
  "policy" = ""
  "put_rest_api_mode" = tostring(null)
  "root_resource_id" = "q3jlr1ea55"
  "tags" = tomap({})
  "tags_all" = tomap({})
}

Interesting enough when I go to get the state of an entire module it prints out just the variables passed to it. Probably more valuable than trying to print out all the sub resources included in that module:

> module.dev_env
{
  "api_gateway_base_path_mapping" = "dev-v1-us-east-1-api.schematical.com/"
  "api_gateway_stage_id" = "ags-psnflsr6ha-dev"
  "api_gateway_stage_name" = "dev"
  "cloudfront_domain_name" = "d3s18d4v1p58tw.cloudfront.net"
  "cloudfront_zone_id" = "Z2FDTNDATAQYW2"
}

Not life changing by any means but a nice little tool to keep in your arsenal.