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

Error handling project and members #356

Merged
merged 6 commits into from
Sep 29, 2023

Conversation

naitmare01
Copy link
Contributor

This PR introduces error-handling to gracefully update and recreate resources that have been altered outside of Terraform.

  • project
  • project_member_group
  • project_member_user

This fixes #235

@flbla
Copy link
Contributor

flbla commented Aug 18, 2023

Hi @naitmare01,
thanks

there is an issue with the SendRequest function : https://github.com/goharbor/terraform-provider-harbor/blob/main/client/client.go#L88
instead of return resp.StatusCode it return 0 when the expected status code is different of the status code.

if we fix that, it will be handle by : https://github.com/goharbor/terraform-provider-harbor/blob/main/provider/resource_project.go#L96 if respCode == 404 && err != nil in the resourceProjectRead function.

same for other resources

Copy link
Contributor

@flbla flbla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to fix SendRequest function

@naitmare01
Copy link
Contributor Author

@flbla I agree that SendRequest needs to be fixed. That explains why I was having trouble getting proper response-code when I wrote this PR.

Are there any active issue or PR coming to fix that? I suggest we wait with this PR until that is fixed.

@flbla
Copy link
Contributor

flbla commented Aug 18, 2023

There is no PR yet. I discovered the bug will reviewing your PR.

@flbla
Copy link
Contributor

flbla commented Aug 21, 2023

@naitmare01 : #363
I did some tests, it seems better.

@naitmare01
Copy link
Contributor Author

LGTM!

@flbla
Copy link
Contributor

flbla commented Aug 21, 2023

@naitmare01
Copy link
Contributor Author

I merged #363 i think we can return nil here : https://github.com/goharbor/terraform-provider-harbor/pull/356/files#diff-8872ceb4daebf7b2223fb0a0341bd06991a1758ec72c38dcf9fc66a396638533R98 to handle it

I think it will work fine. But isn't it more clear if we actually return what the error is about instead of nil?

@flbla
Copy link
Contributor

flbla commented Aug 23, 2023

if we return an error, it will not handle resources deleted outside of terraform
maybe I misunderstood what you want to do ?

@naitmare01
Copy link
Contributor Author

It was I who misunderstood you. :)

Changed to nil in the latest commit.

@naitmare01
Copy link
Contributor Author

@flbla are you waiting for any more changes from me?

@flbla flbla force-pushed the error-handling-project-and-members branch from bdd6a7a to 3f05046 Compare September 29, 2023 09:44
provider/resource_project.go Outdated Show resolved Hide resolved
provider/resource_project.go Outdated Show resolved Hide resolved
@flbla flbla merged commit 773a1fd into goharbor:main Sep 29, 2023
10 of 11 checks passed
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.

Provider does not handle missing members of project correctly
2 participants