# Variable Graph

Source: https://docs.ops0.com/docs/iac/variable-graph

Visualize Terraform variable and resource dependencies across your IaC projects as an interactive directed acyclic graph (DAG). The Variable Graph shows how outputs from one project feed into variables of another, helping you understand blast radius and dependency chains.

**Not the same as Resource Graph**

Variable Graph shows *cross-project* dependencies — which projects' outputs feed which projects' variables. For the dependency graph generated *within* a single project's Terraform state — individual resources, their relationships, and drift — see [Resource Graph](https://docs.ops0.com/docs/resource-graph). The **IaC → Graphs** list in the app is the browsing UI for Resource Graph, not a third feature.

## What It Shows

The graph renders each IaC project as a folder node with three key metrics:

| Metric | Icon | Color | Description |
|--------|------|-------|-------------|
| **Outputs** | Upload | Green | Values this project exports for other projects to consume |
| **Inputs** | Download | Blue | Variables this project consumes from other projects |
| **Resources** | Box | Orange | Terraform resources defined in this project |

Edges between nodes represent dependency relationships.

---

## Dependency Types

| Type | Description |
|------|-------------|
| **Remote State** | Project reads outputs from another project's state via `terraform_remote_state` |
| **Module** | Project consumes a module defined in another project |
| **Data Source** | Project references a data source that reads from another project's resources |

---

## Viewing the Graph

### Organization-Wide Graph

See all projects and their dependencies across the entire organization:

### Navigate to Variable Graph
Go to **IaC → Variable Graph** from the sidebar.

### View the Full Graph
All projects appear as nodes with dependency edges between them.

### Interact
- **Zoom** — scroll to zoom in/out
- **Pan** — drag the canvas to move around
- **Select** — click a node to see its details

### Project-Specific Graph

View a single project and its direct dependencies:

### Open a Project
Navigate to any IaC project.

### Click Variable Graph
Opens the graph filtered to this project and its connected projects.

### Explore Dependencies
The current project is highlighted with a purple "Current" badge. Connected projects show upstream (providers) and downstream (consumers).

---

## Node Details

Click any folder node to open the detail modal:

| Field | Description |
|-------|-------------|
| **Project Name** | The IaC project name |
| **Path** | File path within the project |
| **Variables** | List of input variables with types and descriptions |
| **Outputs** | List of exported outputs |
| **Resources** | Count and types of Terraform resources |
| **Impact Level** | Low, Medium, or High based on downstream dependency count |

### Impact Levels

| Level | Criteria | Meaning |
|-------|----------|---------|
| **Low** | 0–1 downstream dependents | Changes affect few projects |
| **Medium** | 2–4 downstream dependents | Changes may cascade to several projects |
| **High** | 5+ downstream dependents | Changes have wide blast radius — review carefully |

---

## Scanning for Dependencies

ops0 can scan all IaC projects to discover cross-project dependencies:

### Click Scan
On the Variable Graph page, click **Scan Projects**.

### Wait for Analysis
ops0 analyzes all projects for `terraform_remote_state` blocks, module references, and data source dependencies.

### View Updated Graph
The graph refreshes with all discovered dependencies.

Scanning is useful when:
- New projects have been added since the last scan
- Remote state references have changed
- You want to verify the dependency map is current

---

## Use Cases

| Use Case | How the Graph Helps |
|----------|-------------------|
| **Blast radius analysis** | Before modifying a project, see which downstream projects depend on its outputs |
| **Debugging state issues** | Trace which project provides a failing remote state reference |
| **Onboarding** | New team members can visualize how infrastructure projects connect |
| **Refactoring** | Identify tightly coupled projects that should be consolidated or decoupled |
| **Change planning** | Understand the order of operations when updating shared infrastructure |

---

## Cross-Project References

The graph only shows projects that share compatible backends — projects must use the same state backend provider and cloud integration to reference each other's state.

| Backend | Cross-Reference Support |
|---------|------------------------|
| **S3** | Projects sharing the same S3 bucket/region can reference each other |
| **GCS** | Projects in the same GCS bucket can reference each other |
| **Azure Blob** | Projects in the same storage account can reference each other |

---

## Output References

Output references are the mechanism that actually links two IaC projects in the graph. When project B needs to consume a value from project A (e.g. a VPC ID), you create an output reference that wires A's output into B as a variable.

### Inserting an Output Reference

### Open the consumer project
Open the IaC project that needs to read a value from another project.

### Click Insert Output Reference
In the editor toolbar, click **Insert Output Reference** (or use the output reference button in the file panel).

### Select the source project
A picker shows all compatible projects — those that share the same state backend provider and cloud integration.

### Select the output
Choose which output from the source project to reference.

### ops0 generates the reference block
The following is inserted into your `main.tf`:

```hcl
data "terraform_remote_state" "networking" {
  backend = "s3"
  config = {
    bucket = "my-terraform-state"
    key    = "projects/networking/terraform.tfstate"
    region = "us-east-1"
  }
}
```

You can then use the value:

```hcl
resource "aws_instance" "app" {
  subnet_id = data.terraform_remote_state.networking.outputs.private_subnet_id
}
```

### Managing Output References

Navigate to **Project → Output References** to see all output references configured for the project:

| Field | Description |
|-------|-------------|
| **Source project** | The project providing the output |
| **Output name** | The specific output being consumed |
| **Variable name** | How the value is referenced in this project |
| **Backend** | State backend being read from |

To remove a reference, click **Delete** on the reference row, then remove the corresponding `terraform_remote_state` block from your code.

### Backend Compatibility

Output references only work between projects that share a compatible state backend:

| Backend | Projects must share |
|---------|-------------------|
| **S3** | Same bucket and region |
| **GCS** | Same bucket |
| **Azure Blob** | Same storage account and container |

Projects with incompatible backends will not appear in the output reference picker.

---

## Related

- [IaC Overview](https://docs.ops0.com/docs/iac/overview): IaC features including deployments, AI coding, and scheduling.

- [Replicate Projects](https://docs.ops0.com/docs/iac/replicate): Clone projects across cloud providers and regions.

- [Projects](https://docs.ops0.com/docs/iac/projects): Create and manage IaC projects.

- [Advanced](https://docs.ops0.com/docs/iac/advanced): State backend configuration and remote state.
