terraform-provider-postgresql icon indicating copy to clipboard operation
terraform-provider-postgresql copied to clipboard

Adding a grant to an x role is trying to add a role to the postgres role

Open kodless opened this issue 11 months ago • 0 comments

Terraform Version

1.9.6

Provider Version

1.24.0

Affected Resource(s)

  • postgresql_grant

Terraform Configuration Files

provider "postgresql" {
  alias     = "qa-authz"
  host      = "rds.endpoint"
  username  = "postgres"
  password  = "redacted"
  database  = "postgres"
  sslmode   = "require"
  superuser = false
  port      = 5432
}

resource "postgresql_role" "role" {
  password                  = "REDACTED"
  name                      = "debezium"
  skip_reassign_owned       = false
  login                     = true
  roles                     = [ "rds_replication", "readonly_role" ]
  bypass_row_level_security = true
  create_database           = false
  replication               = false
  statement_timeout         = null
}

resource "postgresql_grant" "grant" {
  role              = postgresql_role.role.name
  database          = "authorizer"
  schema            = "kafka"
  object_type       = "table"
  privileges        = [ "INSERT", "SELECT", "UPDATE", "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER" ]
  objects           = [ "debezium_snapshot_signals" ]
  with_grant_option = false
}

Debug Output

https://gist.github.com/kodless/f1f3da77b81e95f5a73b94b6373bcf31

Expected Behavior

Add a new grant for debezium role.

Actual Behavior

The provider is trying to grant the role authorizer_migrate to postgres role which is confusing.

2024-12-02 17:18:21 UTC:10.141.121.97(48032):postgres@authorizer:[8008]:STATEMENT:  GRANT "authorizer_migrate" TO "postgres"
2024-12-02 17:18:21 UTC:10.141.121.97(48032):postgres@authorizer:[8008]:ERROR:  role "authorizer_migrate" is a member of role "postgres"

Steps to Reproduce

  1. terraform apply

Important Factoids

Running on Terraform Cloud

kodless avatar Dec 04 '24 12:12 kodless