Open talbenari-okta opened 4 months ago
Hi @talbenari-okta ,
Thanks for opening this well-detailed issue and sorry for the response delay.
I get the problem and indeed, provider will not read the state of the partitioned tables because of the relkind
.
However, during my tests, I don't have the same behavior than you.
The grant works successfully, the only thing that doesn't work is that the provider will not fix the partitioned table permissions if they are modified manually.
Can you share an example of code and/or detail how to reproduce your issue?
Do you target specific table with your grant or all tables of the schema?
Thanks in advance.
Description
The provider is able to
CREATE
grants on partitioned tables, but is not able to see the grants upon a subsequentSELECT
. This leads to the following problems:CREATE
the grants on each subsequentapply
, because it doesn't know the grants already existRoot Cause
Essentially, the problem is that the
SELECT
query is doing this:https://github.com/cyrilgdn/terraform-provider-postgresql/blob/a961e75c59b360f901020c612deef1e1da8ecfea/postgresql/resource_postgresql_grant.go#L347-L353
The value being passed in for
$4
(relkind
) isobjectTypes["table"]
, whereobjectTypes
is defined here:https://github.com/cyrilgdn/terraform-provider-postgresql/blob/a961e75c59b360f901020c612deef1e1da8ecfea/postgresql/resource_postgresql_grant.go#L29-L35
This
objectTypes
definition is a map from resource type to the corresponding Postgres entry for thepg_default_acl.defaclobjtype
. However,pg_class.relkind
does not user
for partitioned tables - it usesp
.A similar issue exists here: https://github.com/cyrilgdn/terraform-provider-postgresql/blob/a961e75c59b360f901020c612deef1e1da8ecfea/postgresql/resource_postgresql_grant.go#L475
Recommended Fix
And pass in a slice of all
relkind
values that correspond to the"table"
object.Terraform Version
Applies to all versions of Terraform.
Affected Resource(s)
postgresql_grant
References
Someone had found this previously: https://github.com/cyrilgdn/terraform-provider-postgresql/issues/141#issuecomment-944577517. Since the issue was already closed, I imagine it didn't get visibility.
This has existed since the introduction of the
postgresql_grant
resource in https://github.com/cyrilgdn/terraform-provider-postgresql/commit/d9f18f39fc37eb81f78b73f3f022a69d9f666d5c. When column-level grants were introduced in #135, this issue was carried over to that as well.