Saturday 28 August 2021

Importing Existing Azure Vnet into Terraform

Previously i have posted a way to import a resource group into terraform. so today it will a continue process to that where it time to import virtual network into terraform . 

This will be a bit challenging as it got some dependencies to another resources like Subnet and NSG. 

So let begin, so always start with creating a empty of your vnet but for this scenario i will suggest to import NSG first as it was bind with subnet. 


resource "azurerm_network_security_group" "nsg-app" {
 
}

Then run the terraform import for this nsg 

 Terraform import azurerm_network_security_group.nsg-app xx/xxx/xxx/NSG-APP

After that, use terraform show to check what are the information needed for NSG block to match with deployment. 


for my case, i just add in the name and few importance information without all the additional rule created in the NSG. 


this step need to be repeat to all   NSG created before touching on Virtual Network and can be skip if no NSG being created or attach to subnet. 

continuing from that, you may start importing the virtual network with the same step and continue with the subnet . i was planning to use one resource block to address vnet and subnet like here 


but seem like create separate block for each subnet will be easier as less information needed for the subnet block. 




repeat for all the subnet available and check if there more changes needed with terraform plan . For me this is enough to import all. 

Thanks for reading and stay safe. 

No comments:

Kubecost on AKS Part 02