I have my azure cloud setup manually. It almost has 5 subnets. Now in order to make it IAAS, I am writing a Terraform code for it. I know, I can import resource by using the command "terraform import azurerm_subnet.mysybnet ". This only imports one subnet. How can I import multiple subnets? For example, if I have subnets with names "vm-subnet", "aks-subnet", "acr-subnet", "nsg-subnet" and "firewall-subnet". How can I import all these subnets in one shot?
My current code is
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.0.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "myrg" {
name = "myRG"
location = "WEST US 2"
}
resource "azurerm_virtual_network" "myvnet" {
name = "myvnet"
resource_group_name = azurerm_resource_group.myrg.name
location = azurerm_resource_group.myrg.location
address_space = ["10.0.0.0/16"]
}
#Create subnets within the resource group
resource "azurerm_subnet" "mysubnet" {
name = "acr-subnet"
address_prefixes = ["10.0.0.0/24"]
resource_group_name = azurerm_resource_group.myrg.name
virtual_network_name = azurerm_virtual_network.myvnet.name
}




Depending on the version of terraform you are using, you can now use
importblocks withfor_each, which works on the terraform versions >1.7.x. For example: