From ffbfcb44e974dc9c014b82a6e88523ddc21d660e Mon Sep 17 00:00:00 2001 From: rkoron007 Date: Thu, 12 Jun 2025 15:16:47 -0700 Subject: [PATCH 1/4] Add variable page --- .../v1.12.x/data/language-nav-data.json | 6 +- .../v1.12.x/docs/cli/commands/import.mdx | 2 +- .../v1.12.x/docs/language/block/variable.mdx | 384 ++++++++++++++++++ 3 files changed, 390 insertions(+), 2 deletions(-) create mode 100644 content/terraform/v1.12.x/docs/language/block/variable.mdx diff --git a/content/terraform/v1.12.x/data/language-nav-data.json b/content/terraform/v1.12.x/data/language-nav-data.json index b1efdcd7c..bf523e93d 100644 --- a/content/terraform/v1.12.x/data/language-nav-data.json +++ b/content/terraform/v1.12.x/data/language-nav-data.json @@ -210,7 +210,7 @@ "title": "Variables and Outputs", "routes": [ { "title": "Overview", "path": "values" }, - { "title": "Input Variables", "path": "values/variables" }, + { "title": "Variable block", "href": "/terraform/language/block/variable" }, { "title": "Output block", "href": "/terraform/language/block/output" }, { "title": "Local Values", "path": "values/locals" } ] @@ -1142,6 +1142,10 @@ { "title": "Terraform block", "path": "block/terraform" + }, + { + "title": "Variable block", + "path": "block/variable" } ] }, diff --git a/content/terraform/v1.12.x/docs/cli/commands/import.mdx b/content/terraform/v1.12.x/docs/cli/commands/import.mdx index c3097e739..a52dec35a 100644 --- a/content/terraform/v1.12.x/docs/cli/commands/import.mdx +++ b/content/terraform/v1.12.x/docs/cli/commands/import.mdx @@ -71,7 +71,7 @@ The command-line flags are all optional. The following flags are available: - `-var-file=foo` - Set variables in the Terraform configuration from a [variable file](/terraform/language/values/variables#variable-definitions-tfvars-files). If `terraform.tfvars` or any `.auto.tfvars` files are present in the current - directory, they are automatically loaded. Terraform loads `terraform.tfvars` + directory, they are automatically loaded. Terraform loads `terraform.tfvars` first and the `.auto.tfvars` files after in alphabetical order. Any files specified by `-var-file` override any values set automatically from files in the working directory. This flag can be used multiple times. This is only diff --git a/content/terraform/v1.12.x/docs/language/block/variable.mdx b/content/terraform/v1.12.x/docs/language/block/variable.mdx new file mode 100644 index 000000000..900eb4bb6 --- /dev/null +++ b/content/terraform/v1.12.x/docs/language/block/variable.mdx @@ -0,0 +1,384 @@ +--- +page_title: variable block reference for the Terraform configuration language +description: Use variables to parameterize your configuration, making your modules dynamic, reusable, and flexible by intaking values at run time. +--- + +# `variable` block reference + +Use the `variable` block to parameterize your configuration, making your modules dynamic, reusable, and flexible by letting them customize behavior with different values at run time. + +> **Hands-on:** Try the [Customize Terraform Configuration with Variables](/terraform/tutorials/configuration-language/variables) tutorial. + +## Background + +The `variable` block is similar to a function argument in other programming languages. Input variables let you customize Terraform modules without altering their source code. Variables serve as parameters for modules, making them composable and reusable. + +You can define variables in root modules, or in child modules: +- In the root modules, you can set variable values using CLI options, environment variables, variable definition files, or through an HCP Terraform workspace. +- In child modules, the parent module passes values to child modules as arguments to the `module` block. + + + +## Configuration model + +The `variable` block supports the following arguments: + +- [`variable "