Skip to content

Commit

Permalink
API Keys: Do not allow importing
Browse files Browse the repository at this point in the history
  • Loading branch information
briankassouf committed Dec 2, 2024
1 parent 8860672 commit 79d1835
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 27 deletions.
13 changes: 0 additions & 13 deletions docs/resources/apikey.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,3 @@ Optional:

- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.

## Import

Import is supported using the following syntax:

```shell
# API Keys can be imported to incorporate existing API Keys into your Terraform pipeline.
# To import an API Key, you need
# - a resource configuration in your Terraform configuration file/module to accept the imported API Key. In the example below, the placeholder is "temporalcloud_apikey" "tfapikey"
# - the API Key's ID, which is found when clicking into an API Key in the Temporal Cloud UI. In the example below, this is zJV5zQ3IhsAbw75dAkVNEMsAd3a5AemC

terraform import temporalcloud_apikey.tfapikey zJV5zQ3IhsAbw75dAkVNEMsAd3a5AemC
```
6 changes: 0 additions & 6 deletions examples/resources/temporalcloud_apikey/import.sh

This file was deleted.

11 changes: 3 additions & 8 deletions internal/provider/apikey_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand Down Expand Up @@ -39,9 +38,8 @@ type (
)

var (
_ resource.Resource = (*apiKeyResource)(nil)
_ resource.ResourceWithConfigure = (*apiKeyResource)(nil)
_ resource.ResourceWithImportState = (*apiKeyResource)(nil)
_ resource.Resource = (*apiKeyResource)(nil)
_ resource.ResourceWithConfigure = (*apiKeyResource)(nil)
)

func NewApiKeyResource() resource.Resource {
Expand Down Expand Up @@ -357,10 +355,6 @@ func (r *apiKeyResource) Delete(ctx context.Context, req resource.DeleteRequest,
}
}

func (r *apiKeyResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}

func updateApiKeyModelFromSpec(state *apiKeyResourceModel, apikey *identityv1.ApiKey) error {
state.ID = types.StringValue(apikey.GetId())
stateStr, err := enums.FromResourceState(apikey.GetState())
Expand All @@ -379,5 +373,6 @@ func updateApiKeyModelFromSpec(state *apiKeyResourceModel, apikey *identityv1.Ap
state.Description = types.StringValue(apikey.GetSpec().GetDescription())
}
state.ExpiryTime = types.StringValue(apikey.GetSpec().GetExpiryTime().AsTime().Format(time.RFC3339))

return nil
}

0 comments on commit 79d1835

Please sign in to comment.