Skip to content

Add support for ephemeral vault_token resource with type and entity_alias fields#2877

Open
Siddharth-Kannan wants to merge 5 commits intomainfrom
VAULT-43853-Vault-Token-Ephemeral-Resource
Open

Add support for ephemeral vault_token resource with type and entity_alias fields#2877
Siddharth-Kannan wants to merge 5 commits intomainfrom
VAULT-43853-Vault-Token-Ephemeral-Resource

Conversation

@Siddharth-Kannan
Copy link
Copy Markdown
Contributor

@Siddharth-Kannan Siddharth-Kannan commented Apr 13, 2026

Description

Created new ephemeral resource for resource_token and added support for type and entity_alias fields.
Added acceptance tests for the ephemeral resource.
Added a deprecation message for the sdkv2 implementation of the token resource.

Performed testing across vault versions 1.15.0-1.21.0

Checklist

  • Added CHANGELOG entry (only for user-facing changes)
  • Acceptance tests where run against all supported Vault Versions

Output from acceptance testing:

$ terraform-provider-vault % go test -v -count=1 -run TestAccToken ./internal/vault/auth/ephemeral/
=== RUN   TestAccToken_basic
--- PASS: TestAccToken_basic (2.83s)
=== RUN   TestAccToken_batch
--- PASS: TestAccToken_batch (1.31s)
=== RUN   TestAccToken_withPolicies
--- PASS: TestAccToken_withPolicies (3.09s)
=== RUN   TestAccToken_orphan
--- PASS: TestAccToken_orphan (2.97s)
=== RUN   TestAccToken_withRole
--- PASS: TestAccToken_withRole (3.64s)
=== RUN   TestAccToken_wrapped
--- PASS: TestAccToken_wrapped (3.97s)
=== RUN   TestAccToken_wrappedBatch
--- PASS: TestAccToken_wrappedBatch (2.58s)
=== RUN   TestAccToken_withEntityAlias
--- PASS: TestAccToken_withEntityAlias (4.13s)
=== RUN   TestAccToken_batchTokenAutoDetectionViaRole
--- PASS: TestAccToken_batchTokenAutoDetectionViaRole (2.11s)
=== RUN   TestAccToken_full
--- PASS: TestAccToken_full (2.88s)
PASS
ok      github.com/hashicorp/terraform-provider-vault/internal/vault/auth/ephemeral     30.430s
...

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@Siddharth-Kannan Siddharth-Kannan marked this pull request as ready for review April 13, 2026 12:34
@Siddharth-Kannan Siddharth-Kannan requested review from a team as code owners April 13, 2026 12:34
@siyer-corp siyer-corp requested a review from Copilot April 15, 2026 16:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a Terraform Plugin Framework ephemeral vault_token resource to create Vault tokens with automatic revocation, expands functionality (token type + entity_alias), adds acceptance coverage, and deprecates the legacy SDKv2 vault_token resource to guide users to the more secure ephemeral approach.

Changes:

  • Added new ephemeral "vault_token" implementation with token creation + best-effort cleanup on Close().
  • Added acceptance tests for the new ephemeral token behavior (service/batch/role/wrapping/entity alias scenarios).
  • Added deprecation messaging to the legacy SDKv2 vault_token resource and documented the feature in the changelog.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
vault/resource_token.go Adds deprecation message steering users from SDKv2 resource to the new ephemeral resource.
internal/vault/auth/ephemeral/token.go New ephemeral vault_token resource implementation (schema, Open/Create, Close/Revoke).
internal/vault/auth/ephemeral/token_test.go New acceptance tests using echo provider state checks for ephemeral outputs.
internal/provider/fwprovider/provider.go Registers the new ephemeral token resource in the framework provider.
internal/consts/consts.go Adds FieldEntityAlias constant used by the new ephemeral resource/tests.
CHANGELOG.md Documents the new ephemeral resource and the legacy resource deprecation note.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CHANGELOG.md
Comment thread internal/vault/auth/ephemeral/token.go Outdated
Comment thread internal/vault/auth/ephemeral/token_ephemeral_resource.go
Comment thread internal/vault/auth/ephemeral/token.go Outdated
Comment thread internal/vault/auth/ephemeral/token_ephemeral_resource_test.go
Comment thread internal/vault/auth/ephemeral/token_test.go Outdated
Comment thread vault/resource_token.go Outdated
Comment thread CHANGELOG.md Outdated
Comment thread internal/vault/auth/ephemeral/token.go Outdated
Comment thread internal/vault/auth/ephemeral/token_ephemeral_resource.go
// Set additional computed fields from auth response
if !wrapped && tokenResp.Auth != nil {
// Token policies
if len(tokenResp.Auth.TokenPolicies) > 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add an else block here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't need to add an else block. After verifying the Vault response model, I confirmed that wrapped token responses do not contain an auth object, and token_policies, entity_id, or orphan fields. These fields are marked as Computed: true in the schema, which means they default to null values when not explicitly set. Adding an else block to explicitly set them to null would be redundant.

Additionally, I've added test coverage to verify this behaviour - the tests confirm that these fields are properly null for wrapped tokens without requiring explicit initialisation.

Comment thread internal/vault/auth/ephemeral/token_ephemeral_resource.go
@Siddharth-Kannan Siddharth-Kannan changed the title New Implementation: token ephemeral resource Add support for ephemeral vault_token resource with type and entity_alias fields Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants