-
Notifications
You must be signed in to change notification settings - Fork 79
Managing destruction of Postgres DBs in RDS #17
Comments
@tomelliff I've been trying to apply same solution that you suggested as a temp workaround and from some unknown reason the role is granted only to the regular user and not to the admin user:
I than use pgAdmin to review db properties and see that my admin user (postgres) didn't get the "eran2_group" membership. any insights? |
Yeah I noticed the same thing after posting it. I'm not sure what's wrong with using the local exec but the grant doesn't seem to get added at all when ran from it but running the same command locally does seem to work. It doesn't seem to be a timing thing either because when I added another local exec provisioner running the same command I got a warning that the role already had that grant (can't remember the exact wording) but it didn't. I'm not that experienced with Postgres though so I might be missing something stupid but it stumped me too. For now I'm leaving my Terraform unable to destroy stuff and where necessary I'm locally running Terraform with the provisioner built from my branch to tear things down (or just removing the state for the database and role resources first as I'm going to tear down the RDS instance anyway). |
I assume that the reason for the admin user not receiving the group membership is that this user is being used by terraform in an active connection so perhaps it can't be modified while the connection is active. makes sense? |
Doesn't look that way because the connected user is added to the owner's role when creating the database. My pull request simply copies that block (including the |
I have spent some time on this and discovered why this does not work.
It seems the postgresql provider adds the system user into the newly created role so he seems like a superuser, but removes it after the setup is finishied. Unfortunatelly the same thing does not happen when destroying. |
@honzasterba I raised a pull request for that here: #18 |
Please try |
Just tried this now after building master and looks like it works as expected, thanks for the merge. |
I managed to nicely get Terraform creating databases and roles in an RDS Postgres database but due to the stripped down permissions of the
rds_superuser
I can't see an easy way to destroy the created databases that are owned by another user.Using the following config:
leads to this error:
Using local-exec provisioners I was able to grant the role that owned the database to the admin user and the application user:
which seems to work compared to setting ownership only for the app user. I do wonder if there's a better way I can do this without having to shell out in a local-exec though?
The text was updated successfully, but these errors were encountered: