-
Notifications
You must be signed in to change notification settings - Fork 81
Terraform support Global API Key #929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,8 @@ const ( | |
| cloudKindInLowercase = "cloud" | ||
| tableflowKind = "Tableflow" | ||
| tableflowKindInLowercase = "tableflow" | ||
| globalKind = "Global" | ||
| globalKindInLowercase = "global" | ||
|
|
||
| iamApiVersion = "iam/v2" | ||
| cmkApiVersion = "cmk/v2" | ||
|
|
@@ -53,13 +55,14 @@ const ( | |
| ksqldbcmApiVersion = "ksqldbcm/v2" | ||
| fcpmApiVersion = "fcpm/v2" | ||
| tableflowApiVersion = "tableflow/v1" | ||
| globalApiVersion = "global/v1" | ||
| ) | ||
|
|
||
| var acceptedOwnerKinds = []string{serviceAccountKind, userKind} | ||
| var acceptedResourceKinds = []string{clusterKind, regionKind, tableflowKind} | ||
| var acceptedResourceKinds = []string{clusterKind, regionKind, tableflowKind, globalKind} | ||
|
|
||
| var acceptedOwnerApiVersions = []string{iamApiVersion} | ||
| var acceptedResourceApiVersions = []string{cmkApiVersion, srcmV2ApiVersion, srcmV3ApiVersion, ksqldbcmApiVersion, fcpmApiVersion, tableflowApiVersion} | ||
| var acceptedResourceApiVersions = []string{cmkApiVersion, srcmV2ApiVersion, srcmV3ApiVersion, ksqldbcmApiVersion, fcpmApiVersion, tableflowApiVersion, globalApiVersion} | ||
|
|
||
| func apiKeyResource() *schema.Resource { | ||
| return &schema.Resource{ | ||
|
|
@@ -140,6 +143,9 @@ func apiKeyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) | |
| if apiVersion == tableflowApiVersion { | ||
| spec.Resource.SetApiVersion(tableflowApiVersion) | ||
| } | ||
| if apiVersion == globalApiVersion { | ||
| spec.Resource.SetApiVersion(globalApiVersion) | ||
| } | ||
|
|
||
| if isFlinkApiKey(apikeys.IamV2ApiKey{Spec: spec}) { | ||
| spec.Resource.SetId(resourceId) | ||
|
|
@@ -508,6 +514,10 @@ func isTableflowApiKey(apiKey apikeys.IamV2ApiKey) bool { | |
| return apiKey.Spec.Resource.GetKind() == tableflowKind && apiKey.Spec.Resource.GetId() == tableflowKindInLowercase | ||
| } | ||
|
|
||
| func isGlobalApiKey(apiKey apikeys.IamV2ApiKey) bool { | ||
| return apiKey.Spec.Resource.GetKind() == globalKind && apiKey.Spec.Resource.GetId() == globalKindInLowercase | ||
| } | ||
|
|
||
| func waitForApiKeyToSync(ctx context.Context, c *Client, createdApiKey apikeys.IamV2ApiKey, isResourceSpecificApiKey bool, environmentId string) error { | ||
| // For Kafka API Key use Kafka REST API's List Topics request and wait for http.StatusOK | ||
| // For Cloud API Key use Org API's List Environments request and wait for http.StatusOK | ||
|
|
@@ -536,6 +546,10 @@ func waitForApiKeyToSync(ctx context.Context, c *Client, createdApiKey apikeys.I | |
| 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the global API key supposed to be resource specific? Or
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes we use global as the associated resource id for global API key. |
||
| if err := waitForCreatedGlobalApiKeyToSync(ctx, c, createdApiKey.GetId(), createdApiKey.Spec.GetSecret()); err != nil { | ||
| return fmt.Errorf("error waiting for Global API Key %q to sync: %s", createdApiKey.GetId(), createDescriptiveError(err)) | ||
| } | ||
| } else { | ||
| resourceJson, err := json.Marshal(createdApiKey.Spec.GetResource()) | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the backend service suppose to return the lower case
globalas the Id?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it will return lower case global.