Open augustgerro opened 4 years ago
I've seen this when monitors are deleted from outside of terraform (web portal). Provider code should handle it but looks like it needs a little bit of work but haven't had time to set up the source and debug.
Quick fix is to remove the resources in question from your statefile:
terraform state rm <resource-path>
The error message doesn't identify the resource unfortunately so you either know what they are or you'll have to figure it out some other way, terraform state list
might help
@ray-jam thank you!
But for me is not clear which resource is out of state. I guess, instead of � should be resource name
Most terraform providers would fail in the same way. Agreed messaging could be improved (seems like that’s a bug itself), but getting an error when a resource is deleted outside of terraform is expected behaviour (I don’t think it’s even possible for a provider to delete its own state when an error like this happens) to protect users from irreversible consequences when network/server-side issues happen
Couldn't find it to start with but check this part of the docs: https://www.terraform.io/docs/plugins/provider.html#read
What it says is: If the resource is no longer present, calling SetId with an empty string will signal its removal.
I use AWS/Azure providers frequently and if someone has gone off script and deleted resources through the portal the subsequent terraform plan
will just tell us "new resource" and recreate them. That is a lot easier on us as we don't have to jump in to the whole statefile management commands that are really there for exceptional circumstances.
The read
function needs to error when it fails the call for authorisation or such but otherwise if you can identify it is just drift then SetId("")
is recommended. Rough sample from the read function for a provider we were messing around with:
info, err := auth.GetContactGroupInfo(groupID)
if err != nil {
return fmt.Errorf("Error from GetContactInfo: %s", err)
}
// If the resource does not exist, inform Terraform. We want to immediately
// return here to prevent further processing.
if info == nil || string(info.GroupID) != groupID {
data.SetId("")
return nil
}
Guess it comes down to is it an error or just drift. If it is drift then ideally my plan will show me because I'll see the "new resources" being recreated when I review the output and they would be unexpected based on my changes at which point I can choose to cancel, update the tf code and plan again or just apply because I know they shouldn't have been deleted.
By the way thanks for the provider appreciate it being here :) and the effort behind it
Ah makes sense. Wasn’t aware of this. Prob won’t have time to implement but if anyone else wants to send a PR I’ll happily merge
Encountered the same issue sadly, so anybody working on a PR would be much appreciated 👍
I used to run the code and everything worked, now I'm running the plan and I get an unclear error:
Run
Output log