Skip to content

Commit 4a17da3

Browse files
committed
review changes 2
1 parent f629b1f commit 4a17da3

File tree

4 files changed

+45
-43
lines changed

4 files changed

+45
-43
lines changed

docs/resources/service_account_access_token.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
page_title: "stackit_service_account_access_token Resource - stackit"
44
subcategory: ""
55
description: |-
6-
Schema for a STACKIT service account access token resource.
6+
Service account access token schema.
77
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
88
Example Usage
99
Automatically rotate access tokens
1010
1111
resource "stackit_service_account" "sa" {
12-
project_id = var.stackit_project_id
12+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1313
name = "sa01"
1414
}
1515
1616
resource "time_rotating" "rotate" {
1717
rotation_days = 80
1818
}
1919
20-
resource "stackit_service_account_access_token" "sa1" {
21-
project_id = var.stackit_project_id
20+
resource "stackit_service_account_access_token" "sa_token" {
21+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2222
service_account_email = stackit_service_account.sa.email
2323
ttl_days = 180
2424
@@ -30,7 +30,7 @@ description: |-
3030

3131
# stackit_service_account_access_token (Resource)
3232

33-
Schema for a STACKIT service account access token resource.
33+
Service account access token schema.
3434

3535
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.
3636
## Example Usage
@@ -39,16 +39,16 @@ Schema for a STACKIT service account access token resource.
3939
### Automatically rotate access tokens
4040
```terraform
4141
resource "stackit_service_account" "sa" {
42-
project_id = var.stackit_project_id
42+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
4343
name = "sa01"
4444
}
4545
4646
resource "time_rotating" "rotate" {
4747
rotation_days = 80
4848
}
4949
50-
resource "stackit_service_account_access_token" "sa1" {
51-
project_id = var.stackit_project_id
50+
resource "stackit_service_account_access_token" "sa_token" {
51+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
5252
service_account_email = stackit_service_account.sa.email
5353
ttl_days = 180
5454
@@ -79,6 +79,6 @@ resource "stackit_service_account_access_token" "sa1" {
7979
- `access_token_id` (String) Identifier for the access token linked to the service account.
8080
- `active` (Boolean) Indicate whether the token is currently active or inactive
8181
- `created_at` (String) Timestamp indicating when the access token was created.
82-
- `id` (String) Unique internal resource ID for Terraform, formatted as "`project_id`,`access_token_id`".
82+
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`access_token_id`".
8383
- `token` (String, Sensitive) JWT access token for API authentication. Prefixed by 'Bearer' and should be stored securely as it is irretrievable once lost.
8484
- `valid_until` (String) Estimated expiration timestamp of the access token. For precise validity, check the JWT details.

stackit/internal/services/serviceaccount/token/const.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
package token
22

33
const markdownDescription = `
4-
Schema for a STACKIT service account access token resource.` + "\n" + `
5-
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.
64
## Example Usage` + "\n" + `
75
86
### Automatically rotate access tokens` + "\n" +
97
"```terraform" + `
108
resource "stackit_service_account" "sa" {
11-
project_id = var.stackit_project_id
9+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1210
name = "sa01"
1311
}
1412
1513
resource "time_rotating" "rotate" {
1614
rotation_days = 80
1715
}
1816
19-
resource "stackit_service_account_access_token" "sa1" {
20-
project_id = var.stackit_project_id
17+
resource "stackit_service_account_access_token" "sa_token" {
18+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2119
service_account_email = stackit_service_account.sa.email
2220
ttl_days = 180
2321

stackit/internal/services/serviceaccount/token/resource.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ func (r *serviceAccountTokenResource) Metadata(_ context.Context, req resource.M
119119
// Schema defines the resource schema for the service account access token.
120120
func (r *serviceAccountTokenResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
121121
descriptions := map[string]string{
122-
"id": "Unique internal resource ID for Terraform, formatted as \"`project_id`,`access_token_id`\".",
122+
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`access_token_id`,`service_account_email`\".",
123+
"main": "Service account access token schema.",
123124
"project_id": "STACKIT project ID associated with the service account token.",
124125
"service_account_email": "Email address linked to the service account.",
125126
"ttl_days": "Specifies the token's validity duration in days. If unspecified, defaults to 90 days.",
@@ -130,11 +131,9 @@ func (r *serviceAccountTokenResource) Schema(_ context.Context, _ resource.Schem
130131
"created_at": "Timestamp indicating when the access token was created.",
131132
"valid_until": "Estimated expiration timestamp of the access token. For precise validity, check the JWT details.",
132133
}
133-
134134
resp.Schema = schema.Schema{
135-
MarkdownDescription: markdownDescription,
136-
Description: "STACKIT service account access token schema.",
137-
135+
MarkdownDescription: fmt.Sprintf("%s%s", features.AddBetaDescription(descriptions["main"]), markdownDescription),
136+
Description: descriptions["main"],
138137
Attributes: map[string]schema.Attribute{
139138
"id": schema.StringAttribute{
140139
Description: descriptions["id"],
@@ -382,7 +381,7 @@ func mapCreateResponse(resp *serviceaccount.AccessToken, model *Model) error {
382381
validUntil = types.StringValue(validUntilValue.Format(time.RFC3339))
383382
}
384383

385-
idParts := []string{model.ProjectId.ValueString(), *resp.Id}
384+
idParts := []string{model.ProjectId.ValueString(), *resp.Id, model.ServiceAccountEmail.ValueString()}
386385
model.Id = types.StringValue(strings.Join(idParts, core.Separator))
387386
model.AccessTokenId = types.StringPointerValue(resp.Id)
388387
model.Token = types.StringPointerValue(resp.Token)

stackit/internal/services/serviceaccount/token/resource_test.go

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ func TestMapCreateResponse(t *testing.T) {
7171
Token: utils.Ptr("token"),
7272
},
7373
Model{
74-
Id: types.StringValue("pid,aid"),
75-
ProjectId: types.StringValue("pid"),
76-
Token: types.StringValue("token"),
77-
AccessTokenId: types.StringValue("aid"),
78-
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
74+
Id: types.StringValue("pid,aid,email"),
75+
ProjectId: types.StringValue("pid"),
76+
ServiceAccountEmail: types.StringValue("email"),
77+
Token: types.StringValue("token"),
78+
AccessTokenId: types.StringValue("aid"),
79+
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
7980
},
8081
true,
8182
},
@@ -89,14 +90,15 @@ func TestMapCreateResponse(t *testing.T) {
8990
Active: utils.Ptr(true),
9091
},
9192
Model{
92-
Id: types.StringValue("pid,aid"),
93-
ProjectId: types.StringValue("pid"),
94-
Token: types.StringValue("token"),
95-
AccessTokenId: types.StringValue("aid"),
96-
Active: types.BoolValue(true),
97-
CreatedAt: types.StringValue(time.Now().Format(time.RFC3339)),
98-
ValidUntil: types.StringValue(time.Now().Add(24 * time.Hour).Format(time.RFC3339)),
99-
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
93+
Id: types.StringValue("pid,aid,email"),
94+
ProjectId: types.StringValue("pid"),
95+
ServiceAccountEmail: types.StringValue("email"),
96+
Token: types.StringValue("token"),
97+
AccessTokenId: types.StringValue("aid"),
98+
Active: types.BoolValue(true),
99+
CreatedAt: types.StringValue(time.Now().Format(time.RFC3339)),
100+
ValidUntil: types.StringValue(time.Now().Add(24 * time.Hour).Format(time.RFC3339)),
101+
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
100102
},
101103
true,
102104
},
@@ -132,8 +134,9 @@ func TestMapCreateResponse(t *testing.T) {
132134
for _, tt := range tests {
133135
t.Run(tt.description, func(t *testing.T) {
134136
model := &Model{
135-
ProjectId: tt.expected.ProjectId,
136-
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
137+
ProjectId: tt.expected.ProjectId,
138+
ServiceAccountEmail: tt.expected.ServiceAccountEmail,
139+
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
137140
}
138141
err := mapCreateResponse(tt.input, model)
139142
if !tt.isValid && err == nil {
@@ -167,12 +170,13 @@ func TestMapListResponse(t *testing.T) {
167170
ValidUntil: utils.Ptr(time.Now().Add(24 * time.Hour)),
168171
},
169172
Model{
170-
Id: types.StringValue("pid,aid"),
171-
ProjectId: types.StringValue("pid"),
172-
AccessTokenId: types.StringValue("aid"),
173-
CreatedAt: types.StringValue(time.Now().Format(time.RFC3339)), // Adjusted for test setup time
174-
ValidUntil: types.StringValue(time.Now().Add(24 * time.Hour).Format(time.RFC3339)), // Adjust for format
175-
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
173+
Id: types.StringValue("pid,aid,email"),
174+
ProjectId: types.StringValue("pid"),
175+
ServiceAccountEmail: types.StringValue("email"),
176+
AccessTokenId: types.StringValue("aid"),
177+
CreatedAt: types.StringValue(time.Now().Format(time.RFC3339)), // Adjusted for test setup time
178+
ValidUntil: types.StringValue(time.Now().Add(24 * time.Hour).Format(time.RFC3339)), // Adjust for format
179+
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
176180
},
177181
true,
178182
},
@@ -204,8 +208,9 @@ func TestMapListResponse(t *testing.T) {
204208
for _, tt := range tests {
205209
t.Run(tt.description, func(t *testing.T) {
206210
model := &Model{
207-
ProjectId: tt.expected.ProjectId,
208-
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
211+
ProjectId: tt.expected.ProjectId,
212+
ServiceAccountEmail: tt.expected.ServiceAccountEmail,
213+
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
209214
}
210215
err := mapListResponse(tt.input, model)
211216
if !tt.isValid && err == nil {

0 commit comments

Comments
 (0)