Skip to content

Created postgresql deployment modules based on field experience#22

Open
mateofloreza wants to merge 1 commit into
canonical:mainfrom
mateofloreza:feature/field-postgres-deployment
Open

Created postgresql deployment modules based on field experience#22
mateofloreza wants to merge 1 commit into
canonical:mainfrom
mateofloreza:feature/field-postgres-deployment

Conversation

@mateofloreza
Copy link
Copy Markdown

Description

This PR adds a new Terraform module for deploying PostgreSQL, based on real-world field experience. The module is designed for flexibility and integrates with existing infrastructure modules.

Type

  • [ x ] Add module.

How to test

terraform init
terraform apply

@jnsgruk
Copy link
Copy Markdown
Member

jnsgruk commented Jul 17, 2025

Thanks for this. I'll work with the SQL team to look at getting this merged.

One thing I'd suggest in the mean time is a simple README.md in each of the directories with a synopsis of what is being deployed. The PR description is a little light, and a description of what each module does in the repo will also help people who come across it in the future :)

Copy link
Copy Markdown

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making us better!
Can you please add README.md to each module, showing the right way to deploy/apply it.
Great example is https://github.com/canonical/observability-stack/blob/main/terraform/cos-lite/README.md

I didn't manage to deploy it locally as some options have no meaning to me and descriptions was confusing (see inline).

Some mistakes available: e.g. no relations to tls operator at all OR reusing the same subordinate grafana-agent for different principals. Otherwise, I believe it is a good start! Let's make it deployable, document it and merge.

Thank you!

@@ -0,0 +1,85 @@
resource "juju_machine" "postgresql" {
model = var.juju_model_name
base = "ubuntu@22.04"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move hardcoded base to the variable.

Comment on lines +114 to +116
variable "oam_space" {
description = "OAM space"
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mandatory option I do not see in code. Leftover?

resource "juju_application" "data_integrator" {
name = "data-integrator-${var.postgresql_database_name}"
model = var.juju_model_name
trust = true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, trust is applicable for K8s only. Is it necessary here?

Comment on lines +24 to +27
variable "postgresql_endpoints" {
description = "Postgresql endpoint bindings"
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what is postgresql_endpoints? I am not a newbie in Charmed PostgreSQL/Juju, but I do not know what to provide here. Tnx!

Juju spaces?

I see it has been copy&pasted via all applications, please add details here.

resource "juju_application" "backups_s3_integrator" {
name = "backups-s3-integrator"
model = var.juju_model_name
trust = true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

Comment on lines +25 to +47
resource "juju_integration" "grafana-postgresql" {
model = var.juju_model_name
application {
name = juju_application.machine_postgresql.name
endpoint = "cos-agent"
}
application {
name = juju_application.grafana_agent.name
endpoint = "cos-agent"
}
}

resource "juju_integration" "grafana-pgbouncer" {
model = var.juju_model_name
application {
name = juju_application.pgbouncer.name
endpoint = "cos-agent"
}
application {
name = juju_application.grafana_agent.name
endpoint = "cos-agent"
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The grafana-agents for PostgreSQL and PgBouncers must be a different Juju applications. See: https://charmhub.io/pgbouncer/docs/h-enable-monitoring

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see self_signed_certificates application defined/deployed but not related to any charms. Expected?
IMHO it should be related to PG, PGB at least.

resource "juju_application" "machine_postgresql" {
name = var.postgresql_application_name
model = var.juju_model_name
trust = true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below, is trust=true necessary for K8s only?

Comment on lines +33 to +35
variable "total_units" {
description = "Total postgresql units"
}
Copy link
Copy Markdown

@taurus-forever taurus-forever Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use common practice: postgresql_charm_units

Comment on lines +110 to +112
variable "oam_space" {
description = "OAM space"
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftovers?

@taurus-forever
Copy link
Copy Markdown

taurus-forever commented Jul 18, 2025

@mateofloreza after the checking this PR in details, IMHO, we should go the proper direction instead of copy&pasting everything into one module.

Please check our improvements in the official PG module: canonical/postgresql-operator#1052 (and README.md)

This will allow you to use PG module in your TF plan, working example: #23

Can you please update your PR accordingly? Maybe it worth to start with one module first, e.g. your postgresql-single-vm and then switch to pgbouncer once we merge the first module. WDYT?

P.S. I am on the vacation the next week, but I will monitor this thread.

@hloeung hloeung removed the request for review from a team November 22, 2025 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants