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

# Profiles and stacks

> Save a bqto Pro target as a profile, open it by name, and group several profiles in a stack that opens them all in one session through one bastion.

> [!NOTE]
>
> This needs bqto Pro.

A profile saves a target: the project, the service, and the instance. A stack groups several
profiles, and opens them all in one session, through one bastion.

## A first stack

```sh theme={null}
bqto connect --project P --service cloudsql --instance orders --save db
bqto profile create cache --project P --service redis --instance cache
bqto connect db
bqto stack create work --profile db --profile cache
bqto connect --stack work
bqto profile rename cache sessions
bqto stack rename work checkout
```

Replace `P` with your project ID, and `orders` and `cache` with your instances.

1. The first line connects to the Cloud SQL instance `orders` and saves the session as the
   profile `db`. Ctrl-C ends it.
2. The second line saves the Redis instance `cache` as a profile, without connecting.
3. `bqto connect db` opens one profile by name.
4. The next two lines group both profiles in the stack `work`, and open them in one session,
   through one bastion.
5. The last two lines rename the profile `cache` to `sessions`, and the stack `work` to
   `checkout`. A stack that lists a renamed profile lists the new name in the same place.

`bqto profile -h` and `bqto stack -h` show the help, with examples.

## Profiles

A profile stores the identity of a target: the project, the service, and the instance. It never
stores the private IP of the service. bqto looks up the IP again on every connect, because PSC
endpoints change, and an old IP fails much later in a confusing way.

```toml theme={null}
[profiles.prod-db]
project    = "my-project"
service    = "cloudsql"
instance   = "sql-main"
duration   = "30m"
local_port = 15432
```

A profile holds no secrets. Authentication is ADC and IAM, so there is nothing to store.

```sh theme={null}
bqto connect prod-db
bqto connect prod-db -- psql -h 127.0.0.1 -p 15432 -U app
```

* `bqto profile create` saves a profile without connecting.
* `--save` on a `bqto connect` saves the session that you are already running.
* `bqto connect --service NAME` stays as it was: one service, nothing saved.
* `bqto profile list --output json` lists the saved profiles as JSON.
* `bqto profile rm NAME` removes a profile.
* `bqto profile rename OLD NEW` renames a profile. In the same write, bqto also updates every stack
  that lists it.
* `bqto stack rename OLD NEW` renames a stack.

A rename refuses a new name that is already taken.

### Names that are taken

If a name is already saved, bqto refuses it before it creates anything, with exit code 2. To
overwrite it, add `--replace` to `bqto profile create`, `bqto stack create`, or
`bqto connect --save`. bqto then prints the profile or stack that it replaced.

### Where profiles live

bqto stores profiles and stacks in `config.toml`, in the bqto config folder:

| System | Folder |
| - | - |
| macOS | `~/Library/Application Support/bqto/` |
| Linux | `~/.config/bqto/` |

To remove all profiles, delete the file.

## Several services at once

An application talks to its database, its cache, and its queue. Three sessions mean three bastions
and three terminals. Profiles and stacks put them in one session:

```sh theme={null}
bqto profile create db    --project my-project --service cloudsql --instance sql-main
bqto profile create cache --project my-project --service redis    --instance europe-west1/cache
bqto stack create checkout --profile db --profile cache

bqto connect --profile db              # one saved service
bqto connect --profile db,cache        # two, in one session
bqto connect --stack checkout          # the whole set
```

```text theme={null}
[1/2] cloudsql sql-main
[2/2] redis europe-west1/cache
ready: bastion bqto-a1b2c3d4, expires at 14:05 (in 28m)
  ready: 127.0.0.1:15432 → 10.0.0.5:5432 (cloudsql sql-main)
  ready: 127.0.0.1:16379 → 10.0.1.7:6379 (redis europe-west1/cache)
```

### Rules for a stack

* Every service must be on the same VPC, because a session is one bastion. If two services are on
  different VPCs, bqto says which two before it creates anything.
* A stack can have services in different regions. bqto warns about it. bqto creates the bastion in the region
  of the first service in the stack. It also asks that region for everything that the session
  needs from a subnet.
* This matters for Cloud Run, because Cloud Run needs Private Google Access on the subnet of the
  bastion. Put first a service whose region has Private Google Access, or turn it on as [Cloud Run](https://docs.bqto.dev/services/cloud-run.md#private-google-access)
  shows.
* `--service`, `--instance`, `--endpoint`, `-p`, `--web`, `--save`, and `-- CMD` describe a single
  target. They do not apply to a stack, which takes them from each profile.
* bqto checks every profile in the stack before it creates anything.

One session has one bastion. So these settings come from the first profile: `duration`, `spot`,
`zone`, `subnet`, `machine_type`, `image`, and `web`. bqto warns when a later profile sets them
differently.

bqto creates the bastion in the project of the first profile. It looks up the service of each
profile in its own project, so a stack can span projects on a Shared VPC. bqto checks Private
Google Access when any profile is Cloud Run.

## In CI and in the Mac app

* In GitHub Actions, bqto-action reads profiles and stacks from a `config.toml` in your repository.
  See [GitHub Actions](https://docs.bqto.dev/guides/github-actions.md#bqto-pro).
* The [Mac app](https://docs.bqto.dev/guides/mac-app.md) lists, creates, edits, and opens your profiles and stacks.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.