Saturday 21 August 2021

Import Azure Existing Resource Group to Terraform

 As part of using terraform to manage the architecture, there a time when the environment has existing resources or the resource being deploy via portal instead of terraform 

So, in order to keep all the control in terraform, the resource need to be imported to terraform so it can be manage from there. 

In this case , Azure Resource Group will be imported to terraform, as we all aware, all resource in azure need to be located in resource 


1.Start with create an empty block the resource ;

resource "azurerm_resource_group" "prod-rg" {
    
}

"prod-rg" is just a block name, can be name with any name but i prefer to tally with the resource group name created on Azure. 

2. Get the RG resource id from azure portal 


3. Import command need to parameter which is resource and resource id 

For this case - terraform import azurerm_resource_group.prod-rg /xxx/xxx/resourcegroup/PROD-RG

4. After import is complete, some info need to be added into resource group block. 

4.1 you may run terraform show to see what need to be added 

  

 Not all need to be added 

5. Edit the RG block as follow 

resource "azurerm_resource_group" "prod-rg" {
    name = "PROD-RG"
    location = "southeastasia"
}

6. run terraform plan to check if any more information need to be add, but as for now, that two information is enough


That all i have for now, feel free to leave a feedback in the comment, happy terraforming and stay safe 

No comments:

Kubecost on AKS Part 02