In the Aiven console, you could use "Create a read replica" to create a read replica from an existing PostgreSQL or MySQL service:

The same can be achieved using the Aiven Terraform provider by using service integrations which need to be specified at service creation time.

A terraform file example (test was done on Aiven Terraform provider version 2.3.2, other versions may get slightly different results) is shown below for creating a read replica:

terraform {
required_providers {
aiven = {
source = "aiven/aiven"
version = ">= 2.2.1, < 3.0.0"
}
}
}

provider "aiven" {
api_token = var.aiven_api_token
}

locals {
project = "mischa-demo"
}

data "aiven_project" "my_project" {
project = local.project
}

resource "aiven_mysql" "my" {
project = local.project
cloud_name = "google-europe-west1"
service_name = "mischa-mysql-31c29b"
plan = "startup-4"
termination_protection = false

mysql_user_config {
admin_username = "avnadm"
mysql_version = "8"

mysql {
sql_mode = "ANSI,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE"
sql_require_primary_key = true
}

public_access {
mysql = true
}
}
}

resource "aiven_mysql" "my_read_replica" {
project = local.project
cloud_name = "google-europe-west1"
service_name = "mischa-mysql-replica"
plan = "startup-4"
maintenance_window_dow = "saturday"
maintenance_window_time = "07:45:00"
termination_protection = false

service_integrations {
integration_type = "read_replica"
source_service_name = aiven_mysql.my.service_name
}

mysql_user_config {
service_to_fork_from = aiven_mysql.my.service_name
}

depends_on = [
aiven_mysql.my,
]
}

Now sign in to the console and observe your new read replica being created:

If you encounter any problems with our Terraform integration or have improvement suggestions, please let us know. You can either contact our support directly or use Github issues for submitting your issue / improvement.

Did this answer your question?