'Azure terraform import error, unable to import resource

Module Structure

This is my module structure

I am calling a module of resource group

However, when I am trying to import this resource I am getting below error, what could be the reason?

Module:

resource "azurerm_resource_group" "resource_group" {
  name     = var.resource_group_name
  location = var.resource_group_location
  tags     = var.tags
}

Resource:

  module "importtestrs" {
  source                  = "../modules/resource_group"
  resource_group_name     = var.resource_group_name
  resource_group_location = var.location
  tags                    = var.tags
}

Terraform init and plan worked fine!

2022-03-01T09:43:35.4574585Z ##[command]"terraform" import -var-file="variables-dev.tfvars" module.importtestrs.azurerm_resource_group.resource_group /subscriptions/XXXXXXXXXXXXXXXXXXXXX/resourceGroups/DevOps-Agent-Dev -input=false -no-color 2022-03-01T09:43:35.5479792Z The import command expects two arguments. 2022-03-01T09:43:35.5481231Z Usage: terraform [global options] import [options] ADDR ID



Solution 1:[1]

Have you tried simply by

terraform import resource_group.resourcename id

in your case it will be

terraform import azurerm_resource_group. resource_group /subscriptions/XXXXXXXXXXXXXXXXXXXXX/resourceGroups/DevOps-Agent-Dev

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SoH