Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce API Token Ephemeral Resource #996

Merged
merged 12 commits into from
Dec 19, 2024
Merged

Conversation

chrismarget-j
Copy link
Collaborator

@chrismarget-j chrismarget-j commented Dec 15, 2024

This PR introduces our first Ephemeral Resource: apstra_api_token

Broad changes

  • I had to upgrade Terraform CLI on my workstation in order to render the docs. Terraform prior to 1.10.0 doesn't know about Ephemeral Resources.
  • The github.com/hashicorp/terraform-plugin-docs dependency also needed to be upgraded to generate docs for Ephemeral Resources.
  • The minimum version of go needed to be updated in go.mod, I think because of tfplugindocs.
  • The provider object, provider data, configure interfaces and documentation templates were extended to support ephemeral resources.

The new Ephemeral Resource:

apstra_api_token implements the following framework interfaces:

  • ephemeral.EphemeralResource
  • ephemeral.EphemeralResourceWithClose
  • ephemeral.EphemeralResourceWithConfigure
  • ephemeral.EphemeralResourceWithRenew

In Configure(), we extract the apstra.Client from provider data (no surprises here).

In Open(), we create a client based on the one passed in by the provider, log it in, extract the required token info, and set the Renew() time for shortly before the token expires.

In Renew(), we can't actually freshen the token. Renew() is a feature designed for "leased" credentials where the lease can be renewed without replacing the value. All we can do is raise warnings or errors. If the credential is not yet expired, we raise a warning and update the renew time. If it's expired, we raise an error.

In Close(), we call the logout API unless the user asked us not to or the token is already expired.

Odds and Ends

Bugfixes in github.com/hashicorp/terraform-plugin-docs cause several documentation pages to render differently even though the source data didn't change.

@chrismarget-j chrismarget-j requested review from bwJuniper and rajagopalans and removed request for bwJuniper December 16, 2024 22:38
@chrismarget-j chrismarget-j changed the title WIP: Introduce API Token Ephemeral Resource Introduce API Token Ephemeral Resource Dec 16, 2024
@chrismarget-j
Copy link
Collaborator Author

Closes #992

@chrismarget-j chrismarget-j merged commit 5b05612 into main Dec 19, 2024
1 check passed
@chrismarget-j chrismarget-j deleted the ephemeral-api-token branch December 19, 2024 16:50
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.

2 participants