Search code examples
terraformterraform0.12+azure-rm

Issue in importing Azure resource into Terraform state


Objective: Trying to import module.resource which is already created azure resource via terraform into my statefile

What I tried:

terraform -chdir=Terraform import synapse_workspace_pe.azurerm_private_endpoint.syn_ws_pe_dev "/subscriptions/xxxx-xxxx-xxx--xx/resourceGroups/hub/providers/Microsoft.Network/privateEndpoints/pe-cb-ab-dev-we-dev"

Error that I get:

error: Invalid address
│ 
│   on <import-address> line 1:
│    1: synapse_workspace_pe.azurerm_private_endpoint.syn_ws_pe_dev
│ 
│ Resource instance key must be given in square brackets

I referred to some stackoverflow posts, syntax is same. can some one tell me how to fix this ?


Solution

  • When importing resources from a declared module, then the namespace must be prefixed with the string literal module:

    terraform -chdir=Terraform import module.synapse_workspace_pe.azurerm_private_endpoint.syn_ws_pe_dev "/subscriptions/xxxx-xxxx-xxx--xx/resourceGroups/hub/providers/Microsoft.Network/privateEndpoints/pe-cb-ab-dev-we-dev"