Terraform import error "ID was missing the policyAssignments element"

I am facing issue while importing below azure resources.

azurerm_subscription_policy_assignment : while importing policy assignment getting error "ID was missing the policyAssignments element’ .
ID passed has policyassigments which is case sensitive issue, tried to modify as policyAssignments and tried import command but no luck.

similar issue with azurerm_virtual_machine_data_disk_attachment resource import

terraform import azurerm_virtual_machine_data_disk_attachment.disk0 /subscriptions/xxxxx/resourceGroups/xxx/providers/Microsoft.Compute/disks/vmimport01_DataDisk_0
Error: ID was missing the virtualMachines element

In this case terraform expecting virtualMachines in id but azure resource id doesn’t have it.

Please help to fix this issue, below are terraform and azure provider versions

required_version = “>= 1.5”
required_providers {
azurerm = {
source = “hashicorp/azurerm”
version = “3.64.0”
}

Hi @Ramadasui for policyAssignments ID just make sure to capitalize the scope prefixes as per the regex it is implemented.

EG:
terraform import “azurerm_subscription_policy_assignment.policy” “/subscriptions/a47d-46bf-weww-weww-weww-weww/providers/Microsoft.Authorization/policyAssignments/sample-dev-policy”

In the above example the Msft provider for Authorization should also be capitalized like above. you might have to fix that in your ID value.

Likewise see what could be done for the virtual machine element. Hope this helps!

Thanks,
Satish

Thanks Satish, it worked