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

# GitOps with sync Blocks

> Wire infrastructure outputs into ArgoCD and Flux deployments.

ubx's `sync` block creates GitOps CRDs (ArgoCD Applications or Flux Kustomizations) with infrastructure outputs wired in as parameters.

## The Problem

In a traditional GitOps setup:

```
RDS provisioned → manually update values.yaml → commit → ArgoCD picks up
```

This is manual, slow, and error-prone.

## The ubx Solution

```hcl theme={null}
unit "aws_rds_instance" "db" {
  engine         = "postgres"
  instance_class = "db.t3.micro"
}

sync "argocd" "backend" {
  repo      = "https://github.com/myorg/app-config"
  path      = "apps/backend"
  target    = "https://kubernetes.default.svc"
  namespace = "argocd"
  values = {
    db_host = ~unit.aws_rds_instance.db.endpoint  # auto-wired
    db_port = "5432"
  }
}
```

`ubx apply` provisions the RDS instance and creates the ArgoCD Application CRD with the endpoint injected as a Helm parameter. ArgoCD picks it up and deploys the app.

## ArgoCD Setup

```hcl theme={null}
sync "argocd" "backend" {
  repo      = "https://github.com/myorg/app-config"
  path      = "apps/backend"
  target    = "https://kubernetes.default.svc"
  namespace = "argocd"
  values = {
    db_host      = ~unit.aws_rds_instance.db.endpoint
    cluster_name = ~unit.aws_eks_cluster.cluster.name
    env          = input.env
  }
}
```

## Flux Setup

```hcl theme={null}
sync "flux" "infra" {
  repo      = "https://github.com/myorg/fleet-infra"
  path      = "./clusters/prod"
  namespace = "flux-system"
  values = {
    vpc_id  = ~unit.aws_vpc.main.id
    db_host = ~unit.aws_rds_instance.db.endpoint
  }
}
```

## Multi-Stack GitOps

For large platforms, use `remote` blocks to consume outputs from infrastructure stacks:

```hcl theme={null}
# apps stack
remote "infra" {
  source = "github.com/myorg/platform//stacks/infra"
  stack  = input.env
}

sync "argocd" "backend" {
  repo   = "https://github.com/myorg/app-config"
  path   = "apps/backend"
  target = "https://kubernetes.default.svc"
  namespace = "argocd"
  values = {
    db_host = ~@infra.db_endpoint
  }
}
```

## Environment-Specific Sync

```hcl theme={null}
sync "argocd" "backend" {
  repo      = "https://github.com/myorg/app-config"
  path      = "apps/backend/${input.env}"  # env-specific path
  target    = "https://kubernetes.default.svc"
  namespace = "argocd"
  when      = input.env == "prod"  # only in prod
}
```
