cyrilgdn / terraform-provider-postgresql

Terraform PostgreSQL provider
https://www.terraform.io/docs/providers/postgresql/
Mozilla Public License 2.0
356 stars 181 forks source link

postgresql_publication does not accept filters #350

Open pancochea opened 9 months ago

pancochea commented 9 months ago

Hi,

we want to create publications using the postgresql_publication resource, starting from postgresql 15, publication accepts filtering using WHERE statements after the table. Currently this feature can be forced by defining the table as follows:

resource "postgresql_publication" "this" {
  name  = "user_publication"
  tables = [
    "schema.user where (user_id > 1)"
  ]
}

This configuration creates the publication with the filter set. But it then detects the table as changed because the state is retrieved using only schema.table directly from the database.

https://www.postgresql.org/docs/current/sql-createpublication.html

Affected Resource(s)

postgresql_publication

Expected Behavior

A filtered publication is created and is not detected as change.

Actual Behavior

The table is detected as a change and tries to re-create, causing an error.

Steps to Reproduce

Create a publication which uses filtering for a table using the statement in the example. After the publication is correctly created run terraform plan and the filter is removed thus detecting a change and failing

Important Factoids

This issue is caused by how the name of current publications is retrieved, where rowfilter colum is not considered.

References

Documentation