Skip to content

Commit 2f4bd11

Browse files
committed
review changes 2
Signed-off-by: Mauritz Uphoff <[email protected]>
1 parent 23bb334 commit 2f4bd11

File tree

4 files changed

+21
-33
lines changed

4 files changed

+21
-33
lines changed

docs/ephemeral-resources/access_token.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
page_title: "stackit_access_token Ephemeral Resource - stackit"
44
subcategory: ""
55
description: |-
6-
STACKIT Access Token ephemeral resource schema.
6+
Ephemeral resource that generates a short-lived STACKIT access token (JWT) using a service account key. A new token is generated each time the resource is evaluated, and it remains consistent for the duration of a Terraform operation. If a private key is not explicitly provided, the provider attempts to extract it from the service account key instead. Token generation logic prioritizes environment variables first, followed by provider configuration. Access tokens generated from service account keys expire after 60 minutes.
77
---
88

99
# stackit_access_token (Ephemeral Resource)
1010

11-
STACKIT Access Token ephemeral resource schema.
11+
Ephemeral resource that generates a short-lived STACKIT access token (JWT) using a service account key. A new token is generated each time the resource is evaluated, and it remains consistent for the duration of a Terraform operation. If a private key is not explicitly provided, the provider attempts to extract it from the service account key instead. Token generation logic prioritizes environment variables first, followed by provider configuration. Access tokens generated from service account keys expire after 60 minutes.
1212

1313
## Example Usage
1414

@@ -26,8 +26,8 @@ provider "restapi" {
2626
}
2727
2828
create_method = "GET"
29-
update_method = "GET"
30-
destroy_method = "GET"
29+
update_method = "POST"
30+
destroy_method = "DELETE"
3131
}
3232
```
3333

examples/ephemeral-resources/stackit_access_token/ephemeral-resource.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ provider "restapi" {
1111
}
1212

1313
create_method = "GET"
14-
update_method = "GET"
15-
destroy_method = "GET"
14+
update_method = "POST"
15+
destroy_method = "DELETE"
1616
}

stackit/internal/services/access_token/ephemeral_resource.go

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ func NewAccessTokenEphemeralResource() ephemeral.EphemeralResource {
2424
}
2525

2626
type accessTokenEphemeralResource struct {
27-
serviceAccountKeyPath string
28-
serviceAccountKey string
29-
privateKeyPath string
30-
privateKey string
31-
tokenCustomEndpoint string
27+
keyAuthConfig config.Configuration
3228
}
3329

3430
func (e *accessTokenEphemeralResource) Configure(ctx context.Context, req ephemeral.ConfigureRequest, resp *ephemeral.ConfigureResponse) {
@@ -37,11 +33,13 @@ func (e *accessTokenEphemeralResource) Configure(ctx context.Context, req epheme
3733
return
3834
}
3935

40-
e.serviceAccountKey = providerData.ServiceAccountKey
41-
e.serviceAccountKeyPath = providerData.ServiceAccountKeyPath
42-
e.privateKey = providerData.PrivateKey
43-
e.privateKeyPath = providerData.PrivateKeyPath
44-
e.tokenCustomEndpoint = providerData.TokenCustomEndpoint
36+
e.keyAuthConfig = config.Configuration{
37+
ServiceAccountKey: providerData.ServiceAccountKey,
38+
ServiceAccountKeyPath: providerData.ServiceAccountKeyPath,
39+
PrivateKeyPath: providerData.PrivateKey,
40+
PrivateKey: providerData.PrivateKeyPath,
41+
TokenCustomUrl: providerData.TokenCustomEndpoint,
42+
}
4543
}
4644

4745
type ephemeralTokenModel struct {
@@ -54,7 +52,11 @@ func (e *accessTokenEphemeralResource) Metadata(_ context.Context, req ephemeral
5452

5553
func (e *accessTokenEphemeralResource) Schema(_ context.Context, _ ephemeral.SchemaRequest, resp *ephemeral.SchemaResponse) {
5654
resp.Schema = schema.Schema{
57-
Description: "STACKIT Access Token ephemeral resource schema.",
55+
Description: "Ephemeral resource that generates a short-lived STACKIT access token (JWT) using a service account key. " +
56+
"A new token is generated each time the resource is evaluated, and it remains consistent for the duration of a Terraform operation. " +
57+
"If a private key is not explicitly provided, the provider attempts to extract it from the service account key instead. " +
58+
"Token generation logic prioritizes environment variables first, followed by provider configuration. " +
59+
"Access tokens generated from service account keys expire after 60 minutes.",
5860
Attributes: map[string]schema.Attribute{
5961
"access_token": schema.StringAttribute{
6062
Description: "JWT access token for STACKIT API authentication.",
@@ -73,15 +75,7 @@ func (e *accessTokenEphemeralResource) Open(ctx context.Context, req ephemeral.O
7375
return
7476
}
7577

76-
cfg := config.Configuration{
77-
ServiceAccountKey: e.serviceAccountKey,
78-
ServiceAccountKeyPath: e.serviceAccountKeyPath,
79-
PrivateKeyPath: e.privateKeyPath,
80-
PrivateKey: e.privateKey,
81-
TokenCustomUrl: e.tokenCustomEndpoint,
82-
}
83-
84-
rt, err := auth.KeyAuth(&cfg)
78+
rt, err := auth.KeyAuth(&e.keyAuthConfig)
8579
if err != nil {
8680
core.LogAndAddError(ctx, &resp.Diagnostics, "Access token generation failed", fmt.Sprintf("Failed to initialize authentication: %v", err))
8781
return
@@ -97,12 +91,7 @@ func (e *accessTokenEphemeralResource) Open(ctx context.Context, req ephemeral.O
9791
// Retrieve the access token
9892
accessToken, err := client.GetAccessToken()
9993
if err != nil {
100-
core.LogAndAddError(
101-
ctx,
102-
&resp.Diagnostics,
103-
"Access token retrieval failed",
104-
fmt.Sprintf("Error obtaining access token: %v", err),
105-
)
94+
core.LogAndAddError(ctx, &resp.Diagnostics, "Access token retrieval failed", fmt.Sprintf("Error obtaining access token: %v", err))
10695
return
10796
}
10897

stackit/internal/services/access_token/ephemeral_resource_test.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)