Skip to content

Add views support on postgresql_grant #247

@toadjaune

Description

@toadjaune

Terraform Version

Terraform v1.2.6
on darwin_arm64
+ provider registry.terraform.io/cyrilgdn/postgresql v1.17.1

Affected Resource(s)

  • postgresql_grant

Terraform Configuration Files

# This resource ignores views
resource "postgresql_grant" "all" {
  database    = "mydb"
  role        = "myrole"
  schema      = "public"
  object_type = "table"
  privileges  = ["SELECT"]
}

# This one grants permissions on the listed views
resource "postgresql_grant" "view" {
  database    = "mydb"
  role        = "myrole"
  schema      = "public"
  object_type = "table"
  objects     = ["my_view"]
  privileges  = ["SELECT"]
}

Debug Output

Not really useful, I can provide it if wanted

Panic Output

None

Expected Behavior

There should be a way to affect all views as well.

Actual Behavior

Granting permissions on views requires explicitly enumerating them.

Steps to Reproduce

  • create a database with at least a table and a view
  • try to grant a permission on "all views" with postgresql_grant

Important Factoids

Nothing specific as far as I can tell.

References

None

Design evolution ideas

The provider kind of works as expected, we're on an edge case here.

I can think of several ways to fix this :

  1. When using postgresql_grant with object_type = "table" and an empty objects list, apply the privileges to views as well.
  2. Add a view object_type, to be able to specify all tables and all views with 2 resources.

Option 1 has my preference, but it's a breaking change (as existing configurations would suddenly grant more privileges), therefore likely requiring a major version release.

I'm also not familiar enough with postgresql's permission system to know if this design is enough. My current concerns are :

  • What happens if you try to give write permissions on a view ? Is it even legal ?
  • What permissions are required to refresh materialized views ? Do we need new valid values in permissions ? If so, do they make sense on a normal table ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions