-
Notifications
You must be signed in to change notification settings - Fork 5
Fix service datasource returning null due to failing system lookups #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
kind: Fixed | ||
body: Fix service datasource bug caused by system retrieval | ||
time: 2025-10-15T16:02:02.994175-07:00 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,32 +258,27 @@ func (d *ServiceDataSource) Read(ctx context.Context, req datasource.ReadRequest | |
|
||
stateModel := NewServiceDataSourceModel(ctx, service, planModel.Alias.ValueString()) | ||
|
||
system, err := service.GetSystem(d.client, nil) | ||
if err != nil { | ||
diags.AddAttributeError( | ||
path.Root("system"), | ||
"OpsLevel Client Error", | ||
fmt.Sprintf("unable to read System for service, got error: %s", err), | ||
) | ||
return | ||
} | ||
if system == nil { | ||
sys := newSystemDataSourceModel(*system) | ||
stateModel.System = &sys | ||
// In the future we can use `service.GetSystem()` to get full data | ||
// but for now, GetSystem is not working in opslevel-go | ||
if service.Parent != nil { | ||
aliases := OptionalStringListValue(service.Parent.Aliases) | ||
stateModel.System = &systemDataSourceModel{ | ||
Aliases: aliases, | ||
Id: ComputedStringValue(string(service.Parent.Id)), | ||
} | ||
} | ||
|
||
// NOTE: service's hydrate does not populate properties | ||
properties, err := service.GetProperties(d.client, nil) | ||
if err != nil { | ||
diags.AddAttributeError( | ||
resp.Diagnostics.AddAttributeError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. couple minor changes here with error handling:
|
||
path.Root("properties"), | ||
"OpsLevel Client Error", | ||
fmt.Sprintf("unable to read Properties for service, got error: %s", err), | ||
) | ||
return | ||
} | ||
if properties != nil { | ||
} else if properties != nil { | ||
stateModel.Properties, diags = NewPropertiesAllModel(ctx, properties.Nodes) | ||
resp.Diagnostics.Append(diags...) | ||
} | ||
|
||
if service.Repositories == nil { | ||
|
@@ -294,6 +289,7 @@ func (d *ServiceDataSource) Read(ctx context.Context, req datasource.ReadRequest | |
types.StringType, | ||
flattenServiceRepositoriesArray(service.Repositories), | ||
) | ||
resp.Diagnostics.Append(diags...) | ||
} | ||
|
||
// Save data into Terraform state | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
variables { | ||
api_token = "" | ||
} | ||
|
||
run "datasource_service_reads_fields" { | ||
command = plan | ||
|
||
variables { | ||
api_token = var.api_token | ||
name = "Test Service for Data Source" | ||
} | ||
|
||
module { | ||
source = "./service" | ||
} | ||
|
||
assert { | ||
condition = data.opslevel_service.first_service_by_id.id != null | ||
error_message = "expected id to be set for opslevel_service data source" | ||
} | ||
|
||
assert { | ||
condition = data.opslevel_service.first_service_by_id.name != null | ||
error_message = "expected name to be set for opslevel_service data source" | ||
} | ||
|
||
assert { | ||
condition = data.opslevel_service.first_service_by_id.description != null | ||
error_message = "expected description to be set for opslevel_service data source" | ||
} | ||
|
||
assert { | ||
condition = can(data.opslevel_service.first_service_by_id.owner) | ||
error_message = "expected owner field to be accessible for opslevel_service data source" | ||
} | ||
|
||
assert { | ||
condition = data.opslevel_service.last_service.id != null | ||
error_message = "expected id to be set for opslevel_service data source" | ||
} | ||
|
||
assert { | ||
condition = data.opslevel_service.last_service.name != null | ||
error_message = "expected name to be set for opslevel_service data source" | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apparently opslevel-go's
GetSystem
tries to retrievesystem
on Service, but the field isparent
😢