-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor/migrate region #230
Conversation
4eae769
to
0a16063
Compare
0a16063
to
1bd9e0d
Compare
1bd9e0d
to
4a37c93
Compare
d671726
to
a9f419d
Compare
a9f419d
to
27850ba
Compare
4a37c93
to
e10ed27
Compare
9e0a157
to
4072841
Compare
27850ba
to
228bfef
Compare
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.
Thanks for your work, @YanniHu1996. The PR is going in a good direction, IMHO.
I've requested some changes.
After you fix them, please check the following:
- Please make sure to run a
make docs
for the latest documentation. - Please ensure that the examples are correct. In the examples, we can add
bah:aws
to thecloud_provider
variables, for example thebiganimal_regions
data source. - please test the
biganimal_region
andbiganimal_regions
data sources, working as expected. (biganimal_region
giving a deprecation notice). - please test the
biganimal_region
resource, preferably with the acceptance tests. If you need to introduce new tests for thebiganimal_region
resource other than the Basic test, we can include it within this PR.
Thanks a lot!
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.
Some style related changes are requested. Thank you 🙏
pkg/provider/data_source_regions.go
Outdated
} else { | ||
respRegions, err := r.client.List(ctx, *cfg.ProjectId, *cfg.CloudProvider, cfg.Query.ValueString()) | ||
if err != nil { | ||
return |
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.
There is something wrong in this part of the code.
We call the r.client.List
and read the response or check if there is any error.
If there is any error, we're not adding it to resp.Diagnostics
.
If I'm not mistaken, we need to res.Diagnostics.AddError
this error, and then return the method.
Otherwise, when I have an BA API error, such as no token
etc., current implementation misses that.
pkg/provider/utils.go
Outdated
@@ -35,3 +38,12 @@ func unsupportedWarning(message string) diag.Diagnostics { | |||
}, | |||
} | |||
} | |||
|
|||
func fromErr(err error, summary string, args ...any) diag2.Diagnostics { |
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.
This function is quite dangerous.
When we use fromErr
, it will remove all the other Diagnostics that were created during any Method (can be warnings etc.) and will return a clean New Error Diagnostic that returns a given error.
Please use any Diagnostics method to add the error (AddError ideally) instead of completely overriding the errors.
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.
Hi Serdar, could you please provide more information about the statement "This function is quite dangerous"? As I understand it, this function returns "Diagnostics," which will be appended to resp.Diagnostics
using the Append
method. It should not overwrite any existing diagnostics. The purpose of fromErr
is to convert errors into Diagnostics
by accepting an error type parameter. On the other hand, Diagnostics.AddError
does not accept an error parameter, which means you need to convert the error to a string in your subsequent code
Co-authored-by: Serdar Dalgıç <[email protected]>
Co-authored-by: Serdar Dalgıç <[email protected]>
Co-authored-by: Serdar Dalgıç <[email protected]>
Co-authored-by: Serdar Dalgıç <[email protected]>
Co-authored-by: Serdar Dalgıç <[email protected]>
Co-authored-by: Serdar Dalgıç <[email protected]>
433cfee
to
9b76e3f
Compare
2d8bca0
to
f663691
Compare
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.
The PR looks good to me. Thanks for your work, @YanniHu1996 . 🎉
No description provided.