Terraform
upstream_input block reference
Use the upstream_input block to consume outputs from another Stack in the same project to use them in your current Stack.
Background
Note
The upstream_input block requires Terraform version 1.10.0-alpha20241009 or higher.
A Stack can expose an output to other Stacks by defining a publish_output blocks in its deployment configuration.
The upstream_input block specifies another Stack in the same project to consume outputs from. You must declare an upstream_input block for each Stack you want to reference outputs from. When an output from an upstream Stack changes, HCP Terraform automatically triggers runs for any Stacks that depend on those outputs.
Use upstream inputs to create dependencies between Stacks, letting you to share infrastructure details between different parts of your Stack architecture. To learn more and review examples, refer to Pass data between Stacks.
Configuration model
The upstream_input block supports the following arguments:
- upstream_input "<LABEL>"block
Complete configuration
All available arguments are defined in the following upstream_input block:
upstream_input "<LABEL>" {
  type   = "stack"
  source = "<URL_REFERRING_TO_UPSTREAM_STACK>"
}
Specification
An upstream_input block supports the following configuration.
upstream_input "<LABEL>"
The label after the upstream_input keyword is a name for the upstream input, which must be unique among all upstream inputs in the same deployment configuration file. The name can be any valid identifier.
The following arguments are supported in an upstream_input block:
| Argument | Description | Type | Required? | 
|---|---|---|---|
| type | The type of upstream source. HCP Terraform only supports "stack". | String | Required | 
| source | The Stack to source published outputs from specified as an URL. | String | Required | 
type
The type argument specifies "stack" as the type of upstream source to consume outputs from.
upstream_input "network_stack" {
  type   = "stack"
  source = "app.terraform.io/<ORGANIZATION>/<PROJECT>/<STACK_NAME>"
}
Summary
- Data type: String
- Default: None
- Required: Yes
source
The source argument specifies the upstream Stack's URL you want to consume outputs from:
upstream_input "database_stack" {
  type   = "stack"
  source = "app.terraform.io/<ORGANIZATION>/<PROJECT>/<STACK_NAME>"
}
The source URL must reference a Stack that exists in the same project as your current Stack.
Summary
- Data type: String
- Default: None
- Required: Yes
Examples
The following examples demonstrate common use cases for upstream_input blocks.
Fundamental upstream input
In the following example, the upstream_input block specifies a Stack named networking to consume outputs from:
upstream_input "network_stack" {
  type   = "stack"
  source = "app.terraform.io/myorg/myproject/networking"
}
deployment "application" {
  inputs = {
    vpc_id           = upstream_input.network_stack.vpc_id
    private_subnet_ids = upstream_input.network_stack.private_subnet_ids
    security_group_id  = upstream_input.network_stack.default_security_group_id
  }
}
After adding the network_stack upstream input, deployments can reference any values in publish_output blocks from the networking Stack.
After defining an upstream_input block, you can access published outputs from the upstream Stack using the syntax upstream_input.<LABEL>.<OUTPUT_NAME>. So the application deployment can reference outputs from the network_stack using upstream_input.network_stack.<OUTPUT_NAME>.