Terraform for DBaaS
You can use the Terraform Exoscale Provider to manage your DBaaS resources.
Provider Configuration
In the provider configuration, we define some variables that will be used later in the examples:
terraform {
required_providers {
exoscale = {
source = "exoscale/exoscale"
}
}
}
provider "exoscale" {
key = "${var.exoscale_api_key}"
secret = "${var.exoscale_secret_key}"
}
variable "exoscale_api_key" {
default = "api_key_value_here"
}
variable "exoscale_secret_key" {
default = "api_secret_key_value_here"
}
variable "database_username" {
default = "database_username_here"
}
variable "database_password" {
default = "database_password_here"
}
# Customizable parameters
locals {
my_zone = "ch-gva-2"
}
To manage the databases in multiple zones, you need to create
multiple provider configurations, each with a different alias
.
For more information, you can check Terraform’s provider configuration documentation.
Manage Your Databases
Create a PostgreSQL Database
resource "exoscale_dbaas" "postgres" {
name = "databasename"
plan = "hobbyist-2"
type = "pg"
zone = local.my_zone
pg {
admin_username = "${var.database_username}"
admin_password = "${var.database_password}"
ip_filter = ["0.0.0.0/0"]
version = "16"
}
}
You can find the nested options for PostgreSQL here
Create a Kafka Service
resource "exoscale_dbaas" "kafka" {
name = "databasename"
plan = "startup-2"
type = "kafka"
zone = local.my_zone
kafka {
enable_cert_auth = true
enable_kafka_connect = false
enable_kafka_rest = false
enable_sasl_auth = false
enable_schema_registry = false
ip_filter = ["0.0.0.0/0"]
version = "3.8"
}
}
You can find the nested options specific for Kafka here.
Create a MySQL Database
resource "exoscale_dbaas" "mysql" {
name = "databasename"
plan = "startup-8"
type = "mysql"
zone = local.my_zone
mysql {
admin_username = "${var.database_username}"
admin_password = "${var.database_password}"
ip_filter = ["0.0.0.0/0"]
version = "8"
}
}
You can find the nested options specific for MySQL here
Create a Valkey Instance
resource "exoscale_dbaas" "valkey" {
name = "databasename"
plan = "startup-8"
type = "valkey"
zone = local.my_zone
valkey {
ip_filter = ["0.0.0.0/0"]
}
}
You can find the nested options specific for Valkey here
Create a Grafana Instance
resource "exoscale_dbaas" "grafana" {
name = "grafana"
plan = "hobbyist-2"
type = "grafana"
zone = local.my_zone
grafana {
ip_filter = ["0.0.0.0/0"]
}
}
You can find the nested options specific for Grafana here
Create an OpenSearch Instance
resource "exoscale_dbaas" "opensearch" {
name = "databasename"
plan = "hobbyist-2"
type = "opensearch"
zone = local.my_zone
opensearch {
ip_filter = ["0.0.0.0/0"]
}
}
You can find the nested options specific for OpenSearch here