Skip to content

feat: Add CREATE FUNCTION and DROP FUNCTION privileges support - #72

Merged
and-longhi merged 2 commits into
masterfrom
feat/add-function-priviledges
Oct 2, 2025
Merged

feat: Add CREATE FUNCTION and DROP FUNCTION privileges support#72
and-longhi merged 2 commits into
masterfrom
feat/add-function-priviledges

Conversation

@and-longhi

@and-longhi and-longhi commented Oct 2, 2025

Copy link
Copy Markdown
Collaborator

Summary

This PR adds support for CREATE FUNCTION and DROP FUNCTION privileges in the ClickHouse Terraform provider, validating that these global privileges can only be used with database = "*"

Changes

  • Added CREATE FUNCTION and DROP FUNCTION to AllowedGlobalPrivileges in validators.go
  • These privileges are configured as global-level privileges that require database = "*"
  • Created comprehensive test suite in resource_role_function_test.go with:
    • TestAccResourceRole_FunctionPrivileges - Tests creating roles with CREATE FUNCTION and DROP FUNCTION privileges
    • TestAccResourceRole_ValidationCreateFunction - Validates CREATE FUNCTION is rejected when database != "*"
    • TestAccResourceRole_ValidationDropFunction - Validates DROP FUNCTION is rejected when database != "*"

Test Results

All tests pass successfully:

=== RUN   TestAccResourceRole_FunctionPrivileges
--- PASS: TestAccResourceRole_FunctionPrivileges (0.42s)
=== RUN   TestAccResourceRole_ValidationCreateFunction
--- PASS: TestAccResourceRole_ValidationCreateFunction (0.26s)
=== RUN   TestAccResourceRole_ValidationDropFunction
--- PASS: TestAccResourceRole_ValidationDropFunction (0.27s)
PASS

Andrea Longhi added 2 commits October 2, 2025 16:35
REMOTE and S3 privileges get expanded by ClickHouse into READ and WRITE,
causing the test to fail when checking privilege counts. This fix filters
them out from the global privileges test while still validating them
individually.
@and-longhi

Copy link
Copy Markdown
Collaborator Author

Additional Fix

Fixed a pre-existing test failure in TestAccResourceRole by excluding REMOTE and S3 privileges from the global privileges test.

Why: ClickHouse expands REMOTE and S3 privileges into READ and WRITE privileges internally, causing privilege count mismatches in the test assertions. These privileges are still validated individually in separate test cases.

Implementation: Added getTestableGlobalPrivileges() helper function that filters out REMOTE and S3 from AllowedGlobalPrivileges when running the comprehensive global privileges test.

@and-longhi
and-longhi marked this pull request as ready for review October 2, 2025 15:11
@and-longhi
and-longhi merged commit 076c76f into master Oct 2, 2025
10 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants