cyrilgdn / terraform-provider-postgresql

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

Update document for postgresql_default_privileges resource #467

Open caodangtinh opened 1 month ago

caodangtinh commented 1 month ago

Hi, the documentation of the owner, role and privileges arguments in the postgresql_default_privileges resource is quite unclear now. Current documentation

role - (Required) The name of the role to which grant default privileges on.

owner - (Required) Role for which apply default privileges (You can change default privileges only for objects that will be created by yourself or by roles that you are a member of).

privileges - (Required) The list of privileges to apply as default privileges. An empty list could be provided to revoke all default privileges for this role.

Suggest documentation

role - (Required) The role that will automatically be granted the specified privileges on new objects created by the owner.

owner - (Required) Specifies the role that creates objects for which the default privileges will be applied. You can change default privileges only for objects that will be created by yourself or by roles that you are a member of.

privileges - (Required) List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.

Add a new example for granting privileges.

Grant default privileges for tables to "current_role" role:

resource "postgresql_default_privileges" "grant_table_privileges" {
  database    = postgresql_database.example_db.name
  role        = "current_role"
  owner       = "owner_role"
  schema      = "public"
  object_type = "table"
  privileges  = ["SELECT", "INSERT", "UPDATE"]
}

Whenever the owner_role creates a new table in the public schema, the current_role is automatically granted SELECT, INSERT, and UPDATE privileges on that table.

caodangtinh commented 1 month ago

Pull Request: https://github.com/cyrilgdn/terraform-provider-postgresql/pull/468