Linux command
terraform-console 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Open
terraform console
Evaluate
terraform console -plan
Evaluate
echo '[expression]' | terraform console
Open
terraform console -var-file=[path/to/vars.tfvars]
说明
terraform console provides an interactive REPL (Read-Eval-Print Loop) for evaluating Terraform expressions. It allows testing expressions and interpolations, inspecting current state values, experimenting with built-in functions like split(), lower(), length(), and debugging configurations interactively. The console is read-only and does not modify state, configuration files, or infrastructure resources. However, it locks the state file while running, preventing concurrent plan or apply operations. Fields, outputs, variables, and locals from the current Terraform state can be accessed directly. Type exit or press Ctrl-C / Ctrl-D to quit.
参数
- -plan
- Generate an execution plan first and evaluate expressions against the planned state rather than the current state. Shows values Terraform expects after the plan is applied
- -state=_path_
- Path to a local state file to evaluate expressions against (default: terraform.tfstate; legacy, local backend only)
- -var _'NAME=VALUE'_
- Set a variable value on the command line
- -var-file=_FILE_
- Load variable definitions from a file
FAQ
What is the terraform-console command used for?
terraform console provides an interactive REPL (Read-Eval-Print Loop) for evaluating Terraform expressions. It allows testing expressions and interpolations, inspecting current state values, experimenting with built-in functions like split(), lower(), length(), and debugging configurations interactively. The console is read-only and does not modify state, configuration files, or infrastructure resources. However, it locks the state file while running, preventing concurrent plan or apply operations. Fields, outputs, variables, and locals from the current Terraform state can be accessed directly. Type exit or press Ctrl-C / Ctrl-D to quit.
How do I run a basic terraform-console example?
Run `terraform console` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -plan do in terraform-console?
Generate an execution plan first and evaluate expressions against the planned state rather than the current state. Shows values Terraform expects after the plan is applied