-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for API Key management (#193)
* Impliment create/read/update * Impliment delete (invalidate) * Ignore binary * Read only fields * Docs * Docs * Acceptance test * Updating models for differences between expiration and role types * PR feedback Co-authored-by: Toby Brain <[email protected]> * Changelog * Update client in test * Replacing string comparion with DeepEqual when testing role_descriptors * Removing ApiKeyRole and using indices instead of index field * Skipping unsupported versions in test matrix * fmt * Removing now redundant comment * Handling json.marshal in test * docs * Testing an open matrix * Missed ref * Re-enable version guard for test * Bumping SkipFunc Co-authored-by: Toby Brain <[email protected]>
- Loading branch information
Showing
10 changed files
with
599 additions
and
0 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
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,83 @@ | ||
--- | ||
subcategory: "Security" | ||
layout: "" | ||
page_title: "Elasticstack: elasticstack_elasticsearch_security_api_key Resource" | ||
description: |- | ||
Creates an API key for access without requiring basic authentication. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html | ||
--- | ||
|
||
# elasticstack_elasticsearch_security_api_key (Resource) | ||
|
||
Creates an API key for access without requiring basic authentication. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "elasticstack_elasticsearch_security_api_key" "api_key" { | ||
# Set the name | ||
name = "My API key" | ||
# Set the role descriptors | ||
role_descriptors = jsonencode({ | ||
role-a = { | ||
cluster = ["all"], | ||
indices = [{ | ||
names = ["index-a*"], | ||
privileges = ["read"] | ||
}] | ||
} | ||
}) | ||
# Set the expiration for the API key | ||
expiration = "1d" | ||
# Set the custom metadata for this user | ||
metadata = jsonencode({ | ||
"env" = "testing" | ||
"open" = false | ||
"number" = 49 | ||
}) | ||
} | ||
output "api_key" { | ||
value = elasticstack_elasticsearch_security_api_key.api_key | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) Specifies the name for this API key. | ||
|
||
### Optional | ||
|
||
- `elasticsearch_connection` (Block List, Max: 1) Used to establish connection to Elasticsearch server. Overrides environment variables if present. (see [below for nested schema](#nestedblock--elasticsearch_connection)) | ||
- `expiration` (String) Expiration time for the API key. By default, API keys never expire. | ||
- `metadata` (String) Arbitrary metadata that you want to associate with the API key. | ||
- `role_descriptors` (String) Role descriptors for this API key. | ||
|
||
### Read-Only | ||
|
||
- `api_key` (String) Generated API Key. | ||
- `encoded` (String) API key credentials which is the Base64-encoding of the UTF-8 representation of the id and api_key joined by a colon (:). | ||
- `expiration_timestamp` (Number) Expiration time in milliseconds for the API key. By default, API keys never expire. | ||
- `id` (String) Internal identifier of the resource. | ||
|
||
<a id="nestedblock--elasticsearch_connection"></a> | ||
### Nested Schema for `elasticsearch_connection` | ||
|
||
Optional: | ||
|
||
- `api_key` (String, Sensitive) API Key to use for authentication to Elasticsearch | ||
- `ca_data` (String) PEM-encoded custom Certificate Authority certificate | ||
- `ca_file` (String) Path to a custom Certificate Authority certificate | ||
- `endpoints` (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number. | ||
- `insecure` (Boolean) Disable TLS certificate validation | ||
- `password` (String, Sensitive) A password to use for API authentication to Elasticsearch. | ||
- `username` (String) A username to use for API authentication to Elasticsearch. | ||
|
||
## Import | ||
|
||
Import is not supported due to the generated API key only being visible on create. |
29 changes: 29 additions & 0 deletions
29
examples/resources/elasticstack_elasticsearch_security_api_key/resource.tf
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,29 @@ | ||
resource "elasticstack_elasticsearch_security_api_key" "api_key" { | ||
# Set the name | ||
name = "My API key" | ||
|
||
# Set the role descriptors | ||
role_descriptors = jsonencode({ | ||
role-a = { | ||
cluster = ["all"], | ||
indices = [{ | ||
names = ["index-a*"], | ||
privileges = ["read"] | ||
}] | ||
} | ||
}) | ||
|
||
# Set the expiration for the API key | ||
expiration = "1d" | ||
|
||
# Set the custom metadata for this user | ||
metadata = jsonencode({ | ||
"env" = "testing" | ||
"open" = false | ||
"number" = 49 | ||
}) | ||
} | ||
|
||
output "api_key" { | ||
value = elasticstack_elasticsearch_security_api_key.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.