Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased]

- Add key_id to the `elasticstack_elasticsearch_api_key` resource. ([#789](https://github.com/elastic/terraform-provider-elasticstack/pull/789))
- Fix handling of `sys_monitoring` in `elasticstack_fleet_agent_policy` ([#792](https://github.com/elastic/terraform-provider-elasticstack/pull/792))
- Migrate `elasticstack_fleet_agent_policy`, `elasticstack_fleet_integration` (both), and `elasticstack_fleet_server_host` to terraform-plugin-framework ([#785](https://github.com/elastic/terraform-provider-elasticstack/pull/785))
- Fix for synthetics http/tcp monitor produces inconsistent result after apply ([#801](https://github.com/elastic/terraform-provider-elasticstack/pull/801))
Expand Down
1 change: 1 addition & 0 deletions docs/resources/elasticsearch_security_api_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ output "api_key" {
- `encoded` (String, Sensitive) 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.
- `key_id` (String) Unique id for this API key.

<a id="nestedblock--elasticsearch_connection"></a>
### Nested Schema for `elasticsearch_connection`
Expand Down
11 changes: 11 additions & 0 deletions internal/elasticsearch/security/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func ResourceApiKey() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"key_id": {
Description: "Unique id for this API key.",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Specifies the name for this API key.",
Type: schema.TypeString,
Expand Down Expand Up @@ -166,6 +171,9 @@ func resourceSecurityApiKeyCreate(ctx context.Context, d *schema.ResourceData, m
return diag.FromErr(err)
}
}
if err := d.Set("key_id", putResponse.Id); err != nil {
return diag.FromErr(err)
}
if err := d.Set("expiration_timestamp", putResponse.Expiration); err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -230,6 +238,9 @@ func resourceSecurityApiKeyRead(ctx context.Context, d *schema.ResourceData, met
if err := d.Set("expiration_timestamp", apikey.Expiration); err != nil {
return diag.FromErr(err)
}
if err := d.Set("key_id", apikey.Id); err != nil {
return diag.FromErr(err)
}

if apikey.RolesDescriptors != nil {
rolesDescriptors, err := json.Marshal(apikey.RolesDescriptors)
Expand Down
1 change: 1 addition & 0 deletions internal/elasticsearch/security/api_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestAccResourceSecurityApiKey(t *testing.T) {
resource.TestCheckResourceAttrSet("elasticstack_elasticsearch_security_api_key.test", "expiration"),
resource.TestCheckResourceAttrSet("elasticstack_elasticsearch_security_api_key.test", "api_key"),
resource.TestCheckResourceAttrSet("elasticstack_elasticsearch_security_api_key.test", "encoded"),
resource.TestCheckResourceAttrSet("elasticstack_elasticsearch_security_api_key.test", "id"),
),
},
},
Expand Down
Loading