The redshift_privilege resource currently creates grants but also runs ALTER DEFAULT PRIVILEGES. This appears to be due to a misunderstanding of how default privileges work in Redshift.
Per https://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_DEFAULT_PRIVILEGES.html:
Defines the default set of access privileges to be applied to objects that are created in the future by the specified user.
...
FOR USER target_user
Optional. The name of the user for which default privileges are defined... The default value is the current user.
Default privileges are essentially grants that are automatically applied when a particular user creates an object. In other words, if you do:
resource "redshift_privilege" "readonly_tables" {
group = "test_group"
schema = "public"
object_type = "table"
privileges = ["SELECT"]
}
What actually runs is this:
ALTER DEFAULT PRIVILEGES
IN SCHEMA "public"
GRANT SELECT ON TABLES
TO GROUP "test_group"
which is equivalent to this:
ALTER DEFAULT PRIVILEGES
FOR USER CURRENT_USER
IN SCHEMA "public"
GRANT SELECT ON TABLES
TO GROUP "test_group"
which actually means the select permissions will only be given on new tables created by whoever ran terraform.
If what we're really trying to achieve here is for test_group to have select permissions on newly created tables in public then what we actually have to do is run something akin to:
-- redshift doesn't actually support a for loop like this,
-- but you get the idea.
FOR db_user IN (SELECT usename FROM pg_user) DO
ALTER DEFAULT PRIVILEGES
FOR USER db_user
IN SCHEMA "public"
GRANT SELECT ON TABLES
TO GROUP "test_group"
END FOR
The
redshift_privilegeresource currently creates grants but also runsALTER DEFAULT PRIVILEGES. This appears to be due to a misunderstanding of how default privileges work in Redshift.Per https://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_DEFAULT_PRIVILEGES.html:
Default privileges are essentially grants that are automatically applied when a particular user creates an object. In other words, if you do:
What actually runs is this:
which is equivalent to this:
which actually means the select permissions will only be given on new tables created by whoever ran terraform.
If what we're really trying to achieve here is for
test_groupto have select permissions on newly created tables inpublicthen what we actually have to do is run something akin to: