Although I created empty resource group in azure cloud, it is not allowing to import resoure from azure to terraform

sns 9,226 Reputation points
2022-09-22T15:28:19.407+00:00

Although I created empty resource group azure cloud is not allowing to import resoure from azure to terraform
Please find the below screenshot. Please help.
243936-image.png

Azure Cloud Services
Azure Cloud Services
An Azure platform as a service offer that is used to deploy web and cloud applications.
632 questions
0 comments No comments
{count} votes

Accepted answer
  1. JimmySalian-2011 41,916 Reputation points
    2022-09-22T15:55:42.557+00:00

    Hi,

    It seems there is a mismatch between the RG and command, can you check the complete path and verify. Worth create a plan and importing state file I will suggest, check this link for commands if you need - how-to-import-an-existing-azure-resource-in-terraform-6d585f93ea02

    ==
    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


2 additional answers

Sort by: Most helpful
  1. Jordan Lee 81 Reputation points
    2023-01-06T17:57:54.68+00:00

    Based on what I think you're actually trying to achieve, importing the configuration into your vscode experience. That is not what terraform import does. It imports an existing resource into your state file, you have to configure everything in terraform as you normally would giving it the attributes you would expect.

    resource "azurerm_resource_group" "rgp" {
    name = "rg-example"
    location = "uksouth"
    }

    Once you run a terraform apply, it will say a resource exists already with the resource id, at this point you can import into terraform.

    terraform import azurerm_resource_group.rgp /subscriptions/xxx~

    If you don't want to configure the attributes in vscode, you should look at a tool that can import existing deployments, I believe terraform cloud has this functionality or even an open source tool like aztfy.

    1 person found this answer helpful.
    0 comments No comments

  2. Luke Murray 10,526 Reputation points MVP
    2022-09-22T20:33:42.983+00:00

    You need to either, create the Resource Group using Terraform (delete the one in the Azure Portal) - or import it into Terraform: https://gmusumeci.medium.com/how-to-import-an-existing-azure-resource-in-terraform-6d585f93ea02