Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get local variable in terraform console

Tags:

terraform

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
}
like image 982
Tensho Avatar asked Nov 05 '18 16:11

Tensho


2 Answers

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!

like image 70
KJH Avatar answered Sep 18 '22 15:09

KJH


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
}
like image 31
Brent Bradburn Avatar answered Sep 17 '22 15:09

Brent Bradburn