From 4959050a7138054a36e50d8e21e487a1974491a4 Mon Sep 17 00:00:00 2001 From: rkoron007 Date: Wed, 22 Oct 2025 18:10:08 -0700 Subject: [PATCH 1/9] First try on splitting the pages adding to 1.12 for now --- .../v1.12.x/data/language-nav-data.json | 22 +- .../docs/language/parameterize/index.mdx | 82 +++++++ .../docs/language/parameterize/locals.mdx | 76 +++++++ .../docs/language/parameterize/outputs.mdx | 97 ++++++++ .../variables.mdx} | 207 ++---------------- 5 files changed, 292 insertions(+), 192 deletions(-) create mode 100644 content/terraform/v1.12.x/docs/language/parameterize/index.mdx create mode 100644 content/terraform/v1.12.x/docs/language/parameterize/locals.mdx create mode 100644 content/terraform/v1.12.x/docs/language/parameterize/outputs.mdx rename content/terraform/v1.12.x/docs/language/{parameterize.mdx => parameterize/variables.mdx} (53%) 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 0743392450..22d7f6d225 100644 --- a/content/terraform/v1.12.x/data/language-nav-data.json +++ b/content/terraform/v1.12.x/data/language-nav-data.json @@ -57,8 +57,26 @@ }, { "title": "Set configuration parameters", - "path": "parameterize", - "alias": "variables, outputs, locals" + "alias": "variables, outputs, locals", + "routes": [ + { + "title": "Overview", + "path": "parameterize" + }, + { + "title": "Use variables to define module arguments", + "path": "parameterize/variables" + }, + { + "title": "Use locals to reuse expressions", + "path": "parameterize/locals" + }, + { + "title": "Use outputs to expose module data", + "path": "parameterize/outputs", + "alias": "write only" + } + ] }, { "title": "Manage sensitive data", diff --git a/content/terraform/v1.12.x/docs/language/parameterize/index.mdx b/content/terraform/v1.12.x/docs/language/parameterize/index.mdx new file mode 100644 index 0000000000..0c373e0c0b --- /dev/null +++ b/content/terraform/v1.12.x/docs/language/parameterize/index.mdx @@ -0,0 +1,82 @@ +--- +page_title: Set configuration parameters +description: Learn how to make Terraform modules flexible, composable, and reusable by defining input variables, locally-scoped values, and output values for your module. +--- + +# Set configuration parameters + +Make your Terraform modules flexible, composable, and reusable by defining input variables, local values, and output values. + +## Define variables to intake module arguments + +Variables define the interface of your module by specifying the values your module accepts as arguments. Defining a `variable` block lets your module consumers pass in values to customize behavior at runtime. Defining variables lets your module consumers affect module behavior without altering a module's source code. + +The following example `variable` block defines an input variable named `instance_type`, letting module consumers specify an EC2 instance type for `web` at runtime: + + + +```hcl +variable "instance_type" { + type = string + description = "EC2 instance type for the web server" + default = "t2.micro" +} + +resource "aws_instance" "web" { + instance_type = var.instance_type + # ... +} +``` + + + + +To learn more about defining variables, assigning values to variables, and managing variables in HCP Terraform, refer to [Use variables to define module arguments](/terraform/language/parameterize/variables). To learn more about the `variable` block, refer to the [`variable` block reference](/terraform/language/block/variable). + +## Define locals to reuse expressions + +The `locals` block defines temporary values scoped to a module, letting you name and reuse expressions in your configuration. For example, the following `locals` block defines a local value for the name of an application: + + + +```hcl +locals { + app_name = "${var.project_name}-${var.environment}" +} + +resource "aws_instance" "app_server" { + # ... + tags = { + Name = local.app_name + } +} +``` + + + +Other blocks in a module can reference `local.` to access values defined in a `locals` block. + +To learn more about defining and using local values, refer to [Define locals to reuse expressions](/terraform/language/parameterize/locals). To learn more about the `locals` block, refer to the [`locals` block reference](/terraform/language/block/locals). + +## Define outputs to expose module data + +The `output` block exposes data from a module, making module results available in the Terraform CLI, HCP Terraform, and other parts of your configuration. + +Use `output` blocks to export information about your module. In the following example, the `instance_ip` output exposes the private IP address of the `web` EC2 instance: + + + +```hcl +output "instance_ip" { + description = "Private IP address of the EC2 instance" + value = aws_instance.web.private_ip +} + +resource "aws_instance" "web" { + # … +} +``` + + + +To learn more about defining outputs in root and child modules, accessing output values, refer to [Define outputs to expose module data](/terraform/language/parameterize/outputs). To learn more about the `output` block, refer to the [`output` block reference](/terraform/language/block/output). diff --git a/content/terraform/v1.12.x/docs/language/parameterize/locals.mdx b/content/terraform/v1.12.x/docs/language/parameterize/locals.mdx new file mode 100644 index 0000000000..fffc3ff665 --- /dev/null +++ b/content/terraform/v1.12.x/docs/language/parameterize/locals.mdx @@ -0,0 +1,76 @@ +--- +page_title: Use locals to reuse expressions +description: Learn how to use local values to assign names to expressions, letting you name and reuse expressions in your configuration. +--- + +# Use locals to reuse expressions + +> **Hands-on:** Try the [Simplify Terraform Configuration with Locals](/terraform/tutorials/configuration-language/locals?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) tutorial. + +Local values are similar to function-scoped variables in other programming languages. Local values assign names to expressions, letting you use the name multiple times within a module instead of repeating that expression. + +## Define locals + +Add a `locals` block when you want to reuse an expression throughout your configuration. You can define the `locals` block in any module. The value you assign can be any valid Terraform expression and can reference the following: + +- Variables +- Resource attributes +- Function outputs +- Other local values + +For example, you could define a `locals` block to create a consistent naming convention, identify your primary subnet, and to set aside environmental configuration settings: + + + +```hcl +locals { + # Naming convention + resource_name = "${var.project_name}-${var.environment}" + + # Process the subnet list + primary_public_subnet = var.subnet_ids[0] + subnet_count = length(var.subnet_ids) + + # Environmental deployment settings + is_production = var.environment == "prod" + monitoring_enabled = var.monitoring || local.is_production +} +``` + + + +Use the `local.` syntax to reference values from a `locals` block in your configuration. The `locals` block defines local values, but you must use the singular `local` keyword to reference the individual values. + +For example, in your configuration you can reference `local.resource_name` to name resources, and use `local.primary_public_subnet` with `local.monitoring_enabled` to configure a web server: + + + +```hcl +resource "aws_instance" "web" { + ami = data.aws_ami.ubuntu.id + instance_type = var.instance_type + subnet_id = local.primary_public_subnet + monitoring = local.monitoring_enabled + + tags = { + Name = local.resource_name + Environment = var.environment + } +} + +resource "aws_security_group" "web" { + name = "${local.resource_name}-sg" + + tags = { + Name = "${local.resource_name}-security-group" + } +} +``` + + + +You can access local values in the module where you define them, but not in other modules. However, you can pass a local value to a child module as an [argument](/terraform/language/modules/syntax#calling-a-child-module). + +Local values help avoid repetition and give a meaningful name to the value of an expression. However, they can make configuration harder to read because they obscure where values originate. Use local values in situations where you either reuse a single value in many places to let you change a value in a single place or when the value is the result of a complex expression. + +To learn more about the `locals` block, refer to the [`locals` block reference](/terraform/language/block/locals). diff --git a/content/terraform/v1.12.x/docs/language/parameterize/outputs.mdx b/content/terraform/v1.12.x/docs/language/parameterize/outputs.mdx new file mode 100644 index 0000000000..295c21ca5c --- /dev/null +++ b/content/terraform/v1.12.x/docs/language/parameterize/outputs.mdx @@ -0,0 +1,97 @@ +--- +page_title: Use outputs to expose module data +description: Learn how to output data from a module to expose information about your infrastructure on the CLI, in HCP Terraform, and to other Terraform configurations. +--- + +# Use outputs to expose module data + +> **Hands-on:** Try the [Output data from Terraform](/terraform/tutorials/configuration-language/outputs) tutorial. + +Outputs let you expose information about your infrastructure on the command line, in HCP Terraform, and in other Terraform configurations. The `output` block serves the following purposes in Terraform: + +- Child modules can expose resource attributes to parent modules. +- Root modules can display values in CLI output. +- Other Terraform configurations using [remote state](/terraform/language/state/remote) can access root module outputs with the `terraform_remote_state` data source. +- Pass information from a Terraform operation to an automation tool. + +## Define outputs + +Add `output` blocks to export information about your module. For example, you can add two `output` blocks to expose the ID and the IP address of your configuration's web server: + + + +```hcl +output "instance_id" { + description = "ID of the EC2 instance" + value = aws_instance.web.id +} + +output "instance_ip" { + description = "Private IP address of the EC2 instance" + value = aws_instance.web.private_ip +} + +resource "aws_instance" "web" { + # … +} +``` + + + +Depending on whether an output value is defined in your root module or a child module, you can access the information exposed in different ways. Terraform displays root module output values in the CLI after you apply your configuration, and if you are using HCP Terraform, your workspace's overview page lists your configuration's outputs. + +You can use outputs to pass values from a child module to a parent module, and parent modules access those outputs using `module..` syntax. + +For example, your parent module can access the `instance_ip` and `instance_id` outputs from a child module named `web_server` by referencing `module.web_server.NAME`: + + + +```hcl +module "web_server" { + source = "./modules/web_server" + # … +} + +resource "aws_route53_record" "web" { + zone_id = data.aws_route53_zone.main.zone_id + name = "web.example.com" + type = "A" + records = [module.web_server.instance_ip] + #... +} + +resource "aws_cloudwatch_alarm" "web_health" { + alarm_name = "web-server-health" + comparison_operator = "GreaterThanThreshold" + threshold = "80" + + dimensions = { + InstanceId = module.web_server.instance_id + } + # ... +} +``` + + + +## Sensitive values in outputs + +If you are outputting sensitive data such as a password or API key, use the `sensitive` argument to prevent Terraform from displaying the value in CLI output: + + + +```hcl +output "database_password" { + description = "Auto-generated password for the RDS database instance" + value = aws_db_instance.main.password + sensitive = true +} +``` + + + +Terraform does still store the values of sensitive outputs in your state, and if you use the [`terraform output` CLI command](/terraform/cli/commands/output) with the `-json` or `-raw` flags then Terraform displays sensitive outputs in plain text. + +Adding the `ephemeral` argument to an output omits that value from state and plan files, but it adds restrictions to the values you can assign that output. To learn more about handling and outputting sensitive data in your configuration, refer to [Manage sensitive data](/terraform/language/manage-sensitive-data). + +To learn more about the `output` block, refer to the [`output` block reference](/terraform/language/block/output). diff --git a/content/terraform/v1.12.x/docs/language/parameterize.mdx b/content/terraform/v1.12.x/docs/language/parameterize/variables.mdx similarity index 53% rename from content/terraform/v1.12.x/docs/language/parameterize.mdx rename to content/terraform/v1.12.x/docs/language/parameterize/variables.mdx index 4d0bd2c715..9892e201c8 100644 --- a/content/terraform/v1.12.x/docs/language/parameterize.mdx +++ b/content/terraform/v1.12.x/docs/language/parameterize/variables.mdx @@ -1,27 +1,17 @@ --- -page_title: Set configuration parameters -description: Learn how to make Terraform modules flexible, composable, and reusable by defining input variables, locally-scoped values, and output values for your module. +page_title: Use variables to define module arguments +description: Learn how to variables define the interface of your module, and how to assign values to variables. --- -# Set configuration parameters - -Make your Terraform modules flexible, composable, and reusable by defining your module's input variables, defining module-scoped local values, and defining output values to expose data from your module. - -## Overview - -Use the following blocks to modify your module's behavior: - -- The `variable` block lets you define input arguments, letting module consumers pass in values to customize behavior at runtime. -- The `locals` block defines temporary values scoped to a module, letting you name and reuse expressions in your configuration. -- The `outputs` block exposes data from a module, making module results available in the Terraform CLI, HCP Terraform, and other parts of your configuration. - -## Define module input arguments with variables +# Use variables to define module arguments > **Hands-on:** Try the [Customize Terraform Configuration with Variables](/terraform/tutorials/configuration-language/variables?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) tutorial. -Add `variable` blocks to your configuration so that module consumers can pass in specific input values. This lets module consumers customize module behavior without altering the module's source code. Variables define the interface of your module by specifying what values your module accepts as arguments. +Variables define the interface of your module by specifying what values your module accepts as arguments. The `variable` block lets your module consumers customize module behavior without altering the module's source code. + +## Define variables -Adding a `variables` block to your root module lets consumers pass values into the module at run time. Defining a `variable` block in a child module lets a parent module pass values into the child module at run time. Learn more about [passing values to child modules](/terraform/language/modules/syntax#calling-a-child-module). +Add a `variables` block to your root module to let consumers pass values into the module at run time. Defining a `variable` block in a child module lets a parent module pass values into the child module at run time. Learn more about [passing values to child modules](/terraform/language/modules/syntax#calling-a-child-module). For example, if your root module has a resource with hardcoded values, Terraform sets up the same resource every time: @@ -78,6 +68,8 @@ variable "environment" { The `environment` variable contains an optional `validation` block to ensure the value a consumer assigns meets module requirements. Learn more about [validating variable values in your configuration](/terraform/language/validate). +## Reference variable values + To reference a `variable` in other parts of your configuration, use `var.` syntax. For example, to make your web server use the new variables, replace the hardcoded values with references to `var.instance_type`, `var.subnet_id`, and `var.environment`: @@ -100,6 +92,8 @@ resource "aws_instance" "web" { Module consumers can use the default values for the `environment`, `subnet_id`, and `instance_type` variables in the `web` configuration or input custom values when they run the configuration. If a variable does not have a default value, such as the `subnet_id` variable, then Terraform prompts the user to assign a value before it generates a plan. +## Sensitive values in variables + If you are defining a `variable` for sensitive data such as an API key or password, use the `sensitive` argument to prevent Terraform from displaying the value in CLI output: @@ -118,7 +112,7 @@ Terraform still stores the values of sensitive variables in your state. You can To learn more about the best practices of defining variables, refer to the [Terraform style guide](/terraform/language/style#variables). To learn more about the `variable` block, refer to the [`variable` block reference](/terraform/language/block/variable). -### Assign values to input variables +## Assign values to variables You can assign values to root module variables through multiple methods, each with different precedence levels. Child modules receive their inputs from a parent module as arguments. To learn more about calling child modules, refer to [Modules](/terraform/language/modules/syntax#calling-a-child-module). @@ -140,7 +134,7 @@ Once you assign a value to a variable, you cannot reassign that variable within Values defined in HCP Terraform and on the command line take precedence over other ways of assigning variable values. The variable's `default` argument is at the lowest level of precedence. -#### Manage variables in HCP Terraform +### Manage variables in HCP Terraform HCP Terraform provides the following variable management capabilities: @@ -150,7 +144,7 @@ HCP Terraform provides the following variable management capabilities: To learn more about variables in HCP Terraform, refer to the [Variables overview](/terraform/cloud-docs/workspaces/variables). -#### Command-line variables +### Command-line variables Inputting variable values with Terraform CLI commands is useful for one-off deployments or when you need to override specific values without creating new files. You can assign variable values with the Terraform CLI using the `-var==` flag: @@ -175,7 +169,7 @@ export TF_VAR_complex_config='{"key": "value", "list": ["a", "b"]}' For readability, and to avoid shell escaping, we recommend setting complex variable values with [variable definition files](#variable-definition-files). For more details on shell quoting and the Windows command prompt, refer to [Input variables on the command line](/terraform/cli/commands/plan#input-variables-on-the-command-line). -#### Variable definition files +### Variable definition files Variable definition files are ideal for managing different environment configurations and for managing variable values in your version control system. Create a variable definition file to assign multiple variable values in one file. @@ -231,7 +225,7 @@ terraform apply -var-file="production.auto.tfvars" If your variable definition files contains any sensitive values, ensure you [ignore those files in your VCS provider](/terraform/language/style#gitignore). -#### Environment variables +### Environment variables Environment variables are useful in CI/CD pipelines when you want to inject configuration values without creating additional files. You can set environment variables using the `TF_VAR_` prefix to a variable name: @@ -258,177 +252,10 @@ export TF_VAR_complex_config='{"key": "value", "list": ["a", "b"]}' For readability, and to avoid shell escaping, we recommend setting complex variable values with [variable definition files](#variable-definition-files). -#### Undeclared variables +### Undeclared variables Terraform handles setting values for undeclared variables differently depending on how you assign that value: - Terraform ignores any assigned [environment variables](#environment-variables) that do not have a matching `variable` block. - Terraform warns you if you assign an undeclared variable in a [variable definition file](#variable-definition-files), letting you catch accidental misspellings in your configuration or definition files. - Terraform errors if you attempt to assign a value for an undeclared variable with `-var` on the command line. - -## Define locals to reuse expressions - -> **Hands-on:** Try the [Simplify Terraform Configuration with Locals](/terraform/tutorials/configuration-language/locals?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) tutorial. - -Local values are similar to function-scoped variables in other programming languages. Local values assign names to expressions, letting you use the name multiple times within a module instead of repeating that expression. - -Define a `locals` block when you want to reuse an expression throughout your configuration. You can define the `locals` block in any module. The value you assign can be any valid Terraform expression and can reference the following: - -- Variables -- Resource attributes -- Function outputs -- Other local values - -For example, you could define a `locals` block to create a consistent naming convention, identify your primary subnet, and to set aside environmental configuration settings: - - - -```hcl -locals { - # Naming convention - resource_name = "${var.project_name}-${var.environment}" - - # Process the subnet list - primary_public_subnet = var.subnet_ids[0] - subnet_count = length(var.subnet_ids) - - # Environmental deployment settings - is_production = var.environment == "prod" - monitoring_enabled = var.monitoring || local.is_production -} -``` - - - -Use the `local.` syntax to reference values from a `locals` block in your configuration. The `locals` block defines local values, but you must use the singular `local` keyword to reference the individual values. - -For example, in your configuration you can reference `local.resource_name` to name resources, and use `local.primary_public_subnet` with `local.monitoring_enabled` to configure a web server: - - - -```hcl -resource "aws_instance" "web" { - ami = data.aws_ami.ubuntu.id - instance_type = var.instance_type - subnet_id = local.primary_public_subnet - monitoring = local.monitoring_enabled - - tags = { - Name = local.resource_name - Environment = var.environment - } -} - -resource "aws_security_group" "web" { - name = "${local.resource_name}-sg" - - tags = { - Name = "${local.resource_name}-security-group" - } -} -``` - - - -You can access local values in the module where you define them, but not in other modules. However, you can pass a local value to a child module as an [argument](/terraform/language/modules/syntax#calling-a-child-module). - -Local values help avoid repetition and give a meaningful name to the value of an expression. However, they can make configuration harder to read because they obscure where values originate. Use local values in situations where you either reuse a single value in many places to let you change a value in a single place or when the value is the result of a complex expression. - -To learn more about the `locals` block, refer to the [`locals` block reference](/terraform/language/block/locals). - -## Define outputs to expose module data - -> **Hands-on:** Try the [Output data from Terraform](/terraform/tutorials/configuration-language/outputs) tutorial. - -Outputs let you expose information about your infrastructure on the command line, in HCP Terraform, and in other Terraform configurations. The `output` block serves the following purposes in Terraform: - -- Child modules can expose resource attributes to parent modules. -- Root modules can display values in CLI output. -- Other Terraform configurations using [remote state](/terraform/language/state/remote) can access root module outputs with the `terraform_remote_state` data source. -- Pass information from a Terraform operation to an automation tool. - -Add `output` blocks to export information about your module. For example, you can add two `output` blocks to expose the ID and the IP address of your configuration's web server: - - - -```hcl -output "instance_id" { - description = "ID of the EC2 instance" - value = aws_instance.web.id -} - -output "instance_ip" { - description = "Private IP address of the EC2 instance" - value = aws_instance.web.private_ip -} - -resource "aws_instance" "web" { - # … -} -``` - - - -Depending on whether an output value is defined in your root module or a child module, you can access the information exposed in different ways. Terraform displays root module output values in the CLI after you apply your configuration, and if you are using HCP Terraform, your workspace's overview page lists your configuration's outputs. - -You can use outputs to pass values from a child module to a parent module, and parent modules access those outputs using `module..` syntax. - -For example, your parent module can access the `instance_ip` and `instance_id` outputs from a child module named `web_server` by referencing `module.web_server.NAME`: - - - -```hcl -module "web_server" { - source = "./modules/web_server" - # … -} - -resource "aws_route53_record" "web" { - zone_id = data.aws_route53_zone.main.zone_id - name = "web.example.com" - type = "A" - records = [module.web_server.instance_ip] - #... -} - -resource "aws_cloudwatch_alarm" "web_health" { - alarm_name = "web-server-health" - comparison_operator = "GreaterThanThreshold" - threshold = "80" - - dimensions = { - InstanceId = module.web_server.instance_id - } - # ... -} -``` - - - -If you are outputting sensitive data such as a password or API key, use the `sensitive` argument to prevent Terraform from displaying the value in CLI output: - - - -```hcl -output "database_password" { - description = "Auto-generated password for the RDS database instance" - value = aws_db_instance.main.password - sensitive = true -} -``` - - - -Terraform does still store the values of sensitive outputs in your state, and if you use the [`terraform output` CLI command](/terraform/cli/commands/output) with the `-json` or `-raw` flags then Terraform displays sensitive outputs in plain text. - -Adding the `ephemeral` argument to an output omits that value from state and plan files, but it adds restrictions to the values you can assign that output. To learn more about handling and outputting sensitive data in your configuration, refer to [Manage sensitive data](/terraform/language/manage-sensitive-data). - -To learn more about the `outputs` block, refer to the [`outputs` block reference](/terraform/language/block/output). - -## Next steps - -- [Variable block reference](/terraform/language/block/variable) - A complete reference of the `variable` block. -- [Locals block reference](/terraform/language/block/locals) - A complete reference of the `locals` block. -- [Output block reference](/terraform/language/block/output) - A complete reference of the `output` block. -- [Test your Validation](/terraform/language/validate) - Validate your configuration to improve your module consumer's troubleshooting, make your runs more predictable, and help your maintainers understand your configuration's intent. -- [Manage sensitive data](/terraform/language/manage-sensitive-data) - Learn how to handle sensitive and ephemeral data in your configuration and state. From 9f2efe7a40668098e0e5643877f6c6eaaa54e608 Mon Sep 17 00:00:00 2001 From: rkoron007 Date: Wed, 22 Oct 2025 18:11:45 -0700 Subject: [PATCH 2/9] Copy paste typo --- content/terraform/v1.12.x/data/language-nav-data.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 22d7f6d225..ab0654c3f8 100644 --- a/content/terraform/v1.12.x/data/language-nav-data.json +++ b/content/terraform/v1.12.x/data/language-nav-data.json @@ -73,8 +73,7 @@ }, { "title": "Use outputs to expose module data", - "path": "parameterize/outputs", - "alias": "write only" + "path": "parameterize/outputs" } ] }, From acfffa3398fd3eeddf300996ec20de3b1437f784 Mon Sep 17 00:00:00 2001 From: rkoron007 Date: Thu, 23 Oct 2025 10:18:09 -0700 Subject: [PATCH 3/9] Fix links in 1.12 --- content/terraform/v1.12.x/docs/language/block/locals.mdx | 2 +- content/terraform/v1.12.x/docs/language/block/output.mdx | 2 +- content/terraform/v1.12.x/docs/language/block/variable.mdx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/content/terraform/v1.12.x/docs/language/block/locals.mdx b/content/terraform/v1.12.x/docs/language/block/locals.mdx index 6ccc61f04e..ead3c23df0 100644 --- a/content/terraform/v1.12.x/docs/language/block/locals.mdx +++ b/content/terraform/v1.12.x/docs/language/block/locals.mdx @@ -15,7 +15,7 @@ The `locals` block is similar to function-scoped variables in other programming You can define local values in any module. Local values can be any valid Terraform expression, and can reference variables, resource attributes, function outputs, or other local values to transform or combine data. -To learn more about using `locals` blocks in your configurations, refer to [Define locals to reuse expressions](/terraform/language/parameterize#define-locals-to-reuse-expressions). +To learn more about using `locals` blocks in your configurations, refer to [Use locals to reuse expressions](/terraform/language/parameterize/locals). ## Configuration model diff --git a/content/terraform/v1.12.x/docs/language/block/output.mdx b/content/terraform/v1.12.x/docs/language/block/output.mdx index 48f7ebf0f1..8bebbdd2f5 100644 --- a/content/terraform/v1.12.x/docs/language/block/output.mdx +++ b/content/terraform/v1.12.x/docs/language/block/output.mdx @@ -20,7 +20,7 @@ The value of an `output` block is similar to a return value in other programming In HCP Terraform, your `output` block values appear in the UI after Terraform applies your configuration. You can [mark outputs as sensitive in HCP Terraform](/terraform/cloud-docs/workspaces/variables/managing-variables#sensitive-values) to hide their values in the UI and in API responses. -To learn more about using `output` blocks, refer to [Define outputs to expose module data](/terraform/language/parameterize#define-outputs-to-expose-module-data). +To learn more about using `output` blocks, refer to [Define outputs to expose module data](/terraform/language/parameterize/outputs). ## Configuration model diff --git a/content/terraform/v1.12.x/docs/language/block/variable.mdx b/content/terraform/v1.12.x/docs/language/block/variable.mdx index 5406652b1c..20b833c691 100644 --- a/content/terraform/v1.12.x/docs/language/block/variable.mdx +++ b/content/terraform/v1.12.x/docs/language/block/variable.mdx @@ -17,7 +17,7 @@ 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. -To learn more about the different ways to use and set values for variables, refer to [Define module input arguments with variables](/terraform/language/parameterize#define-module-input-arguments-with-variables). +To learn more about the different ways to use and set values for variables, refer to [Use variables to define module arguments](/terraform/language/parameterize/variables). ## Configuration model From 36afc52f37d5330a7c3790d9548bedf655731e01 Mon Sep 17 00:00:00 2001 From: rkoron007 Date: Thu, 23 Oct 2025 10:23:09 -0700 Subject: [PATCH 4/9] small tweaks --- .../v1.12.x/docs/language/parameterize/index.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/terraform/v1.12.x/docs/language/parameterize/index.mdx b/content/terraform/v1.12.x/docs/language/parameterize/index.mdx index 0c373e0c0b..9b6fca8974 100644 --- a/content/terraform/v1.12.x/docs/language/parameterize/index.mdx +++ b/content/terraform/v1.12.x/docs/language/parameterize/index.mdx @@ -37,7 +37,7 @@ To learn more about defining variables, assigning values to variables, and manag The `locals` block defines temporary values scoped to a module, letting you name and reuse expressions in your configuration. For example, the following `locals` block defines a local value for the name of an application: - + ```hcl locals { @@ -56,15 +56,15 @@ resource "aws_instance" "app_server" { Other blocks in a module can reference `local.` to access values defined in a `locals` block. -To learn more about defining and using local values, refer to [Define locals to reuse expressions](/terraform/language/parameterize/locals). To learn more about the `locals` block, refer to the [`locals` block reference](/terraform/language/block/locals). +To learn more about defining and using local values, refer to [Use locals to reuse expressions](/terraform/language/parameterize/locals). To learn more about the `locals` block, refer to the [`locals` block reference](/terraform/language/block/locals). ## Define outputs to expose module data The `output` block exposes data from a module, making module results available in the Terraform CLI, HCP Terraform, and other parts of your configuration. -Use `output` blocks to export information about your module. In the following example, the `instance_ip` output exposes the private IP address of the `web` EC2 instance: +Define `output` blocks to export information about your module. In the following example, the `instance_ip` output exposes the private IP address of the `web` EC2 instance: - + ```hcl output "instance_ip" { @@ -79,4 +79,4 @@ resource "aws_instance" "web" { -To learn more about defining outputs in root and child modules, accessing output values, refer to [Define outputs to expose module data](/terraform/language/parameterize/outputs). To learn more about the `output` block, refer to the [`output` block reference](/terraform/language/block/output). +To learn more about exposing data from modules and accessing those values, refer to [Use outputs to expose module data](/terraform/language/parameterize/outputs). To learn more about the `output` block, refer to the [`output` block reference](/terraform/language/block/output). From 27c3904baf6c46411fdc73033be4c12d0b6a03f4 Mon Sep 17 00:00:00 2001 From: rkoron007 Date: Thu, 23 Oct 2025 11:59:10 -0700 Subject: [PATCH 5/9] small tweak for article title --- content/terraform/v1.12.x/docs/language/block/output.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/terraform/v1.12.x/docs/language/block/output.mdx b/content/terraform/v1.12.x/docs/language/block/output.mdx index 8bebbdd2f5..bfcd069e5b 100644 --- a/content/terraform/v1.12.x/docs/language/block/output.mdx +++ b/content/terraform/v1.12.x/docs/language/block/output.mdx @@ -20,7 +20,7 @@ The value of an `output` block is similar to a return value in other programming In HCP Terraform, your `output` block values appear in the UI after Terraform applies your configuration. You can [mark outputs as sensitive in HCP Terraform](/terraform/cloud-docs/workspaces/variables/managing-variables#sensitive-values) to hide their values in the UI and in API responses. -To learn more about using `output` blocks, refer to [Define outputs to expose module data](/terraform/language/parameterize/outputs). +To learn more about using `output` blocks, refer to [Use outputs to expose module data](/terraform/language/parameterize/outputs). ## Configuration model From c21dc9d48acf460b115afc949b4eb315703bac35 Mon Sep 17 00:00:00 2001 From: rkoron007 Date: Thu, 23 Oct 2025 15:53:23 -0700 Subject: [PATCH 6/9] Add Judith feedback and handle redirects --- .../v1.12.x/data/language-nav-data.json | 16 ++++++++-------- .../v1.12.x/docs/language/block/locals.mdx | 2 +- .../v1.12.x/docs/language/block/output.mdx | 2 +- .../v1.12.x/docs/language/block/variable.mdx | 4 ++-- .../language/{parameterize => values}/index.mdx | 12 ++++++------ .../language/{parameterize => values}/locals.mdx | 0 .../{parameterize => values}/outputs.mdx | 0 .../{parameterize => values}/variables.mdx | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) rename content/terraform/v1.12.x/docs/language/{parameterize => values}/index.mdx (79%) rename content/terraform/v1.12.x/docs/language/{parameterize => values}/locals.mdx (100%) rename content/terraform/v1.12.x/docs/language/{parameterize => values}/outputs.mdx (100%) rename content/terraform/v1.12.x/docs/language/{parameterize => values}/variables.mdx (99%) 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 ab0654c3f8..12714d2f2b 100644 --- a/content/terraform/v1.12.x/data/language-nav-data.json +++ b/content/terraform/v1.12.x/data/language-nav-data.json @@ -56,24 +56,24 @@ ] }, { - "title": "Set configuration parameters", + "title": "Manage values in modules", "alias": "variables, outputs, locals", "routes": [ { "title": "Overview", - "path": "parameterize" + "path": "values" }, { - "title": "Use variables to define module arguments", - "path": "parameterize/variables" + "title": "Use variables", + "path": "values/variables" }, { - "title": "Use locals to reuse expressions", - "path": "parameterize/locals" + "title": "Use locals", + "path": "values/locals" }, { - "title": "Use outputs to expose module data", - "path": "parameterize/outputs" + "title": "Use outputs", + "path": "values/outputs" } ] }, diff --git a/content/terraform/v1.12.x/docs/language/block/locals.mdx b/content/terraform/v1.12.x/docs/language/block/locals.mdx index ead3c23df0..5de7543f63 100644 --- a/content/terraform/v1.12.x/docs/language/block/locals.mdx +++ b/content/terraform/v1.12.x/docs/language/block/locals.mdx @@ -15,7 +15,7 @@ The `locals` block is similar to function-scoped variables in other programming You can define local values in any module. Local values can be any valid Terraform expression, and can reference variables, resource attributes, function outputs, or other local values to transform or combine data. -To learn more about using `locals` blocks in your configurations, refer to [Use locals to reuse expressions](/terraform/language/parameterize/locals). +To learn more about using `locals` blocks in your configurations, refer to [Use locals to reuse expressions](/terraform/language/values/locals). ## Configuration model diff --git a/content/terraform/v1.12.x/docs/language/block/output.mdx b/content/terraform/v1.12.x/docs/language/block/output.mdx index bfcd069e5b..86d1b525ae 100644 --- a/content/terraform/v1.12.x/docs/language/block/output.mdx +++ b/content/terraform/v1.12.x/docs/language/block/output.mdx @@ -20,7 +20,7 @@ The value of an `output` block is similar to a return value in other programming In HCP Terraform, your `output` block values appear in the UI after Terraform applies your configuration. You can [mark outputs as sensitive in HCP Terraform](/terraform/cloud-docs/workspaces/variables/managing-variables#sensitive-values) to hide their values in the UI and in API responses. -To learn more about using `output` blocks, refer to [Use outputs to expose module data](/terraform/language/parameterize/outputs). +To learn more about using `output` blocks, refer to [Use outputs to expose module data](/terraform/language/values/outputs). ## Configuration model diff --git a/content/terraform/v1.12.x/docs/language/block/variable.mdx b/content/terraform/v1.12.x/docs/language/block/variable.mdx index 20b833c691..627c9cf067 100644 --- a/content/terraform/v1.12.x/docs/language/block/variable.mdx +++ b/content/terraform/v1.12.x/docs/language/block/variable.mdx @@ -5,7 +5,7 @@ description: Use variables to parameterize your configuration, making your modul # `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. +Variables define the interface of your module by specifying the values your module accepts as arguments. Use the `variable` block to let module consumers pass in values to customize behavior at runtime. > **Hands-on:** Try the [Customize Terraform Configuration with Variables](/terraform/tutorials/configuration-language/variables) tutorial. @@ -17,7 +17,7 @@ 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. -To learn more about the different ways to use and set values for variables, refer to [Use variables to define module arguments](/terraform/language/parameterize/variables). +To learn more about the different ways to use and set values for variables, refer to [Use variables to input module arguments](/terraform/language/values/variables). ## Configuration model diff --git a/content/terraform/v1.12.x/docs/language/parameterize/index.mdx b/content/terraform/v1.12.x/docs/language/values/index.mdx similarity index 79% rename from content/terraform/v1.12.x/docs/language/parameterize/index.mdx rename to content/terraform/v1.12.x/docs/language/values/index.mdx index 9b6fca8974..032b4c9384 100644 --- a/content/terraform/v1.12.x/docs/language/parameterize/index.mdx +++ b/content/terraform/v1.12.x/docs/language/values/index.mdx @@ -1,13 +1,13 @@ --- -page_title: Set configuration parameters +page_title: Manage values in modules description: Learn how to make Terraform modules flexible, composable, and reusable by defining input variables, locally-scoped values, and output values for your module. --- -# Set configuration parameters +# Manage values in modules Make your Terraform modules flexible, composable, and reusable by defining input variables, local values, and output values. -## Define variables to intake module arguments +## Define variables to input module arguments Variables define the interface of your module by specifying the values your module accepts as arguments. Defining a `variable` block lets your module consumers pass in values to customize behavior at runtime. Defining variables lets your module consumers affect module behavior without altering a module's source code. @@ -31,7 +31,7 @@ resource "aws_instance" "web" { -To learn more about defining variables, assigning values to variables, and managing variables in HCP Terraform, refer to [Use variables to define module arguments](/terraform/language/parameterize/variables). To learn more about the `variable` block, refer to the [`variable` block reference](/terraform/language/block/variable). +To learn more about defining variables, assigning values to variables, and managing variables in HCP Terraform, refer to [Use variables to define module arguments](/terraform/language/values/variables). To learn more about the `variable` block, refer to the [`variable` block reference](/terraform/language/block/variable). ## Define locals to reuse expressions @@ -56,7 +56,7 @@ resource "aws_instance" "app_server" { Other blocks in a module can reference `local.` to access values defined in a `locals` block. -To learn more about defining and using local values, refer to [Use locals to reuse expressions](/terraform/language/parameterize/locals). To learn more about the `locals` block, refer to the [`locals` block reference](/terraform/language/block/locals). +To learn more about defining and using local values, refer to [Use locals to reuse expressions](/terraform/language/values/locals). To learn more about the `locals` block, refer to the [`locals` block reference](/terraform/language/block/locals). ## Define outputs to expose module data @@ -79,4 +79,4 @@ resource "aws_instance" "web" { -To learn more about exposing data from modules and accessing those values, refer to [Use outputs to expose module data](/terraform/language/parameterize/outputs). To learn more about the `output` block, refer to the [`output` block reference](/terraform/language/block/output). +To learn more about exposing data from modules and accessing those values, refer to [Use outputs to expose module data](/terraform/language/values/outputs). To learn more about the `output` block, refer to the [`output` block reference](/terraform/language/block/output). diff --git a/content/terraform/v1.12.x/docs/language/parameterize/locals.mdx b/content/terraform/v1.12.x/docs/language/values/locals.mdx similarity index 100% rename from content/terraform/v1.12.x/docs/language/parameterize/locals.mdx rename to content/terraform/v1.12.x/docs/language/values/locals.mdx diff --git a/content/terraform/v1.12.x/docs/language/parameterize/outputs.mdx b/content/terraform/v1.12.x/docs/language/values/outputs.mdx similarity index 100% rename from content/terraform/v1.12.x/docs/language/parameterize/outputs.mdx rename to content/terraform/v1.12.x/docs/language/values/outputs.mdx diff --git a/content/terraform/v1.12.x/docs/language/parameterize/variables.mdx b/content/terraform/v1.12.x/docs/language/values/variables.mdx similarity index 99% rename from content/terraform/v1.12.x/docs/language/parameterize/variables.mdx rename to content/terraform/v1.12.x/docs/language/values/variables.mdx index 9892e201c8..9be5b1b0c7 100644 --- a/content/terraform/v1.12.x/docs/language/parameterize/variables.mdx +++ b/content/terraform/v1.12.x/docs/language/values/variables.mdx @@ -1,9 +1,9 @@ --- -page_title: Use variables to define module arguments +page_title: Use variables to input module arguments description: Learn how to variables define the interface of your module, and how to assign values to variables. --- -# Use variables to define module arguments +# Use variables to input module arguments > **Hands-on:** Try the [Customize Terraform Configuration with Variables](/terraform/tutorials/configuration-language/variables?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) tutorial. From 846c8083c743b88580326022b9b15b1aa3210df4 Mon Sep 17 00:00:00 2001 From: rkoron007 Date: Thu, 23 Oct 2025 16:27:51 -0700 Subject: [PATCH 7/9] Tweak intro --- content/terraform-docs-common/redirects.jsonc | 126 +++++++++--------- .../v1.12.x/docs/language/values/index.mdx | 18 +-- .../docs/language/values/variables.mdx | 6 +- 3 files changed, 75 insertions(+), 75 deletions(-) diff --git a/content/terraform-docs-common/redirects.jsonc b/content/terraform-docs-common/redirects.jsonc index c4ae108eff..10ea2ef66b 100644 --- a/content/terraform-docs-common/redirects.jsonc +++ b/content/terraform-docs-common/redirects.jsonc @@ -544,69 +544,69 @@ "permanent": true }, // values → parameterize - { - "source": "/terraform/language/values", - "destination": "/terraform/language/parameterize", - "permanent": true - }, - { - "source": "/terraform/language/v:version(1\\.(?:[1-9]|1[01])\\.x)/parameterize", - "destination": "/terraform/language/v:version/values", - "permanent": true - }, - { - "source": "/terraform/language/v:version((?:1\\.(?:1[2-9]|[2-9]\\d)|[2-9]\\d*\\.\\d+)\\.x)/values", - "destination": "/terraform/language/v:version/parameterize", - "permanent": true - }, - // values/locals → block/locals - { - "source": "/terraform/language/values/locals", - "destination": "/terraform/language/block/locals", - "permanent": true - }, - { - "source": "/terraform/language/v:version(1\\.(?:[1-9]|1[01])\\.x)/block/locals", - "destination": "/terraform/language/v:version/values/locals", - "permanent": true - }, - { - "source": "/terraform/language/v:version((?:1\\.(?:1[2-9]|[2-9]\\d)|[2-9]\\d*\\.\\d+)\\.x)/values/locals", - "destination": "/terraform/language/v:version/block/locals", - "permanent": true - }, - // values/variables → block/variable - { - "source": "/terraform/language/values/variables", - "destination": "/terraform/language/block/variable", - "permanent": true - }, - { - "source": "/terraform/language/v:version(1\\.(?:[1-9]|1[01])\\.x)/block/variable", - "destination": "/terraform/language/v:version/values/variables", - "permanent": true - }, - { - "source": "/terraform/language/v:version((?:1\\.(?:1[2-9]|[2-9]\\d)|[2-9]\\d*\\.\\d+)\\.x)/values/variables", - "destination": "/terraform/language/v:version/block/variable", - "permanent": true - }, - // values/outputs → block/output - { - "source": "/terraform/language/values/outputs", - "destination": "/terraform/language/block/output", - "permanent": true - }, - { - "source": "/terraform/language/v:version(1\\.(?:[1-9]|1[01])\\.x)/block/output", - "destination": "/terraform/language/v:version/values/outputs", - "permanent": true - }, - { - "source": "/terraform/language/v:version((?:1\\.(?:1[2-9]|[2-9]\\d)|[2-9]\\d*\\.\\d+)\\.x)/values/outputs", - "destination": "/terraform/language/v:version/block/output", - "permanent": true - }, + // { + // "source": "/terraform/language/values", + // "destination": "/terraform/language/parameterize", + // "permanent": true + // }, + // { + // "source": "/terraform/language/v:version(1\\.(?:[1-9]|1[01])\\.x)/parameterize", + // "destination": "/terraform/language/v:version/values", + // "permanent": true + // }, + // { + // "source": "/terraform/language/v:version((?:1\\.(?:1[2-9]|[2-9]\\d)|[2-9]\\d*\\.\\d+)\\.x)/values", + // "destination": "/terraform/language/v:version/parameterize", + // "permanent": true + // }, + // // values/locals → block/locals + // { + // "source": "/terraform/language/values/locals", + // "destination": "/terraform/language/block/locals", + // "permanent": true + // }, + // { + // "source": "/terraform/language/v:version(1\\.(?:[1-9]|1[01])\\.x)/block/locals", + // "destination": "/terraform/language/v:version/values/locals", + // "permanent": true + // }, + // { + // "source": "/terraform/language/v:version((?:1\\.(?:1[2-9]|[2-9]\\d)|[2-9]\\d*\\.\\d+)\\.x)/values/locals", + // "destination": "/terraform/language/v:version/block/locals", + // "permanent": true + // }, + // // values/variables → block/variable + // { + // "source": "/terraform/language/values/variables", + // "destination": "/terraform/language/block/variable", + // "permanent": true + // }, + // { + // "source": "/terraform/language/v:version(1\\.(?:[1-9]|1[01])\\.x)/block/variable", + // "destination": "/terraform/language/v:version/values/variables", + // "permanent": true + // }, + // { + // "source": "/terraform/language/v:version((?:1\\.(?:1[2-9]|[2-9]\\d)|[2-9]\\d*\\.\\d+)\\.x)/values/variables", + // "destination": "/terraform/language/v:version/block/variable", + // "permanent": true + // }, + // // values/outputs → block/output + // { + // "source": "/terraform/language/values/outputs", + // "destination": "/terraform/language/block/output", + // "permanent": true + // }, + // { + // "source": "/terraform/language/v:version(1\\.(?:[1-9]|1[01])\\.x)/block/output", + // "destination": "/terraform/language/v:version/values/outputs", + // "permanent": true + // }, + // { + // "source": "/terraform/language/v:version((?:1\\.(?:1[2-9]|[2-9]\\d)|[2-9]\\d*\\.\\d+)\\.x)/values/outputs", + // "destination": "/terraform/language/v:version/block/output", + // "permanent": true + // }, // /terraform → block/terraform { "source": "/terraform/language/terraform", diff --git a/content/terraform/v1.12.x/docs/language/values/index.mdx b/content/terraform/v1.12.x/docs/language/values/index.mdx index 032b4c9384..1f931c068c 100644 --- a/content/terraform/v1.12.x/docs/language/values/index.mdx +++ b/content/terraform/v1.12.x/docs/language/values/index.mdx @@ -5,13 +5,13 @@ description: Learn how to make Terraform modules flexible, composable, and reusa # Manage values in modules -Make your Terraform modules flexible, composable, and reusable by defining input variables, local values, and output values. +Make your Terraform modules flexible, composable, and reusable by defining input variable values, local values, and output values. ## Define variables to input module arguments -Variables define the interface of your module by specifying the values your module accepts as arguments. Defining a `variable` block lets your module consumers pass in values to customize behavior at runtime. Defining variables lets your module consumers affect module behavior without altering a module's source code. +Variables define the interface of your module by specifying the values your module accepts as arguments. Defining a `variable` block lets your module consumers input values at runtime. Variables let your module consumers change module behavior without altering that module's source code. -The following example `variable` block defines an input variable named `instance_type`, letting module consumers specify an EC2 instance type for `web` at runtime: +The following example `variable` block defines an input variable named `instance_type`, letting a module consumer specify an EC2 instance type for `web` at runtime: @@ -31,7 +31,7 @@ resource "aws_instance" "web" { -To learn more about defining variables, assigning values to variables, and managing variables in HCP Terraform, refer to [Use variables to define module arguments](/terraform/language/values/variables). To learn more about the `variable` block, refer to the [`variable` block reference](/terraform/language/block/variable). +To learn more about defining variables, assigning values to variables, and managing variables in HCP Terraform, refer to [Use variables to input module arguments](/terraform/language/values/variables). To learn more about the `variable` block and its arguments, refer to the [`variable` block reference](/terraform/language/block/variable). ## Define locals to reuse expressions @@ -54,15 +54,15 @@ resource "aws_instance" "app_server" { -Other blocks in a module can reference `local.` to access values defined in a `locals` block. +Other blocks in a module can reference `local.` to access values you define in a `locals` block. -To learn more about defining and using local values, refer to [Use locals to reuse expressions](/terraform/language/values/locals). To learn more about the `locals` block, refer to the [`locals` block reference](/terraform/language/block/locals). +To learn more about defining and using local values, refer to [Use locals to reuse expressions](/terraform/language/values/locals). To learn more about the `locals` block and its arguments, refer to the [`locals` block reference](/terraform/language/block/locals). ## Define outputs to expose module data -The `output` block exposes data from a module, making module results available in the Terraform CLI, HCP Terraform, and other parts of your configuration. +The `output` block exposes data from a module, making module values available in the Terraform CLI, HCP Terraform, and other parts of your configuration. -Define `output` blocks to export information about your module. In the following example, the `instance_ip` output exposes the private IP address of the `web` EC2 instance: +Define `output` blocks when you want to export information out of your module. In the following example, the `instance_ip` output exposes the private IP address of the `web` EC2 instance: @@ -79,4 +79,4 @@ resource "aws_instance" "web" { -To learn more about exposing data from modules and accessing those values, refer to [Use outputs to expose module data](/terraform/language/values/outputs). To learn more about the `output` block, refer to the [`output` block reference](/terraform/language/block/output). +To learn more about exposing data from modules and accessing those values, refer to [Use outputs to expose module data](/terraform/language/values/outputs). To learn more about the `output` block and its arguments, refer to the [`output` block reference](/terraform/language/block/output). diff --git a/content/terraform/v1.12.x/docs/language/values/variables.mdx b/content/terraform/v1.12.x/docs/language/values/variables.mdx index 9be5b1b0c7..131443f26d 100644 --- a/content/terraform/v1.12.x/docs/language/values/variables.mdx +++ b/content/terraform/v1.12.x/docs/language/values/variables.mdx @@ -13,7 +13,7 @@ Variables define the interface of your module by specifying what values your mod Add a `variables` block to your root module to let consumers pass values into the module at run time. Defining a `variable` block in a child module lets a parent module pass values into the child module at run time. Learn more about [passing values to child modules](/terraform/language/modules/syntax#calling-a-child-module). -For example, if your root module has a resource with hardcoded values, Terraform sets up the same resource every time: +For example, if your root module has a resource with hardcoded values: @@ -32,7 +32,7 @@ resource "aws_instance" "web" { -Hardcoded values in your configuration produce the same results every time, making your module inflexible and potentially hard to reuse. If you know a value in your configuration changes between Terraform operations, you can replace hardcoded values with `variable` blocks. +Terraform sets up resources with hardcoded values the same way every time, making your module inflexible and potentially hard to reuse. If you know a value in your configuration changes between Terraform operations, you can replace that value with a `variable` block. Defining variables gives your module consumer the flexibility to change values at run time. Add a `variable` block for each input you want to define for your module. @@ -66,7 +66,7 @@ variable "environment" { -The `environment` variable contains an optional `validation` block to ensure the value a consumer assigns meets module requirements. Learn more about [validating variable values in your configuration](/terraform/language/validate). +The `environment` variable also contains an optional `validation` block to ensure the value a consumer inputs meets module requirements. Learn more about [validating variable values in your configuration](/terraform/language/validate). ## Reference variable values From 03e331d371670f9e0beb87fc6119a445392d834e Mon Sep 17 00:00:00 2001 From: rkoron007 Date: Tue, 28 Oct 2025 15:19:02 -0700 Subject: [PATCH 8/9] Adam feedback --- .../v1.12.x/docs/language/values/index.mdx | 33 +++++++++++++------ .../v1.12.x/docs/language/values/locals.mdx | 4 +++ .../v1.12.x/docs/language/values/outputs.mdx | 30 ++++++++++++++--- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/content/terraform/v1.12.x/docs/language/values/index.mdx b/content/terraform/v1.12.x/docs/language/values/index.mdx index 1f931c068c..1a7cc711e2 100644 --- a/content/terraform/v1.12.x/docs/language/values/index.mdx +++ b/content/terraform/v1.12.x/docs/language/values/index.mdx @@ -1,17 +1,23 @@ --- page_title: Manage values in modules -description: Learn how to make Terraform modules flexible, composable, and reusable by defining input variables, locally-scoped values, and output values for your module. +description: Learn how to make Terraform modules flexible, composable, and reusable by defining input variables, local values, and output values for your module. --- # Manage values in modules Make your Terraform modules flexible, composable, and reusable by defining input variable values, local values, and output values. +## Background + +Terraform modules communicate with each other through the interface of inputs and outputs. Variables add parameters to your module, letting users input values at runtime. Outputs expose data from a module, letting you export information about your infrastructure. Locals let you define and reuse expressions within a module. + +Defining clear interfaces for your modules creates boundaries between them, letting you compose infrastructure from reusable components while keeping each module's implementation independent. + ## Define variables to input module arguments -Variables define the interface of your module by specifying the values your module accepts as arguments. Defining a `variable` block lets your module consumers input values at runtime. Variables let your module consumers change module behavior without altering that module's source code. +Variables define the input interface of your module by specifying the values your module accepts as arguments. -The following example `variable` block defines an input variable named `instance_type`, letting a module consumer specify an EC2 instance type for `web` at runtime: +For example, the following `variable` block defines an input variable named `instance_type`, letting a module consumer specify an EC2 instance type for `web` at runtime: @@ -31,11 +37,11 @@ resource "aws_instance" "web" { -To learn more about defining variables, assigning values to variables, and managing variables in HCP Terraform, refer to [Use variables to input module arguments](/terraform/language/values/variables). To learn more about the `variable` block and its arguments, refer to the [`variable` block reference](/terraform/language/block/variable). +To learn more about defining variables, assigning values to them, and managing variables in HCP Terraform, refer to [Use variables to input module arguments](/terraform/language/values/variables). To learn more about the `variable` block and its arguments, refer to the [`variable` block reference](/terraform/language/block/variable). ## Define locals to reuse expressions -The `locals` block defines temporary values scoped to a module, letting you name and reuse expressions in your configuration. For example, the following `locals` block defines a local value for the name of an application: +Locals define temporary values scoped to your module, letting you name and reuse expressions in your configuration. For example, the following `locals` block defines a local value for the name of an application: @@ -44,7 +50,14 @@ locals { app_name = "${var.project_name}-${var.environment}" } -resource "aws_instance" "app_server" { +resource "aws_instance" "example" { + # ... + tags = { + Name = local.app_name + } +} + +resource "aws_instance" "example2" { # ... tags = { Name = local.app_name @@ -54,15 +67,15 @@ resource "aws_instance" "app_server" { -Other blocks in a module can reference `local.` to access values you define in a `locals` block. +You can reference locals in other parts of your configuration to avoid retyping an expression multiple times. -To learn more about defining and using local values, refer to [Use locals to reuse expressions](/terraform/language/values/locals). To learn more about the `locals` block and its arguments, refer to the [`locals` block reference](/terraform/language/block/locals). +To learn more about when to use local values, refer to [Use locals to reuse expressions](/terraform/language/values/locals). To learn more about the `locals` block and its arguments, refer to the [`locals` block reference](/terraform/language/block/locals). ## Define outputs to expose module data -The `output` block exposes data from a module, making module values available in the Terraform CLI, HCP Terraform, and other parts of your configuration. +Outputs expose data from a module, making module values available in the Terraform CLI, HCP Terraform, and other parts of your configuration. -Define `output` blocks when you want to export information out of your module. In the following example, the `instance_ip` output exposes the private IP address of the `web` EC2 instance: +In the following example, the `instance_ip` output exports the private IP address of the `web` EC2 instance: diff --git a/content/terraform/v1.12.x/docs/language/values/locals.mdx b/content/terraform/v1.12.x/docs/language/values/locals.mdx index fffc3ff665..c75855dd8f 100644 --- a/content/terraform/v1.12.x/docs/language/values/locals.mdx +++ b/content/terraform/v1.12.x/docs/language/values/locals.mdx @@ -39,6 +39,10 @@ locals { +Refer to the [`locals` block reference](/terraform/language/block/locals) for more information about configuring local variables. + +## Reference local variables + Use the `local.` syntax to reference values from a `locals` block in your configuration. The `locals` block defines local values, but you must use the singular `local` keyword to reference the individual values. For example, in your configuration you can reference `local.resource_name` to name resources, and use `local.primary_public_subnet` with `local.monitoring_enabled` to configure a web server: diff --git a/content/terraform/v1.12.x/docs/language/values/outputs.mdx b/content/terraform/v1.12.x/docs/language/values/outputs.mdx index 295c21ca5c..61462f9558 100644 --- a/content/terraform/v1.12.x/docs/language/values/outputs.mdx +++ b/content/terraform/v1.12.x/docs/language/values/outputs.mdx @@ -16,7 +16,7 @@ Outputs let you expose information about your infrastructure on the command line ## Define outputs -Add `output` blocks to export information about your module. For example, you can add two `output` blocks to expose the ID and the IP address of your configuration's web server: +Add `output` blocks to export information about your module's infrastructure. For example, you can add two `output` blocks to expose the ID and the IP address of your configuration's web server: @@ -38,11 +38,18 @@ resource "aws_instance" "web" { -Depending on whether an output value is defined in your root module or a child module, you can access the information exposed in different ways. Terraform displays root module output values in the CLI after you apply your configuration, and if you are using HCP Terraform, your workspace's overview page lists your configuration's outputs. +You can set the `value` argument of an `output` block to any valid expression. To learn more, refer to the [`output` block reference](/terraform/language/block/output). -You can use outputs to pass values from a child module to a parent module, and parent modules access those outputs using `module..` syntax. -For example, your parent module can access the `instance_ip` and `instance_id` outputs from a child module named `web_server` by referencing `module.web_server.NAME`: +## Access output values + +Depending where you define an output value, you can access the information a module exposes in different ways. Terraform displays root module output values in the CLI after you apply your configuration. If you are using HCP Terraform, your workspace's overview page also lists your configuration's outputs. + +### Child module outputs + +Defining an `output` block in a child module exposes that value to the parent module. You can use outputs to pass a value from a child module to a parent module. Parent modules can access child module outputs using `module..` syntax. + +For example, the following parent module can access the `instance_ip` and `instance_id` outputs from a child module named `web_server` by referencing `module.web_server.NAME`: @@ -74,6 +81,8 @@ resource "aws_cloudwatch_alarm" "web_health" { +To learn more about passing information between modules, refer to [Call a child module](/language/modules/configuration#reference-module-output-values). + ## Sensitive values in outputs If you are outputting sensitive data such as a password or API key, use the `sensitive` argument to prevent Terraform from displaying the value in CLI output: @@ -90,7 +99,18 @@ output "database_password" { -Terraform does still store the values of sensitive outputs in your state, and if you use the [`terraform output` CLI command](/terraform/cli/commands/output) with the `-json` or `-raw` flags then Terraform displays sensitive outputs in plain text. +Trying to access a sensitive output value directly in the CLI displays a redacted message instead of the actual value: + +```shell-session +$ terraform output database_password +database_password = +``` + + + +Terraform stores the values of `sensitive` outputs in your state. If you use the [`terraform output` CLI command](/terraform/cli/commands/output) with the `-json` or `-raw` flags, Terraform displays sensitive outputs in plain text. + + Adding the `ephemeral` argument to an output omits that value from state and plan files, but it adds restrictions to the values you can assign that output. To learn more about handling and outputting sensitive data in your configuration, refer to [Manage sensitive data](/terraform/language/manage-sensitive-data). From f54a7f7ad6807b339e0e9fd7eeb3995192a461f5 Mon Sep 17 00:00:00 2001 From: rkoron007 Date: Tue, 28 Oct 2025 15:30:55 -0700 Subject: [PATCH 9/9] Fix the intro if variable --- .../v1.12.x/docs/language/values/variables.mdx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/content/terraform/v1.12.x/docs/language/values/variables.mdx b/content/terraform/v1.12.x/docs/language/values/variables.mdx index 131443f26d..ed1ac4f39a 100644 --- a/content/terraform/v1.12.x/docs/language/values/variables.mdx +++ b/content/terraform/v1.12.x/docs/language/values/variables.mdx @@ -1,13 +1,15 @@ --- -page_title: Use variables to input module arguments -description: Learn how to variables define the interface of your module, and how to assign values to variables. +page_title: Use input variables to add module arguments +description: Learn how to define input variables so that you can input new values at runtime. --- -# Use variables to input module arguments +# Use input variables to add module arguments > **Hands-on:** Try the [Customize Terraform Configuration with Variables](/terraform/tutorials/configuration-language/variables?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) tutorial. -Variables define the interface of your module by specifying what values your module accepts as arguments. The `variable` block lets your module consumers customize module behavior without altering the module's source code. +Variables define the input interface of your module by specifying what values your module accepts as arguments. + +Terraform sets up resources with hardcoded values the same way every time, making your module inflexible and potentially hard to reuse. If you know a value in your configuration changes between Terraform operations, you can replace that value with a `variable` block. A `variable` block lets module consumers customize module behavior without altering the module's source code. ## Define variables