parent
d1e12fcf64
commit
24b7387db9
140 changed files with 1597 additions and 7 deletions
|
|
@ -179,6 +179,8 @@ func (r *serviceAccountTokenResource) Create(ctx context.Context, req resource.C
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
// Set logging context with the project ID and service account email.
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
|
||||
|
|
@ -194,12 +196,13 @@ func (r *serviceAccountTokenResource) Create(ctx context.Context, req resource.C
|
|||
|
||||
// Initialize the API request with the required parameters.
|
||||
serviceAccountAccessTokenResp, err := r.client.CreateAccessToken(ctx, projectId, serviceAccountEmail).CreateAccessTokenPayload(*payload).Execute()
|
||||
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Failed to create service account access token", fmt.Sprintf("API call error: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Map the response to the resource schema.
|
||||
err = mapCreateResponse(serviceAccountAccessTokenResp, &model)
|
||||
if err != nil {
|
||||
|
|
@ -227,6 +230,8 @@ func (r *serviceAccountTokenResource) Read(ctx context.Context, req resource.Rea
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
// Extract the project ID and serviceAccountEmail for the service account.
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
|
||||
|
|
@ -245,6 +250,8 @@ func (r *serviceAccountTokenResource) Read(ctx context.Context, req resource.Rea
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Iterate over the list of service account tokens to find the one that matches the ID from the state.
|
||||
saTokens := *listSaTokensResp.Items
|
||||
for i := range saTokens {
|
||||
|
|
@ -296,6 +303,8 @@ func (r *serviceAccountTokenResource) Delete(ctx context.Context, req resource.D
|
|||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
|
||||
accessTokenId := model.AccessTokenId.ValueString()
|
||||
|
|
@ -309,6 +318,9 @@ func (r *serviceAccountTokenResource) Delete(ctx context.Context, req resource.D
|
|||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting service account token", fmt.Sprintf("Calling API: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
tflog.Info(ctx, "Service account token deleted")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue