Reputation: 115
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.
Upvotes: 2
Views: 3520
Reputation: 1271
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.
Upvotes: 3