# Lagoon Integration

DDEV provides integration with [Lagoon](<https://lagoon.sh/>), allowing users to quickly sync the files and database from a Lagoon environment to the local DDEV project.

## Lagoon Per-Project Configuration

1. Check out the Lagoon project and configure it by running [`ddev config`](<https://ddev.github.io/ddev/en/stable/users/usage/commands/#config>). You’ll want to run [`ddev start`](<https://ddev.github.io/ddev/en/stable/users/usage/commands/#start>) and make sure the basic functionality is working.
2. Add `LAGOON_PROJECT` and `LAGOON_ENVIRONMENT` variables to your project using `'web_environment'` in its YAML configuration or a `.ddev/.env` file. For example:

   ```
   web_environment:
       - LAGOON_PROJECT=your-project
       - LAGOON_ENVIRONMENT=main
   ```

   You can also do this with:

   ```
   ddev config --web-environment-add="LAGOON_PROJECT=your-project,LAGOON_ENVIRONMENT=main"
   ```
3. Syncing is done via [`lagoon-sync`](<https://github.com/uselagoon/lagoon-sync>) which must be configured in your `.lagoon.yml` or `.lagoon-sync.yml`, see the [DDEV example `.lagoon.yml`](<https://github.com/ddev/test-amazeeio-lagoon/blob/main/.lagoon.yml#L27-L37>).
4. Configure an [SSH key](<https://docs.lagoon.sh/using-lagoon-advanced/ssh/>) for your Lagoon user.
5. Run `ddev auth ssh` to make your SSH key available in the project’s web container.
6. Run [`ddev restart`](<https://ddev.github.io/ddev/en/stable/users/usage/commands/#restart>).
7. Run `ddev pull lagoon`. After you agree to the prompt, the current upstream databases and files will be downloaded.
8. Optionally use `ddev push lagoon` to push local files and database to Lagoon. The [`ddev push`](<https://ddev.github.io/ddev/en/stable/users/usage/commands/#push>) command must be done with great care if you’re pushing to a production environment, but is great for pushing to branch environments.

## Usage

- [`ddev pull lagoon`](<https://ddev.github.io/ddev/en/stable/users/usage/commands/#pull>) will connect to the Lagoon environment to download database and files. To skip downloading and importing either file or database assets, use the `--skip-files` and `--skip-db` flags.
- To pull from a specific environment without permanently changing your project config, pass environment variables using `--environment`:

  ```
  ddev pull lagoon --environment="LAGOON_ENVIRONMENT=main"
  ```

  You can combine multiple variables:

  ```
  ddev pull lagoon --environment="LAGOON_PROJECT=your-project,LAGOON_ENVIRONMENT=main"
  ```
- If you need to change the `lagoon.yaml` recipe, you can change it to suit your needs, but remember to remove the `#ddev-generated` line from the top of the file.
