Skip to content

Commit

Permalink
thomasgauvin: add credential rotation methods to hyperdrive (#17464)
Browse files Browse the repository at this point in the history
* thomasgauvin: add credential rotation methods to hyperdrive

* thomasgauvin:rename file and add note to update in situ

* Apply suggestions from code review

* Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx

* Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx

* Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx

* Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx

* Apply suggestions from code review

* Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx

* Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx

---------

Co-authored-by: Jun Lee <junlee@cloudflare.com>
  • Loading branch information
thomasgauvin and Oxyjun authored Oct 11, 2024
1 parent b0697fc commit 26c5dda
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/content/docs/hyperdrive/configuration/rotate-credentials.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
pcx_content_type: concept
title: Rotating database credentials
sidebar:
order: 8
---

import { TabItem, Tabs, Render } from "~/components";

You can change the connection information and credentials of your Hyperdrive configuration in one of two ways:

1. Create a new Hyperdrive configuration with the new connection information, and update your Worker to use the new Hyperdrive configuration.
2. Update the existing Hyperdrive configuration with the new connection information and credentials.

## Use a new Hyperdrive configuration

Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Hyperdrive configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration, and easily roll back to the previous configuration if needed.

To create a Hyperdrive configuration that connects to an existing PostgreSQL database, use the [Wrangler](/workers/wrangler/install-and-update/) CLI or the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers-and-pages/hyperdrive).

```sh
# wrangler v3.11 and above required
npx wrangler hyperdrive create my-updated-hyperdrive --connection-string="<YOUR_CONNECTION_STRING>"
```

The command above will output the ID of your Hyperdrive. Set this ID in the `wrangler.toml` configuration file for your Workers project:

```toml
# required for database drivers to function
compatibility_flags = [ "nodejs_compat" ]
compatibility_date = "2024-09-23"

[[hyperdrive]]
binding = "HYPERDRIVE"
id = "<your-hyperdrive-id-here>"
```

To update your Worker to use the new Hyperdrive configuration, redeploy your Worker or use [gradual deployments](/workers/configuration/versions-and-deployments/gradual-deployments/).

## Update the existing Hyperdrive configuration

You can update the configuration of an existing Hyperdrive configuration using the [wrangler CLI](/workers/wrangler/install-and-update/).

```sh
# wrangler v3.11 and above required
npx wrangler hyperdrive update <HYPERDRIVE_CONFIG_ID> --origin-host <YOUR_ORIGIN_HOST> --origin-password <YOUR_ORIGIN_PASSWORD> --origin-user <YOUR_ORIGIN_USERNAME> --database <YOUR_DATABASE> --origin-port <YOUR_ORIGIN_PORT>
```

:::note
Updating the settings of an existing Hyperdrive configuration does not purge Hyperdrive's cache and does not tear down the existing database connection pool. New connections will be established using the new connection information.
:::

0 comments on commit 26c5dda

Please sign in to comment.