-
Notifications
You must be signed in to change notification settings - Fork 10
Description
When using the provider on ClickHouse Cloud with >1 replica, terraform apply intermittently fails on clickhousedbops_grant_privilege even though the GRANT succeeds server-side.
The error shown is:
Error: Error Creating ClickHouse Privilege Grant
The grant operation was successful but it didn't create the expected entry
in system.grants table. This normally means there is an already granted
privilege to the same grantee that already includes the one you tried to apply.
On a single-replica service, the issue does not occur.
From reading the provider code:
- After issuing the GRANT, the provider reads system.grants to verify creation:
-
With multiple replicas, that post-write read can hit a replica that hasn’t replicated the new row yet (replication lag on system.grants). The lookup then returns no row.
-
The provider subsequently enters the overlap/duplicate detection branch:
- That logic can conclude there is an “already included” permission and raise the error above, even though the GRANT actually succeeded.
This explains why the same plan succeeds reliably on a single-replica service but fails intermittently on multi-replica services.
Steps to Reproduce
-
Use ClickHouse Cloud with ≥2 replicas.
-
Provider version : 1.3.1
-
Apply a plan that creates role privilege grants (global and/or per-DB).
-
Observe intermittent failures on
clickhousedbops_grant_privilege. -
On a 1-replica service, the same plan succeeds consistently.
Fix / Ideas
- When verifying the grant, query all replicas (e.g. via
clusterAllReplicas('cluster', system.grants)) for clickhouse cloud - Pass a flag to use
clusterAllReplicas
Many thanks