0
votes

I want to create subnet in my existing vnet which is present in azure. I found a command to import resource terraform import . but how do i use the resource details example: vnet resource group in the code.

resource "azurerm_virtual_network" "vnet" {
  name                           = var.vnet_name
  address_space                  = var.vnet_address_space
  resource_group_name            = var.subscriptionrg_name
  location  }

I ran the command and found that the dns server which we earlier present are now deleted. Does that means i have to define everything in my code and import. Or is there any other way to use existing resources.

1
terraform import <terraform resource name>.<resource label> <resource id>mikeknows

1 Answers

2
votes

First just define an empty block like this:

resource "azurerm_virtual_network" "vnet" {
}

Then, run terraform import command to import existing resource into your Terraform state. Afterward, execute the terraform show to print out the TF state into the screen. Finally, you can copy the content of printed "azurerm_virtual_network" "vnet" block into the actual block in .tf file.