Use Terraform on Google Cloud SQL Postgres to create a Replication Slot

835 Views Asked by At

Overall I'm trying to create a Datastream Connection to a Postgres database in Cloud SQL.

As I'm trying to configure it all through Terraform, I'm stuck on how I should create a Replication Slot. This guide explains how to do it through the Postgres Client and running SQL commands, but I thought there might be a way to do it in the Terraform configuration directly.

Example SQL that I would like to replicate in Terraform:

ALTER USER [CURRENT_USER] WITH REPLICATION;
CREATE PUBLICATION [PUBLICATION_NAME] FOR ALL TABLES;
SELECT PG_CREATE_LOGICAL_REPLICATION_SLOT('[REPLICATION_SLOT_NAME]', 'pgoutput');

If not, does anyone know how to run the Postgres SQL commands against the Cloud SQL database through Terraform?

I have setup the Datastream and Postgres connection for all other parts. I'm expecting that there is a Terraform setting I'm missing or a way to run Postgres commands against the Google Cloud SQL Postgres database.

1

There are 1 best solutions below

1
On

Unfortunately, there is no terraform resource for specifying a replication slot on a google_sql_database_instance.