Skip to content

Commit 7545496

Browse files
committed
review changes
1 parent 3b7f0ec commit 7545496

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

docs/resources/service_account_key.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
page_title: "stackit_service_account_key Resource - stackit"
44
subcategory: ""
55
description: |-
6-
Service account access key schema.
6+
Service account key 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 service account keys
@@ -30,7 +30,7 @@ description: |-
3030

3131
# stackit_service_account_key (Resource)
3232

33-
Service account access key schema.
33+
Service account key 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

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
89
"net/http"
910
"strings"
1011
"time"
@@ -108,7 +109,7 @@ func (r *serviceAccountKeyResource) Configure(ctx context.Context, req resource.
108109
tflog.Info(ctx, "Service Account client configured")
109110
}
110111

111-
// Metadata sets the resource type name for the service account resource.
112+
// Metadata sets the resource type name for the service account key resource.
112113
func (r *serviceAccountKeyResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
113114
resp.TypeName = req.ProviderTypeName + "_service_account_key"
114115
}
@@ -117,7 +118,7 @@ func (r *serviceAccountKeyResource) Metadata(_ context.Context, req resource.Met
117118
func (r *serviceAccountKeyResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
118119
descriptions := map[string]string{
119120
"id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`service_account_email`,`key_id`\".",
120-
"main": "Service account access key schema.",
121+
"main": "Service account key schema.",
121122
"project_id": "The STACKIT project ID associated with the service account key.",
122123
"key_id": "The unique identifier for the key associated with the service account.",
123124
"service_account_email": "The email address associated with the service account, used for account identification and communication.",
@@ -139,7 +140,6 @@ func (r *serviceAccountKeyResource) Schema(_ context.Context, _ resource.SchemaR
139140
Required: true,
140141
Validators: []validator.String{
141142
validate.UUID(),
142-
validate.NoSeparator(),
143143
},
144144
PlanModifiers: []planmodifier.String{
145145
stringplanmodifier.RequiresReplace(),
@@ -206,29 +206,29 @@ func (r *serviceAccountKeyResource) Create(ctx context.Context, req resource.Cre
206206
ctx = tflog.SetField(ctx, "project_id", projectId)
207207
ctx = tflog.SetField(ctx, "service_account_email", serviceAccountEmail)
208208

209-
if model.TtlDays.IsUnknown() {
209+
if utils.IsUndefined(model.TtlDays) {
210210
model.TtlDays = types.Int64Null()
211211
}
212212

213213
// Generate the API request payload.
214214
payload, err := toCreatePayload(&model)
215215
if err != nil {
216-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating service account access key", fmt.Sprintf("Creating API payload: %v", err))
216+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating service account key", fmt.Sprintf("Creating API payload: %v", err))
217217
return
218218
}
219219

220220
// Initialize the API request with the required parameters.
221221
saAccountKeyResp, err := r.client.CreateServiceAccountKey(ctx, projectId, serviceAccountEmail).CreateServiceAccountKeyPayload(*payload).Execute()
222222

223223
if err != nil {
224-
core.LogAndAddError(ctx, &resp.Diagnostics, "Failed to create service account access key", fmt.Sprintf("API call error: %v", err))
224+
core.LogAndAddError(ctx, &resp.Diagnostics, "Failed to create service account key", fmt.Sprintf("API call error: %v", err))
225225
return
226226
}
227227

228228
// Map the response to the resource schema.
229229
err = mapCreateResponse(saAccountKeyResp, &model)
230230
if err != nil {
231-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating service account access key", fmt.Sprintf("Processing API payload: %v", err))
231+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating service account key", fmt.Sprintf("Processing API payload: %v", err))
232232
return
233233
}
234234

@@ -238,7 +238,7 @@ func (r *serviceAccountKeyResource) Create(ctx context.Context, req resource.Cre
238238
if resp.Diagnostics.HasError() {
239239
return
240240
}
241-
tflog.Info(ctx, "Service account access key created")
241+
tflog.Info(ctx, "Service account key created")
242242
}
243243

244244
// Read refreshes the Terraform state with the latest service account data.
@@ -285,10 +285,10 @@ func (r *serviceAccountKeyResource) Read(ctx context.Context, req resource.ReadR
285285
// lifecycle management.
286286
func (r *serviceAccountKeyResource) Update(ctx context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) { // nolint:gocritic // function signature required by Terraform
287287
// Service accounts cannot be updated, so we log an error.
288-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating service account access key", "Service account key can't be updated")
288+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating service account key", "Service account key can't be updated")
289289
}
290290

291-
// Delete deletes the service account and removes it from the Terraform state on success.
291+
// Delete deletes the service account key and removes it from the Terraform state on success.
292292
func (r *serviceAccountKeyResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { // nolint:gocritic // function signature required by Terraform
293293
// Retrieve current state of the resource.
294294
var model Model
@@ -324,7 +324,7 @@ func toCreatePayload(model *Model) (*serviceaccount.CreateServiceAccountKeyPaylo
324324
payload := &serviceaccount.CreateServiceAccountKeyPayload{}
325325

326326
// Set ValidUntil based on TtlDays if specified
327-
if !model.TtlDays.IsUnknown() && !model.TtlDays.IsNull() {
327+
if !utils.IsUndefined(model.TtlDays) {
328328
validUntil, err := computeValidUntil(model.TtlDays.ValueInt64Pointer())
329329
if err != nil {
330330
return nil, err
@@ -333,7 +333,7 @@ func toCreatePayload(model *Model) (*serviceaccount.CreateServiceAccountKeyPaylo
333333
}
334334

335335
// Set PublicKey if specified
336-
if !model.PublicKey.IsUnknown() && model.PublicKey.String() != "" {
336+
if !utils.IsUndefined(model.PublicKey) && model.PublicKey.ValueString() != "" {
337337
payload.PublicKey = conversion.StringValueToPointer(model.PublicKey)
338338
}
339339

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestMapResponse(t *testing.T) {
101101
model := &Model{
102102
ProjectId: tt.expected.ProjectId,
103103
ServiceAccountEmail: tt.expected.ServiceAccountEmail,
104-
KeyId: tt.expected.KeyId,
104+
KeyId: types.StringNull(),
105105
Json: types.StringValue("{}"),
106106
RotateWhenChanged: types.MapValueMust(types.StringType, map[string]attr.Value{}),
107107
}

0 commit comments

Comments
 (0)