generated from davidji99/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement new resource: `split_api_key` * update go.sum * update ci ymls
- Loading branch information
Showing
15 changed files
with
577 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ on: | |
- docs/** | ||
|
||
env: | ||
GO_VERSION: "1.18" | ||
GO_VERSION: "1.21" | ||
GO111MODULE: on | ||
|
||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ jobs: | |
name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.20.7 | ||
go-version: 1.21 | ||
- | ||
name: Import GPG key | ||
id: import_gpg | ||
|
@@ -28,7 +28,7 @@ jobs: | |
name: Run GoReleaser | ||
uses: goreleaser/[email protected] | ||
with: | ||
version: v1.20 | ||
version: v1.21 | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package api | ||
|
||
import "github.com/davidji99/simpleresty" | ||
|
||
var ( | ||
ValidApiKeyTypes = []string{"client_side", "server_side", "admin"} | ||
ValidApiKeyRoles = []string{"API_ALL_GRANTED", "API_APIKEY", "API_ADMIN", "API_WORKSPACE_ADMIN", "API_FEATURE_FLAG_VIEWER", | ||
"API_FEATURE_FLAG_EDITOR", "API_SEGMENT_VIEWER", "API_SEGMENT_EDITOR"} | ||
) | ||
|
||
// KeysService handles communication with the api keys related | ||
// methods of the Split.io APIv2. | ||
// | ||
// Reference: https://docs.split.io/reference/api-keys-overview | ||
type KeysService service | ||
|
||
// KeyRequest represents a request to create an API key. | ||
type KeyRequest struct { | ||
Name string `json:"name"` | ||
KeyType string `json:"apiKeyType"` | ||
Roles []string `json:"roles"` | ||
Environments []KeyEnvironmentRequest `json:"environments"` | ||
Workspace *KeyWorkspaceRequest `json:"workspace"` | ||
} | ||
|
||
type KeyEnvironmentRequest struct { | ||
Type string `json:"type"` | ||
Id string `json:"id"` | ||
} | ||
|
||
type KeyWorkspaceRequest struct { | ||
Type string `json:"type"` | ||
Id string `json:"id"` | ||
} | ||
|
||
// KeyResponse represents the created key. | ||
// | ||
// Not all fields are added here. | ||
type KeyResponse struct { | ||
Id *string `json:"id"` | ||
Name *string `json:"name"` | ||
Roles []string `json:"roles"` | ||
Type *string `json:"type"` | ||
ApiKeyType *string `json:"apiKeyType"` | ||
|
||
// Key is the actual API key | ||
Key *string `json:"key"` | ||
} | ||
|
||
// Create an API key. | ||
// | ||
// Reference: https://docs.split.io/reference/create-an-api-key | ||
func (k *KeysService) Create(opts *KeyRequest) (*KeyResponse, *simpleresty.Response, error) { | ||
var result KeyResponse | ||
urlStr := k.client.http.RequestURL("/apiKeys") | ||
|
||
// Execute the request | ||
response, createErr := k.client.post(urlStr, &result, opts) | ||
|
||
return &result, response, createErr | ||
} | ||
|
||
// Delete an API key. | ||
// | ||
// Reference: https://docs.split.io/reference/delete-an-api-key | ||
func (k *KeysService) Delete(key string) (*simpleresty.Response, error) { | ||
urlStr := k.client.http.RequestURL("/apiKeys/%s", key) | ||
// Execute the request | ||
response, err := k.client.delete(urlStr, nil, nil) | ||
|
||
return response, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
layout: "split" | ||
page_title: "Split: split_api_key" | ||
sidebar_current: "docs-split-resource-api-key" | ||
description: |- | ||
Provides the ability to manage a Split API key. | ||
--- | ||
|
||
# split_api_key | ||
|
||
This resource provides the ability to manage an [API key](https://docs.split.io/reference/api-keys-overview). | ||
|
||
Due to API limitations, it is not possible update an existing API key. Any modifications to a `split_api_key` resource | ||
will result in a destroy and recreate process. | ||
|
||
-> **IMPORTANT!** | ||
Please be very careful when deleting this resource as the deleted API keys are NOT recoverable and invalidated immediately. | ||
Furthermore, this resource renders the actual API key plain-text in your state file. | ||
Please ensure that your state file is properly secured and encrypted at rest. | ||
|
||
## Example Usage | ||
|
||
```hcl-terraform | ||
data "split_workspace" "default" { | ||
name = "default" | ||
} | ||
resource "split_environment" "foobar" { | ||
workspace_id = data.split_workspace.default.id | ||
name = "staging" | ||
production = true | ||
} | ||
resource "split_api_key" "foobar" { | ||
workspace_id = data.split_workspace.default.id | ||
name = "my client side key" | ||
type = "client_side" | ||
environment_ids = [split_environment.foobar.id] | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `workspace_id` - (Required) `<string>` The UUID of the workspace you want to create the environment in. | ||
* `environment_ids` - (Required) `<list(string)>` List of environment UUIDs. | ||
* `name` - (Required) `<boolean>` Name of the API key. | ||
* `type` - (Required) `<boolean>` Type of the API key. Refer to Split [documentation](https://docs.split.io/reference/create-an-api-key#supported-types) on acceptable values, case sensitive. | ||
* `roles` - (Required) `<boolean>` Supported only when `type=admin` API keys. For the full list of allowed Admin API Key roles, refer | ||
to Split [documentation](https://docs.split.io/reference/api-keys-overview#admin-api-key-roles), case sensitive. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
n/a | ||
|
||
## Import | ||
|
||
Due to Split API limitations, it is not possible to import an existing API key. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.