terraform-provider-postgresql icon indicating copy to clipboard operation
terraform-provider-postgresql copied to clipboard

concurrency issue when granting privileges on tables with postgresql_grant

Open vedata opened this issue 1 year ago • 1 comments

Hi there,

We're encountering a persistent issue during the execution of Terraform apply, consistently receiving the error message: "Error: Could not execute revoke query: pq: tuple concurrently updated." Despite upgrading the provider to cyrilgdn/postgresql 1.18.0, the error remains unresolved

Terraform Version

Terraform v1.5.0

Affected Resource(s)

  • postgresql_grant

Terraform Configuration Files

resource "postgresql_grant" "rw_role_table_crud" {
  depends_on = [postgresql_schema.public]
  count      = var.create_rw_role ? 1 : 0

  database    = postgresql_database.service_database[0].name
  role        = postgresql_role.rw_role[0].name
  object_type = "table"
  schema      = "public"
  privileges  = ["INSERT", "SELECT", "UPDATE", "DELETE", "TRUNCATE"]
}

resource "postgresql_grant" "ro_role_table_crud" {
  depends_on = [postgresql_schema.public]
  count      = var.create_ro_role ? 1 : 0

  database    = postgresql_database.service_database[0].name
  role        = postgresql_role.ro_role[0].name
  object_type = "table"
  schema      = "public"
  privileges  = ["SELECT"]
}

Expected Behavior

resource "postgresql_grant" "rw_role_table_crud" { depends_on = [postgresql_schema.public] count = var.create_rw_role ? 1 : 0

database = postgresql_database.service_database[0].name role = postgresql_role.rw_role[0].name object_type = "table" schema = "public" privileges = ["INSERT", "SELECT", "UPDATE", "DELETE", "TRUNCATE"] }

resource "postgresql_grant" "ro_role_table_crud" { depends_on = [postgresql_schema.public] count = var.create_ro_role ? 1 : 0

database = postgresql_database.service_database[0].name role = postgresql_role.ro_role[0].name object_type = "table" schema = "public" privileges = ["SELECT"] }

Actual Behavior

│ Error: could not execute revoke query: pq: tuple concurrently updated │ │ with module.cp-database.postgresql_grant.rw_role_table_crud[0], │ on ../../modules/postgresql-db/main.tf line 155, in resource "postgresql_grant" "rw_role_table_crud": │ 155: resource "postgresql_grant" "rw_role_table_crud" { │ ╵ ╷ │ Error: could not execute revoke query: pq: tuple concurrently updated │ │ with module.cp-database.postgresql_grant.ro_role_table_crud[0], │ on ../../modules/postgresql-db/main.tf line 244, in resource "postgresql_grant" "ro_role_table_crud": │ 244: resource "postgresql_grant" "ro_role_table_crud" { │ ╵

Steps to Reproduce

  1. terraform apply

Important Factoids

The DB is running on AWS RDS with Engine version: 13.11

References

  • GH-224

vedata avatar Mar 28 '24 12:03 vedata

Same issue for us, need to apply several times.

enricojonas avatar Apr 03 '24 14:04 enricojonas

Removed table lock in DB

vedata avatar May 03 '24 14:05 vedata