We tried to import the multiple resources of same resource type using the below commands to the state file. Though it says the resource is imported successfully to the state file, we can’t see the resource in the state file. And when we execute Terraform plan, it is still recognizing the resources as new creation.
There is insufficient information here to give a clear answer, as you haven’t included the relevant portions of Terraform source code that define the resources you are importing.
However I do spot one thing that looks odd:
This says you imported once to the resource address without any square-bracketed for_each key, and once with - that doesn’t seem right.
When we tried the terraform import with same resource type without square braces, below message is displayed.
│ Error: Resource already managed by Terraform │ │ Terraform is already managing a remote object for module.resource_group.azurerm_resource_group.resource_group. To import to this address you must first remove the │ existing object from the state. ╵
What will be the recommended approach for declaring the multiple resource groups in tfvars file and import the existing resources to the state file ?
Please also show the code that calls your modules/azure/resources/resource-group module.
Copy/pastes of text, with each block surrounded by ``` markers to make it a code block, are generally much better than image screenshots, as then it is possible to quote sections when responding.
The code that you have shown us here creates one and only one resource group.
Therefore you cannot import multiple resource groups into one Terraform state for use along with this code, because that is not what the code has been written to support.