-
Notifications
You must be signed in to change notification settings - Fork 763
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
Remove team from state if deletion failed and it does not exist #1039
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,6 +243,29 @@ func resourceGithubTeamDelete(d *schema.ResourceData, meta interface{}) error { | |
|
||
log.Printf("[DEBUG] Deleting team: %s", d.Id()) | ||
_, err = client.Teams.DeleteTeamByID(ctx, orgId, id) | ||
/* | ||
When deleting a team and it failed, we need to check if it has already been deleted meanwhile. | ||
This could be the case when deleting nested teams via Terraform by looping through a module | ||
or resource and the parent team might have been deleted already. If the parent team had | ||
been deleted already (via parallel runs), the child team is also already gone (deleted by | ||
GitHub automatically). | ||
So we're checking if it still exists and if not, simply remove it from TF state. | ||
*/ | ||
if err != nil { | ||
// Fetch the team in order to see if it exists or not (http 404) | ||
_, _, err = client.Teams.GetTeamByID(ctx, orgId, id) | ||
if err != nil { | ||
if ghErr, ok := err.(*github.ErrorResponse); ok { | ||
if ghErr.Response.StatusCode == http.StatusNotFound { | ||
// If team we failed to delete does not exist, remove it from TF state. | ||
log.Printf("[WARN] Removing team: %s from state because it no longer exists", | ||
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. The following warning does not show up with 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. @jcudit the only thing I'd need some help on is the logging level as the above is only showing up in
However, when looking at a valid
Any idea on what I'm doing wrong here? 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. I am stumped. This looks very similar to what I'm seeing in Does |
||
d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
} | ||
} | ||
} | ||
return err | ||
} | ||
|
||
|
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 is a really good comment to add to our docs on this resource as well.