Logging and error handling improvements, bug fixes (#21)
- Uniformed logs and diagnostics: - Logging and adding to diagnostics is done by the highest level function (Create/Read/Update/Delete/Import) using `LogAndAddError` - Lower-level routines' signature changed to return error instead of writing to diagnostics - Standardize summary and details across services - Removed manual adding of relevant variables to details (they're in the context, TF adds them to logs) - Changed validators to be closer to official implementation - Fix logging wrong output after wait - Fix Argus checking wrong diagnostics - Fix Resource Manager not updating state after project update - Fix unnecessary pointer in LogAndAddError
This commit is contained in:
parent
29b8c91999
commit
4e8514df00
51 changed files with 1389 additions and 1092 deletions
|
|
@ -45,7 +45,7 @@ func (r *clusterDataSource) Configure(ctx context.Context, req datasource.Config
|
|||
|
||||
providerData, ok := req.ProviderData.(core.ProviderData)
|
||||
if !ok {
|
||||
resp.Diagnostics.AddError("Unexpected Data Source Configure Type", fmt.Sprintf("Expected stackit.ProviderData, got %T. Please report this issue to the provider developers.", req.ProviderData))
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring API client", fmt.Sprintf("Expected configure type stackit.ProviderData, got %T", req.ProviderData))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -64,12 +64,12 @@ func (r *clusterDataSource) Configure(ctx context.Context, req datasource.Config
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Could not Configure API Client", err.Error())
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring API client", fmt.Sprintf("Configuring client: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "SKE client configured")
|
||||
r.client = apiClient
|
||||
tflog.Info(ctx, "SKE client configured")
|
||||
}
|
||||
func (r *clusterDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
|
|
@ -292,19 +292,22 @@ func (r *clusterDataSource) Read(ctx context.Context, req datasource.ReadRequest
|
|||
ctx = tflog.SetField(ctx, "name", name)
|
||||
clusterResp, err := r.client.GetCluster(ctx, projectId, name).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, fmt.Sprintf("Unable to read cluster, project_id = %s, name = %s", projectId, name), err.Error())
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading cluster", fmt.Sprintf("Calling API: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
err = mapFields(ctx, clusterResp, &state)
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Mapping fields", err.Error())
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading cluster", fmt.Sprintf("Processing API payload: %v", err))
|
||||
return
|
||||
}
|
||||
r.getCredential(ctx, &diags, &state)
|
||||
// Set refreshed state
|
||||
diags = resp.State.Set(ctx, state)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "SKE cluster read")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue