> ## 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.

# deploy block

> Push-based application deployment via Helm, Kustomize, or raw manifests.

The `deploy` block declares a push-based application deployment. ubx owns and applies it directly via Pulumi. Supports Helm charts, Kustomize, and raw Kubernetes manifests.

## Syntax

```hcl theme={"theme":"css-variables"}
deploy "type" "name" {
  # type-specific attributes
}
```

## Supported Types

| Type        | Pulumi resource           |
| ----------- | ------------------------- |
| `helm`      | `k8s.helm.v3.Chart`       |
| `kustomize` | `k8s.kustomize.Directory` |
| `manifest`  | `k8s.yaml.ConfigFile`     |

## Helm Deployment

```hcl theme={"theme":"css-variables"}
deploy "helm" "backend" {
  chart     = "my-backend"
  version   = "3.1.0"
  namespace = "backend"
  values = {
    database = {
      host = ~unit.aws_rds_instance.db.endpoint   # Pending<string>
      port = 5432
    }
    replica_count = 2
  }
}
```

The `values` attribute supports `Pending&lt;T&gt;` references. When any value is pending, ubx wraps the entire values object in `pulumi.all([...]).apply(...)`.

Generated TypeScript:

```typescript theme={"theme":"css-variables"}
const backend = new k8s.helm.v3.Chart("backend", {
    chart: "my-backend",
    version: "3.1.0",
    namespace: "backend",
    values: pulumi.all([db.endpoint]).apply(([_dep0]) => ({
        database: {
            host: _dep0,
            port: 5432,
        },
        replicaCount: 2,
    })),
} as any);
```

## Kustomize Deployment

```hcl theme={"theme":"css-variables"}
deploy "kustomize" "infra" {
  path = "./k8s/overlays/prod"
}
```

## Manifest Deployment

```hcl theme={"theme":"css-variables"}
deploy "manifest" "config" {
  file = "./k8s/configmap.yaml"
}
```

## Meta-Arguments

All meta-arguments work on `deploy` blocks:

```hcl theme={"theme":"css-variables"}
deploy "helm" "backend" {
  chart      = "my-backend"
  depends_on = [unit.aws_rds_instance.db]
  when       = input.env == "prod"
}
```

| Argument     | Type            | Description                                                                                                                        |
| ------------ | --------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `count`      | `number`        | Create N deployment instances. Use `count.index` for per-instance values. Mutually exclusive with `for_each`.                      |
| `for_each`   | `list` or `map` | Create one instance per element. Use `each.key` / `each.value`. Mutually exclusive with `count`.                                   |
| `when`       | `bool` expr     | Conditionally create the deployment. Resolved `bool` → `if (cond) { ... }`. Pending → `.apply((_when) => { if (_when) { ... } })`. |
| `depends_on` | `list` of refs  | Explicit dependency not inferred from `~` refs.                                                                                    |

## count

Create multiple deployments from one block. Each instance is keyed by index.

```hcl theme={"theme":"css-variables"}
deploy "helm" "backend" {
  count         = 3
  chart         = "my-app"
  release_name  = "backend-${count.index}"
}
```

Generated TypeScript:

```typescript theme={"theme":"css-variables"}
const backend: {[key: string]: k8s.helm.v3.Chart} = {};
[...Array(3)].forEach((_, idx) => {
    backend[String(idx)] = new k8s.helm.v3.Chart(`backend-${idx}`, {
        chart: "my-app",
        releaseName: `backend-${idx}`,
    } as any);
});
```

`count` and `for_each` are mutually exclusive on the same block.

## when

Conditionally create a deployment. The value must be a boolean expression.

```hcl theme={"theme":"css-variables"}
input "deploy_backend" { default = "true" }

deploy "helm" "backend" {
  when  = input.deploy_backend == "true"
  chart = "my-backend"
}
```

Generated TypeScript (resolved `when`):

```typescript theme={"theme":"css-variables"}
if ((deploy_backend === "true")) {
    const backend = new k8s.helm.v3.Chart("backend", {
        chart: "my-backend",
    } as any);
}
```

When the `when` condition references a `Pending<T>` value, ubx wraps the block in `.apply((_when) => { if (_when) { ... } })` instead.

## Cross-Stack Wiring

The key value of `deploy` blocks is wiring infra outputs directly into deployments:

```hcl theme={"theme":"css-variables"}
unit "aws_rds_instance" "db" {
  engine         = "postgres"
  instance_class = "db.t3.micro"
}

unit "aws_eks_cluster" "cluster" {
  name = "my-cluster"
}

deploy "helm" "app" {
  chart     = "my-app"
  namespace = "default"
  values = {
    db_host      = ~unit.aws_rds_instance.db.endpoint
    cluster_name = ~unit.aws_eks_cluster.cluster.name
  }
}
```

No `depends_on` needed — ubx infers the dependency from the `~` references.
