Skip to content

Commit

Permalink
WIP: PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbloss committed Oct 15, 2024
1 parent 581ff17 commit f88a4de
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 48 deletions.
4 changes: 0 additions & 4 deletions opslevel/resource_opslevel_property_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ func (resource *PropertyAssignmentResource) Read(ctx context.Context, req resour
owner := planModel.Owner.ValueString()
assignment, err := resource.client.GetProperty(owner, definition)
if err != nil {
if (assignment == nil || assignment.Definition.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("unable to read property assignment '%s' on service '%s', got error: %s", definition, owner, err))
return
}
Expand Down
8 changes: 4 additions & 4 deletions opslevel/resource_opslevel_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ func (r *RepositoryResource) Create(ctx context.Context, req resource.CreateRequ
repository, err = r.client.GetRepositoryWithAlias(identifier)
}
if err != nil {
if (repository == nil || repository.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to get repository, got error: %s", err))
return
}
Expand Down Expand Up @@ -143,6 +139,10 @@ func (r *RepositoryResource) Read(ctx context.Context, req resource.ReadRequest,

readRepository, err := r.client.GetRepository(opslevel.ID(planModel.Id.ValueString()))
if err != nil || readRepository == nil {
if (readRepository == nil || readRepository.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read repository, got error: %s", err))
return
}
Expand Down
6 changes: 1 addition & 5 deletions opslevel/resource_opslevel_service_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ func (r *ServiceDependencyResource) Read(ctx context.Context, req resource.ReadR
service, err = r.client.GetServiceWithAlias(serviceIdentifier)
}
if err != nil {
if (service == nil || service.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read service, got error: %s", err))
return
}
Expand All @@ -160,7 +156,7 @@ func (r *ServiceDependencyResource) Read(ctx context.Context, req resource.ReadR
}
extractedServiceDependency := extractServiceDependency(planModel.Id.ValueString(), *dependencies)
if extractedServiceDependency == nil {
resp.Diagnostics.AddError("opslevel client error", "Unable to extract service dependency")
resp.State.RemoveResource(ctx)
return
}

Expand Down
10 changes: 3 additions & 7 deletions opslevel/resource_opslevel_service_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ func (r *ServiceRepositoryResource) Read(ctx context.Context, req resource.ReadR
service, err = r.client.GetServiceWithAlias(currentStateModel.ServiceAlias.ValueString())
}
if err != nil {
if (service == nil || service.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read service, got error: %s", err))
return
}
Expand All @@ -224,10 +220,10 @@ func (r *ServiceRepositoryResource) Read(ctx context.Context, req resource.ReadR
}
}
if serviceRepository == nil {
verifiedStateModel = ServiceRepositoryResourceModel{}
} else {
verifiedStateModel = NewServiceRepositoryResourceModel(ctx, *serviceRepository, currentStateModel)
resp.State.RemoveResource(ctx)
return
}
verifiedStateModel = NewServiceRepositoryResourceModel(ctx, *serviceRepository, currentStateModel)

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &verifiedStateModel)...)
Expand Down
8 changes: 2 additions & 6 deletions opslevel/resource_opslevel_service_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ func (serviceTagResource *ServiceTagResource) Read(ctx context.Context, req reso
return
}
_, err = service.GetTags(serviceTagResource.client, nil)
if err != nil {
if service.Tags == nil && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
if err != nil || service.Tags == nil {
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("unable to read tags on service (%s), got error: %s", serviceIdentifier, err))
}
var serviceTag *opslevel.Tag
Expand All @@ -179,7 +175,7 @@ func (serviceTagResource *ServiceTagResource) Read(ctx context.Context, req reso
}
}
if serviceTag == nil {
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("service tag (with key '%s') not found on service (%s)", data.Key.ValueString(), serviceIdentifier))
resp.State.RemoveResource(ctx)
return
}

Expand Down
10 changes: 5 additions & 5 deletions opslevel/resource_opslevel_service_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ func (r *ServiceToolResource) Create(ctx context.Context, req resource.CreateReq
service, err = r.client.GetServiceWithAlias(planModel.ServiceAlias.ValueString())
}
if err != nil {
if (service == nil || service.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to get service during create, got error: %s", err))
return
}
Expand All @@ -155,7 +151,11 @@ func (r *ServiceToolResource) Create(ctx context.Context, req resource.CreateReq
ServiceId: &service.Id,
Url: planModel.Url.ValueString(),
})
if err != nil || serviceTool == nil || string(serviceTool.Id) == "" {
if err != nil {
if (serviceTool == nil || serviceTool.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to create service tool, got error: %s", err))
return
}
Expand Down
4 changes: 0 additions & 4 deletions opslevel/resource_opslevel_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ func (r *TagResource) Read(ctx context.Context, req resource.ReadRequest, resp *
resourceType := opslevel.TaggableResource(planModel.TargetType.ValueString())
data, err := r.client.GetTaggableResource(resourceType, resourceId)
if err != nil {
if (data == nil || data.ResourceId() == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read tag, got error: %s", err))
return
}
Expand Down
10 changes: 3 additions & 7 deletions opslevel/resource_opslevel_team_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ func (teamContactResource *TeamContactResource) Read(ctx context.Context, req re
} else {
team, err = teamContactResource.client.GetTeamWithAlias(teamIdentifier)
}
if err != nil {
if (team == nil || team.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
if err != nil || team == nil {
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("unable to read team (%s), got error: %s", teamIdentifier, err))
return
}
Expand All @@ -154,8 +150,8 @@ func (teamContactResource *TeamContactResource) Read(ctx context.Context, req re
break
}
}
if teamContact == nil {
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("team contact (with ID '%s') not found on team (%s)", contactID, teamIdentifier))
if teamContact == nil || teamContact.Id == "" {
resp.State.RemoveResource(ctx)
return
}

Expand Down
8 changes: 2 additions & 6 deletions opslevel/resource_opslevel_team_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ func (teamTagResource *TeamTagResource) Read(ctx context.Context, req resource.R
return
}
_, err = team.GetTags(teamTagResource.client, nil)
if err != nil {
if team.Tags == nil && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
if err != nil || team.Tags == nil {
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("unable to read tags on team (%s), got error: %s", teamIdentifier, err))
}
var teamTag *opslevel.Tag
Expand All @@ -186,7 +182,7 @@ func (teamTagResource *TeamTagResource) Read(ctx context.Context, req resource.R
}
}
if teamTag == nil {
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("team tag (with key '%s') not found on team (%s)", data.Key.ValueString(), teamIdentifier))
resp.State.RemoveResource(ctx)
return
}

Expand Down

0 comments on commit f88a4de

Please sign in to comment.