Skip to content

Commit c0e1bed

Browse files
authored
Add key_id as an explicit attribute (#789)
* Add key_id as an explicit attribute * Changelog
1 parent 845721a commit c0e1bed

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [Unreleased]
22

3+
- Add key_id to the `elasticstack_elasticsearch_api_key` resource. ([#789](https://github.com/elastic/terraform-provider-elasticstack/pull/789))
34
- Fix handling of `sys_monitoring` in `elasticstack_fleet_agent_policy` ([#792](https://github.com/elastic/terraform-provider-elasticstack/pull/792))
45
- 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))
56
- Fix for synthetics http/tcp monitor produces inconsistent result after apply ([#801](https://github.com/elastic/terraform-provider-elasticstack/pull/801))

docs/resources/elasticsearch_security_api_key.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ output "api_key" {
9898
- `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 (:).
9999
- `expiration_timestamp` (Number) Expiration time in milliseconds for the API key. By default, API keys never expire.
100100
- `id` (String) Internal identifier of the resource.
101+
- `key_id` (String) Unique id for this API key.
101102

102103
<a id="nestedblock--elasticsearch_connection"></a>
103104
### Nested Schema for `elasticsearch_connection`

internal/elasticsearch/security/api_key.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ func ResourceApiKey() *schema.Resource {
2626
Type: schema.TypeString,
2727
Computed: true,
2828
},
29+
"key_id": {
30+
Description: "Unique id for this API key.",
31+
Type: schema.TypeString,
32+
Computed: true,
33+
},
2934
"name": {
3035
Description: "Specifies the name for this API key.",
3136
Type: schema.TypeString,
@@ -166,6 +171,9 @@ func resourceSecurityApiKeyCreate(ctx context.Context, d *schema.ResourceData, m
166171
return diag.FromErr(err)
167172
}
168173
}
174+
if err := d.Set("key_id", putResponse.Id); err != nil {
175+
return diag.FromErr(err)
176+
}
169177
if err := d.Set("expiration_timestamp", putResponse.Expiration); err != nil {
170178
return diag.FromErr(err)
171179
}
@@ -230,6 +238,9 @@ func resourceSecurityApiKeyRead(ctx context.Context, d *schema.ResourceData, met
230238
if err := d.Set("expiration_timestamp", apikey.Expiration); err != nil {
231239
return diag.FromErr(err)
232240
}
241+
if err := d.Set("key_id", apikey.Id); err != nil {
242+
return diag.FromErr(err)
243+
}
233244

234245
if apikey.RolesDescriptors != nil {
235246
rolesDescriptors, err := json.Marshal(apikey.RolesDescriptors)

internal/elasticsearch/security/api_key_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func TestAccResourceSecurityApiKey(t *testing.T) {
6262
resource.TestCheckResourceAttrSet("elasticstack_elasticsearch_security_api_key.test", "expiration"),
6363
resource.TestCheckResourceAttrSet("elasticstack_elasticsearch_security_api_key.test", "api_key"),
6464
resource.TestCheckResourceAttrSet("elasticstack_elasticsearch_security_api_key.test", "encoded"),
65+
resource.TestCheckResourceAttrSet("elasticstack_elasticsearch_security_api_key.test", "id"),
6566
),
6667
},
6768
},

0 commit comments

Comments
 (0)