7
votes

Is there any way to get local variables within Terraform console?

> local.name
unknown values referenced, can't compute value

Seems like Terraform console allows only to check input variables and module output variables.

> var.in
2

> module.abc.out
3

Configuration file examples:

# main.tf

locals {
  name = 1
}

variable "in" {
  value = 2
}

module "abc" {
  source "path/to/module"
}

# path/to/module/main.tf

output "out" {
  value = 3
}
2
Where is the local value set from? Please elaborate. - Mithilesh_Kunal
@mithilesh.kunal Edited the question to give more context 🙇‍♂️ - Tensho

2 Answers

7
votes

Unfortunately, it looks like this is not possible in Terraform v0.11.x, but will be in v0.12 as described in this issue ticket:

https://github.com/hashicorp/terraform/issues/18413

HTH!

0
votes

This should work in recent Terraform releases.

$ terraform version
Terraform v1.0.5

$ terraform console
> local.name
1
> var.in
2

The tested 'main.tf'

locals {
  name = 1
}

variable in {
  default = 2
}