The Drum playing Computer Scientist
How to fix “Error parsing Resource ID […]: ID contained more segments than required” in Terraform

How to fix “Error parsing Resource ID […]: ID contained more segments than required” in Terraform

Hey folks,

today i would like to give you a quick hint in the hope of saving you an hour’s worth of pondering.

Our starting position:

To long to read

Update: 24.01.23:

Thanks to Sven for pointing out an even better solution, as described here:

https://github.com/hashicorp/terraform-provider-azurerm/issues/2208

Original:

Use Powershell.

The whole story

So, we enthusiasticly open our shell and smash something like

 terraform import azurerm_resource_group.xxxxx <resourceID>Code language: HTML, XML (xml)

and straight in our face comes this

Error: Error parsing Resource ID <resourceID> ID contained more segments than required: <resourceID>Code language: JavaScript (javascript)

Now, hell breaks loose, we check our commands triple times, change the <resourceID> to lower and uppercase but nothing changes.

But wait…

Why the heck contains the <resourceID> of the error message our local file system?!
Something like:

C:/git/subscriptions/xxxxCode language: JavaScript (javascript)

Powershell to the rescue

It would appear that the <resourceID> is not correctly transmitted to the Azure Provider Plugin and therefore not correctly parsed.


Just using Powershell resolved the issue for me.

The end

Thats all for today folks, i hope i can save someone a little bit of headache.

Have a nice day!

Armin