Skip to content
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

Merged
merged 52 commits into from
Jul 11, 2023
Merged

Refactor/migrate region #230

merged 52 commits into from
Jul 11, 2023

Conversation

YanniHu1996
Copy link
Contributor

No description provided.

@YanniHu1996 YanniHu1996 changed the base branch from main to refactor/migrate-project May 15, 2023 11:33
@YanniHu1996 YanniHu1996 force-pushed the refactor/migrate-region branch from 4eae769 to 0a16063 Compare May 15, 2023 11:58
@YanniHu1996 YanniHu1996 force-pushed the refactor/migrate-region branch from 0a16063 to 1bd9e0d Compare May 24, 2023 08:06
@YanniHu1996 YanniHu1996 force-pushed the refactor/migrate-region branch from 1bd9e0d to 4a37c93 Compare May 31, 2023 10:24
@YanniHu1996 YanniHu1996 force-pushed the refactor/migrate-project branch 4 times, most recently from d671726 to a9f419d Compare June 6, 2023 06:32
@YanniHu1996 YanniHu1996 force-pushed the refactor/migrate-project branch from a9f419d to 27850ba Compare June 8, 2023 08:18
@YanniHu1996 YanniHu1996 force-pushed the refactor/migrate-region branch from 4a37c93 to e10ed27 Compare June 8, 2023 08:21
@YanniHu1996 YanniHu1996 force-pushed the refactor/migrate-region branch from 9e0a157 to 4072841 Compare June 8, 2023 09:42
@YanniHu1996 YanniHu1996 force-pushed the refactor/migrate-project branch from 27850ba to 228bfef Compare June 8, 2023 09:42
Copy link
Contributor

@serdardalgic serdardalgic left a 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 the cloud_provider variables, for example the biganimal_regions data source.
  • please test the biganimal_region and biganimal_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 the biganimal_region resource other than the Basic test, we can include it within this PR.

Thanks a lot!

docs/data-sources/pgd.md Outdated Show resolved Hide resolved
docs/data-sources/region.md Outdated Show resolved Hide resolved
pkg/provider/data_source_regions.go Outdated Show resolved Hide resolved
pkg/provider/data_source_regions.go Outdated Show resolved Hide resolved
pkg/provider/data_source_regions_test.go Outdated Show resolved Hide resolved
pkg/provider/resource_region.go Outdated Show resolved Hide resolved
pkg/provider/resource_region.go Outdated Show resolved Hide resolved
pkg/provider/resource_region.go Outdated Show resolved Hide resolved
templates/data-sources/regions.md.tmpl Outdated Show resolved Hide resolved
pkg/provider/validators.go Show resolved Hide resolved
Copy link
Contributor

@serdardalgic serdardalgic left a 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 🙏

.env.example Outdated Show resolved Hide resolved
examples/data-sources/biganimal_region/data-source.tf Outdated Show resolved Hide resolved
pkg/provider/data_source_regions.go Outdated Show resolved Hide resolved
pkg/provider/resource_region.go Outdated Show resolved Hide resolved
pkg/provider/utils.go Outdated Show resolved Hide resolved
pkg/provider/utils.go Outdated Show resolved Hide resolved
} else {
respRegions, err := r.client.List(ctx, *cfg.ProjectId, *cfg.CloudProvider, cfg.Query.ValueString())
if err != nil {
return
Copy link
Contributor

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.

@@ -35,3 +38,12 @@ func unsupportedWarning(message string) diag.Diagnostics {
},
}
}

func fromErr(err error, summary string, args ...any) diag2.Diagnostics {
Copy link
Contributor

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.

Copy link
Contributor Author

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

YanniHu1996 and others added 7 commits June 29, 2023 14:49
@YanniHu1996 YanniHu1996 force-pushed the refactor/migrate-region branch from 433cfee to 9b76e3f Compare June 29, 2023 08:08
@YanniHu1996 YanniHu1996 force-pushed the refactor/migrate-region branch from 2d8bca0 to f663691 Compare July 11, 2023 06:08
Copy link
Contributor

@serdardalgic serdardalgic left a 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 . 🎉

@serdardalgic serdardalgic merged commit 92afa7f into main Jul 11, 2023
@serdardalgic serdardalgic deleted the refactor/migrate-region branch July 11, 2023 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants