Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] When changing owner of database, change ownership of all objects by providing an additional flag #439

Closed
lukaalba opened this issue May 8, 2024 · 1 comment · Fixed by #458

Comments

@lukaalba
Copy link
Contributor

lukaalba commented May 8, 2024

Hi there,

I would like to request an additional flag for the postgresql_database-resource. Although it is possible to change the owner of the database itself with this resource, the owner of already created tables or sequences in this database is not altered. I would like to suggest an additional flag to be able to alter those objects, too, e.g.:

Terraform Configuration Files

resource "postgresql_database" "my_db" {
  name              = "my_db"
  owner             = "my_role"
  template          = "template0"
  lc_collate        = "C"
  connection_limit  = -1
  allow_connections = true
  alter_object_ownership = true
}

If this feature request turns out to be useful, I am happy to provide a PR.

@melihsunbul
Copy link

Hi, it would be actually quite helpful.

cyrilgdn added a commit that referenced this issue Sep 8, 2024
#458)

Hi,

this is my first Pull Request, so if something is missing or wrong, let
me know.

To resolve
[439](#439)
I suggest to add an additional parameter to the database resource called
`alter_object_ownership`. If set to true, it will issue a REASSIGN OWNED
BY query on the database when the owner changes, transfer the whole
ownership in the database from the previous owner to the new one.

As far as I can tell this is only possible if the user in the provider
configuration is a superuser or a user which has grants for both the
previous owner role and the new one. So I skipped the test in the
rds-like test suite.

---------

Co-authored-by: Lukas Albani <[email protected]>
Co-authored-by: Cyril Gaudin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants