terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Confusing extra quoting in import error message for "object not found"

Open apparentlymart opened this issue 2 years ago • 0 comments

(Originally discussed in a Reddit post.)

It seems that when Terraform asks a provider to import something and the provider reports "not found", Terraform is producing an error message which includes the resource address in quoted form, rather than in the typical "naked" form:

╷
│ Error: Cannot import non-existent remote object
│
│ While attempting to import an existing object to "azurerm_pim_eligible_role_assignment.role-vdi-vmadminpim[\"Team3\"]", 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.  
╵

Resource instance addresses should not be presented in quotes, because they aren't written in quotes in the configuration and because (as shown here) they sometimes contain quotes themselves, making the result misleading for someone who isn't familiar with Terraform's internals. (In the original question, this made both me and the person who saw it originally think the problem was caused by the escaping on the command line, since unfortunately the command line quote-escaping conventions are the same on Windows.)

I'm guessing this is really just an accidental use of %q instead of %s in a fmt.Sprintf call, in which case it's hopefully easy to fix so that the error message won't lead folks to try to solve the wrong problem in future.

apparentlymart avatar Oct 20 '23 23:10 apparentlymart