@@ -25,6 +25,7 @@ import (
2525 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
2626 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
2727 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
28+ "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
2829 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
2930)
3031
@@ -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.
112113func (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
117118func (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.
286286func (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.
292292func (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
0 commit comments