Terraform support Global API Key#929
Terraform support Global API Key#929Taohao Wang (taohaowang) wants to merge 2 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for Global API Keys in the Terraform provider, enabling users to create, update, and delete API keys scoped to global resources rather than specific Kafka clusters or environments.
Changes:
- Added Global API Key resource type with appropriate validation and synchronization logic
- Implemented test coverage for Global API Key lifecycle operations including creation, update, and deletion
- Added documentation example for Global API Key resource configuration
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/testdata/apikey/create_global_api_key.json | Test fixture for Global API Key creation response |
| internal/testdata/apikey/read_created_global_api_key.json | Test fixture for reading a newly created Global API Key |
| internal/testdata/apikey/read_updated_global_api_key.json | Test fixture for reading an updated Global API Key |
| internal/testdata/apikey/read_deleted_global_api_key.json | Test fixture for reading a deleted Global API Key |
| internal/provider/utils_wait.go | Added synchronization logic for Global API Keys to wait for proper propagation |
| internal/provider/resource_api_key_test.go | Added comprehensive test coverage for Global API Key lifecycle |
| internal/provider/resource_api_key.go | Added Global API Key type support and validation logic |
| docs/resources/confluent_api_key.md | Added documentation example for Global API Key usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Can you please create a live test for this in resource_api_key_live_test.go? |
| if err := waitForCreatedTableflowApiKeyToSync(ctx, tableflowRestClient, c.isAcceptanceTestMode); err != nil { | ||
| return fmt.Errorf("error waiting for Tableflow API Key %q to sync: %s", createdApiKey.GetId(), createDescriptiveError(err)) | ||
| } | ||
| } else if isGlobalApiKey(createdApiKey) { |
There was a problem hiding this comment.
Is the global API key supposed to be resource specific? Or Global is considered as a special resource?
There was a problem hiding this comment.
Yes we use global as the associated resource id for global API key.
| return apiKey.Spec.Resource.GetKind() == tableflowKind && apiKey.Spec.Resource.GetId() == tableflowKindInLowercase | ||
| } | ||
|
|
||
| func isGlobalApiKey(apiKey apikeys.IamV2ApiKey) bool { |
There was a problem hiding this comment.
Is the backend service suppose to return the lower case global as the Id?
There was a problem hiding this comment.
yes, it will return lower case global.
| WillReturn( | ||
| string(readDeletedGlobalApiKeyResponse), | ||
| contentTypeJSONHeader, | ||
| http.StatusForbidden, |
There was a problem hiding this comment.
Should this be 404 instead of 403?
There was a problem hiding this comment.
Here we are following the same pattern with other resource api keys e.g. Kafka, Flink, ...
The reason here is more from security perspective: an attacker probing key IDs can't distinguish between "this key never existed" and "this key was deleted," making enumeration and reconnaissance harder.
|
Live Test Result (linked to stag): |
Release Notes
New Features
Support Global API key from Terraform
Bug Fixes
NA
Examples
Please refer to https://confluentinc.atlassian.net/wiki/spaces/~712020ba3ea6a8cdb24e61b11d46bc2b8c41b6/pages/5092836879/How+to+Test+Cli+Terraform+Locally
Checklist
Test & Reviewsection below.Blast Radiussection below.What
Support Global API key management from Terraform.
Blast Radius
This is a new feature for Global API key, relatively low impact on existing customer use cases.
References
https://confluentinc.atlassian.net/wiki/spaces/~712020ba3ea6a8cdb24e61b11d46bc2b8c41b6/pages/5092836879/How+to+Test+Cli+Terraform+Locally
https://confluentinc.atlassian.net/browse/IDENTITY-6365
Test & Review