Official doc: https://www.terraform.io/docs/commands/console.html
“terraform console” is a command you can run, which gives you the opportunity to evaluate expressions and interpolation – very useful while building terraform.
To use it, on the command line, navigate to your terraform folder, and then run
terraform console
You will be met with this prompt (which doesn’t support any history through the “up” arrow key ?):
Here you can enter Terraform syntax and press enter to see the results.
Lets take a look at a resource group that exists in my configuration:
I entered in “azurerm_resource_group.mpn-trainlab-rg” and the console output all the properties in the state file for this resource.
I could further define my entry to a single property, and get this:
Now we can try this with some of our input variables. Lets say I have a complicated variable that I’m using to define disks, and I want to make sure when I reference that on a resource, its going to work:
data_disks = { ti-web = { count = 1 size = 64 sku = "Standard_LRS" caching = "ReadWrite" } production_u02 = { # Take the total data size you want, and divide it by the count of disks you want, to determine size count = 4 size = 256 sku = "Premium_LRS" # Standard_LRS caching = "None" } } |
If I enter “var.data_disks” in the console, I would expect to get the exact same output as the code above, in JSON notation (lots of extra quotes and colons).
What if I’m trying to get the size of just the ti-web disk?
Looks like it works! Now I know on the resource for the “size” property, I can use “var.data_disks.ti-web.size” as a reference and it will provide my expected value.
Thank you for the information jeff