Skip to content
This repository has been archived by the owner on Nov 14, 2020. It is now read-only.

postgresql_default_privileges grantRoleMembership fails when username != role #130

Open
OscartGiles opened this issue Apr 16, 2020 · 1 comment

Comments

@OscartGiles
Copy link

Terraform Version

Terraform v0.12.24

  • provider.azuread v0.8.0
  • provider.azurerm v1.44.0
  • provider.external v1.2.0
  • provider.postgresql v1.5.0
  • provider.random v2.2.1
  • provider.template v2.1.2

Affected Resource(s)

Please list the resources as a list, for example:

  • postgresql_default_privileges
  • postgresql

Expected Behavior

When running :

resource  "postgresql_default_privileges" "read_only_tables" {
  role     = "test_role"
  database = "test_db"
  schema   = "public"

  owner       = "db_owner"
  object_type = "table"
  privileges  = ["SELECT"]
}

where db_owner is the role of the user(db_owner@<host>) given to the provider, we expect this to execute: https://github.com/terraform-providers/terraform-provider-postgresql/blob/3e2ad5faafb4c74b8a688d2c03dd633841f3f941/postgresql/resource_postgresql_default_privileges.go#L243

Actual Behavior

Error message:

Error: Error granting role db_owner to db_owner@<host>: pq: role "db_owner@<host>" does not exist.

It looks like it should check if "db_owner" is the same role as that of the user given to the provider and in this case return at line 53:

https://github.com/terraform-providers/terraform-provider-postgresql/blob/3e2ad5faafb4c74b8a688d2c03dd633841f3f941/postgresql/helpers.go#L51-L54

However, it seems to check the username against the role:

https://github.com/terraform-providers/terraform-provider-postgresql/blob/3e2ad5faafb4c74b8a688d2c03dd633841f3f941/postgresql/resource_postgresql_default_privileges.go#L104

https://github.com/terraform-providers/terraform-provider-postgresql/blob/3e2ad5faafb4c74b8a688d2c03dd633841f3f941/postgresql/resource_postgresql_default_privileges.go#L117

and so presumably it runs:

GRANT db_owner to "db_owner@<host> 

which errors

@siwon
Copy link

siwon commented Aug 6, 2020

Same error here 😦

Impact is : postgresql_default_privileges doesn't work with Azure PostreSQL resources ...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants