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

Consider it successful to delete a non-existing FIP #1160

Merged
merged 1 commit into from
Mar 11, 2020

Conversation

odaira
Copy link
Contributor

@odaira odaira commented Mar 5, 2020

Sometimes users need to destroy a resource without refresh terraform destroy -refresh=false for various reasons. Even when the resource does not exist any more, the delete operation should be considered successful.

This PR allows deletion of a non-existing FIP. It is already allowed for a security group rule:

err = sgC.DeleteRule(secgrpID, ruleID)
if err != nil {
iserror, ok := err.(iserrors.RiaasError)
if ok {
if len(iserror.Payload.Errors) == 1 &&
iserror.Payload.Errors[0].Code == "not_found" {
return nil
}
}
return err
}

@odaira
Copy link
Contributor Author

odaira commented Mar 9, 2020

Let me know if you have any concern with allowing deletion of a non-existing resource without refresh.

An example case where users need to run terraform destroy -refresh=false: hashicorp/terraform#15386

@hkantare
Copy link
Collaborator

@odaira Intially I was concerned with the change because according to earlier docs of Terraform if its fails to delete any resource we should return back error..but yesterday I was going through latest Terraform docs
https://www.terraform.io/docs/extend/writing-custom-providers.html#implementing-destroy

The destroy function should always handle the case where the resource might already be destroyed (manually, for example). If the resource is already destroyed, this should not return an error. 

For Read also they are saying to follow the same logic
https://www.terraform.io/docs/extend/writing-custom-providers.html#implementing-read
can we update Read Method also?

@odaira
Copy link
Contributor Author

odaira commented Mar 10, 2020

@hkantare I've never thought about Read, but yes, looks like we need to update Read as well to gracefully handle already-deleted resources.

However, I've used Terraform with IBM plugin for already-deleted resources many times, but unless I specified -refresh=false, I've never seen any weird error. I guess even with the current plugin implementation, Terraform gracefully handles an error from Read and simply considers that the resource no longer exists. (This is just my guess.)

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