Open jcardinal opened 8 months ago
Hi @jcardinal, can you tell me exactly how to replicate this plugin crash? Whenever I try to run the import without team_id, I'm not getting a plugin crash, instead, I get this error:
Planning failed. Terraform encountered an error while generating this plan.
│ Error: Cannot import non-existent remote object
│
│ While attempting to import an existing object to "opsgenie_alert_policy.koushikTest", the provider detected that no object
│ exists with the given id. Only pre-existing objects can be imported; check that the id is correct and that it is associated
│ with the provider's configured region or endpoint, or use "terraform apply" to create a new remote object for this resource.
@koushik-swaminathan is it possible you're using an API key with global privileges? When I encountered the error, I was using an API key with team-level scope. I'm guessing the API returns a different error depending on whether the key allows the caller to know whether the given global ID exists.
I found that attempting to import a team alert policy without specifying the team_id would crash the plugin without providing the user with useful feedback:
We were handling 404's specifically, but ignoring other error types. I've added error handling for other error types and confirms it fixed my particular crash:
I believe this will also resolve this issue.
As an aside, I introduced the pattern of using the
tflog
package for logging, instead of thelog
package. Terraform now recommends this pattern for logging, and it solves the issue I raised here, where filtering logs by level does not work correctly.