Skip to content

Commit 4c7c882

Browse files
fixes catalog item destroy failures when display name wasn't changed (#138)
1 parent d6ead16 commit 4c7c882

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

internal/provider/resources/space_ado_server_repository_resource.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,16 @@ func (r *TorqueSpaceAdoServerRepositoryResource) Create(ctx context.Context, req
164164
}
165165
}
166166
start := time.Now()
167-
err := r.client.OnboardAdoServerRepoToSpace(data.SpaceName.ValueString(), data.RepositoryName.ValueString(),
167+
onboardErr := r.client.OnboardAdoServerRepoToSpace(data.SpaceName.ValueString(), data.RepositoryName.ValueString(),
168168
data.RepositoryUrl.ValueString(), data.Token.ValueStringPointer(), data.Branch.ValueString(), data.CredentialName.ValueString(), agents, data.UseAllAgents.ValueBool(), data.AutoRegisterEac.ValueBool())
169-
if err != nil {
169+
if onboardErr != nil {
170170
repo, err := r.client.GetRepoDetails(data.SpaceName.ValueString(), data.RepositoryName.ValueString())
171171
if repo == nil {
172-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to onboard repository to space, got error: %s", err))
172+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to onboard repository to space, got error: %s", onboardErr))
173+
return
174+
}
175+
if err != nil {
176+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to onboard repository to space, got error: %s", onboardErr))
173177
return
174178
}
175179
if repo.Status == StatusSyncing {
@@ -189,7 +193,7 @@ func (r *TorqueSpaceAdoServerRepositoryResource) Create(ctx context.Context, req
189193
resp.Diagnostics.AddError("Sync Timeout", "Timed out while syncing repository")
190194
return
191195
}
192-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to onboard repository to space, got error: %s", err))
196+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to onboard repository to space, got error: %s", onboardErr))
193197
return
194198
}
195199
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)

internal/provider/resources/torque_catalog_item_resource.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,20 @@ func (r *TorqueCatalogItemResource) Delete(ctx context.Context, req resource.Del
429429
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to set blueprint policies, got error: %s", err))
430430
return
431431
}
432-
err = r.client.UpdateBlueprintDisplayName(data.SpaceName.ValueString(), data.RepositoryName.ValueString(), data.BlueprintName.ValueString(), data.BlueprintName.ValueString())
433-
if err != nil {
434-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create Catalog Item, failed to set blueprint display name, got error: %s", err))
435-
return
432+
// Only reset the display name if the user had explicitly set a custom one.
433+
// When display_name was never provided, it is stored in state as the blueprint name;
434+
// calling the API with the same value causes a 422, so we skip the call.
435+
// This is a temporary solution, ideally the API should allow idempotent calls to update the display name even when the value doesn't change.
436+
if data.DisplayName.ValueString() != data.BlueprintName.ValueString() {
437+
err = r.client.UpdateBlueprintDisplayName(data.SpaceName.ValueString(), data.RepositoryName.ValueString(), data.BlueprintName.ValueString(), data.BlueprintName.ValueString())
438+
if err != nil {
439+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to reset blueprint display name, got error: %s", err))
440+
return
441+
}
436442
}
437443
err = r.client.EditCatalogItemLabels(data.SpaceName.ValueString(), data.BlueprintName.ValueString(), data.RepositoryName.ValueString(), nil)
438444
if err != nil {
439-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to remove Catalog Item custom icon, failed to set catalog item custom icon, got error: %s", err))
445+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to remove Catalog Item labels, got error: %s", err))
440446
return
441447
}
442448
}

0 commit comments

Comments
 (0)