-
Notifications
You must be signed in to change notification settings - Fork 278
Description
Hi there,
Thank you for opening an issue. Please provide the following information:
Terraform Version
Terraform v1.1.9
on darwin_amd64
- provider registry.terraform.io/cyrilgdn/postgresql v1.16.0
Affected Resource(s)
- postgresql_grant
Terraform Configuration Files
resource "postgresql_grant" "test-grant" {
database = "db"
role = "test-role"
schema = "public"
object_type = "table"
objects = ["table-one"]
privileges = ["SELECT"]
}Expected Behavior
When changing the objects from ["table-one"] to ["table-one", "table-two"], the permissions should be revoked / granted atomatically, so that existing systems querying the database don't temporarily see errors.
Actual Behavior
Because of the way objects was implemented in #105 (specifically, the ForceNew schema flag), Terraform forces the plan to destroy and recreate the grant which does not happen within the same postgres transaction. Therefore, postgres roles using the "SELECT" permission on "table-one" temporarily see errors for a little while when Terraform has deleted but not yet recreated the permission grants.
Steps to Reproduce
- create a postgres db with a test schema
- create a testing role and apply the tf code from above
- Connect to postgres using the test role
- Continously run statements such as
select count(*) from "table-one"; - change the
objects = ["table-one"]line toobjects = ["table-one", "table-two"]and apply the changes through terraform - Keep running your count(*) statement, you will see some errors for ~1 second while the system revokes / issues new permissions.
Question
Are there any smart workarounds for this? For testing and dev purposes, this behaviour is OK, but for production systems that are running hundreds of queries per second through a role managed with this provider, seeing errors for about a second is something I would definitely like to avoid. Thank you!