Manage Databases 🛢️ with Terraform

This tutorial is part of the Bytebase Terraform Provider series:

Part 1: Manage Environments with Terraform – Set up environments with policies
Part 2: Manage Databases with Terraform 👈
Part 3: Manage Projects with Terraform – Organize databases into…


This content originally appeared on DEV Community and was authored by Ayra Jett

This tutorial is part of the Bytebase Terraform Provider series:

This tutorial series uses separate Terraform files for better organization. Files are numbered bytutorial part and sub-step (e.g., 1-1-env-setting.tf, 1-2-env-policy-rollout.tf for Part 1, 2-instances.ti for Part 2, etc.). Terraform automatically handles dependencies between files.

View sample code

What You'll Learn

Register database instances in Bytebase using Terraform.

Prerequisites

Before starting this tutorial, ensure you have:

  • Completed Part 1:
    • Bytebase running with built-in sample data
    • Service account created
    • Terraform initialized
    • Environments configured

Step 1 - Explore Built-in Instances

Bytebase sample data includes two sample PostgreSQL instances. Let's explore them:

  1. In Bytebase, click Instances on the left sidebar. You'll see two PostgreSQL instances:
  • Test Sample Instance (port 8083)
  • Prod Sample Instance (port 8084)
  1. Click +Add Instance, you may add more database instances.

  1. Click Projects on the left sidebar to see the Sample Project, then click it. You'll see:
  • hr_test database on Test instance
  • hr_prod database on Prod instance
  1. Click + New DB, you may create more databases on the existing instances.

Step 2 - Register Instances with Terraform

Now let's import these instances into Terraform management.

Terraform resource bytebase_instance
Sample file 2-instances.tf

Create 2-instances.tf with the following configuration:

```hcl 2-instances.tf

Test Sample Instance - PostgreSQL on port 8083

resource "bytebase_instance" "test" {
depends_on = [bytebase_setting.environments]
resource_id = "test-sample-instance"
environment = "environments/test"
title = "Test Sample Instance"
engine = "POSTGRES"
# Assign instance license
activation = true

# Connection settings for the built-in test database
data_sources {
id = "admin-test"
type = "ADMIN"
host = "/tmp" # Unix socket for local connection
port = "8083"
username = "bbsample"
password = "" # Empty for local auth
}
}

Production Sample Instance - PostgreSQL on port 8084

resource "bytebase_instance" "prod" {
depends_on = [bytebase_setting.environments]
resource_id = "prod-sample-instance"
environment = "environments/prod"
title = "Prod Sample Instance"
engine = "POSTGRES"
activation = true

data_sources {
id = "admin-prod"
type = "ADMIN"
host = "/tmp"
port = "8084"
username = "bbsample"
password = ""
}
}




**Understanding the Configuration**

- **depends_on**: Ensures environments from Part 1 exist first
- **resource_id**: Must match the existing instance ID
- **environment**: Links instance to Test or Prod environment
- **data_sources**: Connection details for the database

## Step 3 - Apply Configuration

Now apply the configuration:



```bash
terraform plan
terraform apply

Step 4 - Verify Setup

  1. Go to Instances in Bytebase.
  2. Verify both instances show:
    • Correct environment assignment
    • Y under License column (if using Enterprise)

You can now modify instance properties through Terraform. For example, to rename an instance:

resource "bytebase_instance" "test" {
  # ... other config ...
  title = "Development Database"  # Changed title
}

Further Reading: Manage Projects with Terraform


This content originally appeared on DEV Community and was authored by Ayra Jett


Print Share Comment Cite Upload Translate Updates
APA

Ayra Jett | Sciencx (2025-07-22T07:18:03+00:00) Manage Databases 🛢️ with Terraform. Retrieved from https://www.scien.cx/2025/07/22/manage-databases-%f0%9f%9b%a2%ef%b8%8f-with-terraform/

MLA
" » Manage Databases 🛢️ with Terraform." Ayra Jett | Sciencx - Tuesday July 22, 2025, https://www.scien.cx/2025/07/22/manage-databases-%f0%9f%9b%a2%ef%b8%8f-with-terraform/
HARVARD
Ayra Jett | Sciencx Tuesday July 22, 2025 » Manage Databases 🛢️ with Terraform., viewed ,<https://www.scien.cx/2025/07/22/manage-databases-%f0%9f%9b%a2%ef%b8%8f-with-terraform/>
VANCOUVER
Ayra Jett | Sciencx - » Manage Databases 🛢️ with Terraform. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/22/manage-databases-%f0%9f%9b%a2%ef%b8%8f-with-terraform/
CHICAGO
" » Manage Databases 🛢️ with Terraform." Ayra Jett | Sciencx - Accessed . https://www.scien.cx/2025/07/22/manage-databases-%f0%9f%9b%a2%ef%b8%8f-with-terraform/
IEEE
" » Manage Databases 🛢️ with Terraform." Ayra Jett | Sciencx [Online]. Available: https://www.scien.cx/2025/07/22/manage-databases-%f0%9f%9b%a2%ef%b8%8f-with-terraform/. [Accessed: ]
rf:citation
» Manage Databases 🛢️ with Terraform | Ayra Jett | Sciencx | https://www.scien.cx/2025/07/22/manage-databases-%f0%9f%9b%a2%ef%b8%8f-with-terraform/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.