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_grant: Error: could not execute revoke query: pq: zero-length delimited identifier at or near """" #451

Open loganmzz opened 5 days ago

loganmzz commented 5 days ago

Terraform Version

Terraform v1.5.7

Affected Resource(s)

Terraform Configuration Files

resource "postgresql_grant" "public_database_connect" {
  database    = "test_db"
  role        = "test_role"
  schema      = "public"
  object_type = "database"
  privileges  = ["CONNECT"]
}

Debug Output

2024-07-02T10:53:59.095+0200 [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/cyrilgdn/postgresql/1.22.0/linux_amd64/terraform-provider-postgresql_v1.22.0 pid=196227
2024-07-02T10:53:59.095+0200 [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/cyrilgdn/postgresql/1.22.0/linux_amd64/terraform-provider-postgresql_v1.22.0
2024-07-02T10:53:59.105+0200 [INFO]  provider.terraform-provider-postgresql_v1.22.0: configuring server automatic mTLS: timestamp=2024-07-02T10:53:59.105+0200
2024-07-02T10:53:59.123+0200 [DEBUG] provider: using plugin: version=5
2024-07-02T10:53:59.123+0200 [DEBUG] provider.terraform-provider-postgresql_v1.22.0: plugin address: network=unix address=/tmp/plugin3940814070 timestamp=2024-07-02T10:53:59.123+0200
2024-07-02T10:53:59.138+0200 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/cyrilgdn/postgresql\"]" changed the config value, but that value is unused
2024-07-02T10:53:59.142+0200 [WARN]  Provider "registry.terraform.io/cyrilgdn/postgresql" produced an invalid plan for postgresql_grant.public_database_connect, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .with_grant_option: planned value cty.False for a non-computed attribute
2024-07-02T10:53:59.142+0200 [INFO]  Starting apply for postgresql_grant.public_database_connect
2024-07-02T10:53:59.143+0200 [DEBUG] postgresql_grant.public_database_connect: applying the planned Create change
2024-07-02T10:54:00.469+0200 [ERROR] provider.terraform-provider-postgresql_v1.22.0: Response contains error diagnostic: tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.15.0/tfprotov5/internal/diag/diagnostics.go:55 diagnostic_severity=ERROR diagnostic_summary="could not execute revoke query: pq: zero-length delimited identifier at or near """"" tf_req_id=203472e2-3fc8-96b5-5e6c-46c4de71e634 tf_provider_addr=provider tf_resource_type=postgresql_grant @module=sdk.proto diagnostic_detail= tf_proto_version=5.3 timestamp=2024-07-02T10:54:00.469+0200
2024-07-02T10:54:00.470+0200 [DEBUG] State storage *remote.State declined to persist a state snapshot
2024-07-02T10:54:00.470+0200 [ERROR] vertex "postgresql_grant.public_database_connect" error: could not execute revoke query: pq: zero-length delimited identifier at or near """"

Panic Output

N/A

Expected Behavior

Success

Actual Behavior

Failing by executing unknown invalid SQL request:

│ Error: could not execute revoke query: pq: zero-length delimited identifier at or near """"
│ 
│   with postgresql_grant.public_database_connect,
│   on pgsql.tf line 181, in resource "postgresql_grant" "public_database_connect":
│  181: resource "postgresql_grant" "public_database_connect" {

Steps to Reproduce

  1. terraform apply

Important Factoids

Database may have been partially setup by another process/Terraform script. But role is new.

References

N/A

loganmzz commented 5 days ago

For unknown reason, database was empty or null (get from a Terraform data), but Provider should check and complain about missing or invalid database attribute