cyrilgdn / terraform-provider-postgresql

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

[postgresql_default_privileges] no rows in result set #290

Closed dylan-shipwell closed 1 year ago

dylan-shipwell commented 1 year ago

edit: I realized this was a configuration error, I happened to be providing a bad value for postgresql_default_privileges owner. Report filed for posterity.

I would suggest attempting to improve the error message in this case "role becore_admin_super does not exist" maybe with a trace of "caused by ... (existing error)", that would have been more useful to me than "XY problem, caused by: sql result set empty"

│   Error: could not check if role becore_admin_super is superuser: sql: no rows in result set
│   with postgresql_default_privileges.main,
│   on terraform.tf line 201, in resource "postgresql_default_privileges" "main":
│  201: resource "postgresql_default_privileges" "main" {

Terraform Version

Terraform v1.4.2
on linux_amd64
+ provider registry.terraform.io/cyrilgdn/postgresql v1.18.0

Affected Resource(s)

Please list the resources as a list, for example:

Issue only observed with postgresql_default_privileges, issue repro'd on a conventional postgres database (eg testing against https://hub.docker.com/_/postgres )

Terraform Configuration Files

cat terraform.tf
terraform {
  required_providers {
    postgresql = {
      source  = "cyrilgdn/postgresql"
      version = "1.18.0"
    }
  }
}
provider "postgresql" {
  port            = 5432
  host            = "127.0.0.1"
  database        = "postgres"
  username        = "postgres"
  password        = "postgres"
  sslmode         = "disable"
  connect_timeout = 2
  superuser       = false
}
resource "postgresql_default_privileges" "main" {
  database    = "postgres"
  object_type = "sequence"
  owner       = "not_exists"
  privileges = [
    "SELECT"
  ]
  role              = "postgres"
  schema            = "public"
  with_grant_option = false
}

Debug Output

omitted due to user-error

Expected Behavior

What should have happened?

a user-facing "bad configuration" message

Actual Behavior

What actually happened?

a technical-facing "XY" message

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

Are there anything atypical about your accounts that we should know? For example: Running in EC2 Classic? Custom version of OpenStack? Tight ACLs?

I originally interpreted this error to be a limitation of aws rds postgres, (as this was the "detail" that changed between testing on docker and deploying live), however the issue was actually that terraform was initialized with a a module dependency from git, which has since been patched to rename owner field (that role is created by the same module when the user supplies a password, however the user was supplying a password for a now-nonexistent role, rather than the renamed role)

this was ultimately resolved by clearing terraform module cache, eg terraform get -update or rm -r .terraform/; terraform init

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

no.