In Aiven console, if you use "service integrations" to create a read replica from an existing PostgreSQL or MySQL service, there is an option for the read replica service to "Promote to master" :

While it's not explicitly mentioned in Terraform how to promote the read replica to master. You can remove the service integration between to accomplish the task.

An tf file example (test was done on Terraform version 2.1.15, other version may get slightly different) can be found as following for creating a read replica "pg-replica" from "pg-aiqin":

terraform {
required_providers {
aiven = {
source = "aiven/aiven"
version = "2.1.15"
}
}
}

variable "aiven_api_token" {
type = string
}

provider "aiven" {
api_token = var.aiven_api_token
}

resource "aiven_pg" "pg" {
project = "test"
cloud_name = "google-australia-southeast1"
plan = "startup-4"
service_name = "pg-aiqin"
pg_user_config {
pg_version = "12"
}
}

resource "aiven_pg" "pg2" {
project = "test"
cloud_name = "google-europe-west1"
plan = "startup-4"
service_name = "pg-replica"
service_integrations {
integration_type = "read_replica"
source_service_name = aiven_pg.pg.service_name
}
}

resource "aiven_service_integration" "pg-readreplica" {
project = "test"
integration_type = "read_replica"
source_service_name = aiven_pg.pg.service_name
destination_service_name = aiven_pg.pg2.service_name
}

You can get the read replica promoted to master by removing resource "aiven_service_integration" and "service_integrations" under the "pg-replica" above.

If you encounter any problems with the 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?