How to print terraform variable values?
10,895
I tested with this:
variable "VMCount" {
description = "How many VMs do you want to start with (number)? default=1 max=5"
type = number
}
output "VMCount" {
value = "${var.VMCount > 2 && var.VMCount < 6 ? var.VMCount : 2}"
}
and it works well.
Terraform will perform the following actions:
Plan: 0 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ VMCount = 4
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
VMCount = 4
PS C:\d\m\terraform\output-and-variable> terraform output
VMCount = 4
PS C:\d\m\terraform\output-and-variable> terraform apply
var.VMCount
How many VMs do you want to start with (number)? default=1 max=5
Enter a value: 8
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
Terraform will perform the following actions:
Plan: 0 to add, 0 to change, 0 to destroy.
Changes to Outputs:
~ VMCount = 4 -> 2
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
VMCount = 2
PS C:\d\m\terraform\output-and-variable> terraform output
VMCount = 2
PS C:\d\m\terraform\output-and-variable>
Could you check what outouts doyou have in state? VMC or VMCount?
Related videos on Youtube
Author by
rajeev
Updated on June 04, 2022Comments
-
rajeev almost 2 years
I am learning terraform. I want to print values of variables in "plan" stage. So I found how to do it. seems I am doing something wrong here....
in variables.tf:....
variable "VMCount" { description = "How many VMs do you want to start with (number)? default=1 max=5" type = number }
in main.tf
output "VMCount" { value = "${var.VMCount > 2 && var.VMCount < 6 ? var.VMCount : 2}" }
after that i run terraform plan and the condition seem to be working fine (it creates right num of VMs)
but the variable output is not coming. why?
$ terraform output VMC = 56
that VMC is might be from some previous attempts ( I tried several things).
How to print the value of user entry (variable)?
Thank you.
-
ydaetskcoR almost 3 yearsYour code doesn't match the output shown. Specifically if you set
VMCount
to 56 it will currently return 2. Can you please edit your question to show your actual code (ideally as a minimal reproducible example) with the actual output you get when you runterraform apply
andterraform output
?
-
-
rajeev almost 3 yearsHow do I check that?
-
Krzysztof Madej almost 3 yearsDo you have remote backend or where do you store your state? Open state file and you should find output near the top.
-
Tanya Branagan almost 2 yearsOnly somewhat related, but I came across this question while looking to inspect module variables and I learned you can do that with Terraform console. terraform.io/cli/commands/console