> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ubiquex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Cross-Stack References

> Share outputs between stacks using remote blocks and ~@ references.

Large infrastructure projects split resources across multiple stacks. ubx's `remote` block and `~@` syntax make cross-stack output wiring first-class.

## Pattern

```
networking stack         →  exports: vpc_id, vpc_cidr
  ↓
eks stack               →  consumes: vpc_id; exports: cluster_endpoint
  ↓
apps stack              →  consumes: cluster_endpoint
```

## Declaring a Remote Reference

```hcl theme={null}
# apps/stack.iac

remote "networking" {
  source = "github.com/myorg/platform//stacks/networking"
  stack  = "${input.env}"
}
```

## Consuming Remote Outputs

Use `~@name.output` syntax:

```hcl theme={null}
unit "aws_subnet" "app" {
  vpc_id     = ~@networking.vpc_id      # Pending<string>
  cidr_block = cidrsubnet(~@networking.vpc_cidr, 8, 1)
}
```

Cross-stack references are always `Pending&lt;T&gt;`.

## The Remote Stack Must Export

The referenced stack must have a matching `output` block:

```hcl theme={null}
# networking/stack.iac

output "vpc_id" {
  value       = ~unit.aws_vpc.main.id
  description = "VPC ID for downstream stacks"
}

output "vpc_cidr" {
  value = ~unit.aws_vpc.main.cidr_block
}
```

## Stack References in Generated TypeScript

```typescript theme={null}
const networking = new pulumi.StackReference(
  `myorg/networking/${env}`
);

const app = new aws.ec2.Subnet("app", {
    vpcId: networking.getOutput("vpc_id"),
});
```

## Interface Contracts

Use [`interface`](/v1/language/interface) blocks to enforce that a stack exports required outputs:

```hcl theme={null}
interface "networking_contract" {
  output "vpc_id" {
    type        = "string"
    description = "Required by downstream stacks"
  }
}
```

`ubx validate` fails if the output is missing.
