Importing Azure resources to terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Install Terraform on mac | |
brew install hashicorp/tap/terraform | |
brew install terraform | |
2. Install the azure-cli | |
brew install azure-cli | |
3. Install terraformer tool | |
To import the existing resources from (AWS, Google cloud,AZURE) | |
https://github.com/GoogleCloudPlatform/terraformer | |
brew install terraformer | |
4. Authenticate with azure | |
az login | |
[ | |
{ | |
"cloudName": "AzureCloud", | |
"homeTenantId": "58fb75e6-9db3-4492-b319-a095a08786ce", | |
"id": "bc8ba97c-c476-4996-9d49-c92ccfe258f2", | |
"isDefault": true, | |
"managedByTenants": [], | |
"name": "Free Trial", | |
"state": "Enabled", | |
"tenantId": "58fb75e6-9db3-4492-b319-a095a08786ce", | |
"user": { | |
"name": "kiranchavala@gmail.com", | |
"type": "user" | |
} | |
} | |
] | |
5. Create a provider.tf file with the following content | |
mkdir -p test | |
cd test | |
vi provider.tf | |
provider "azurerm" { | |
features {} | |
} | |
terraform init | |
export ARM_SUBSCRIPTION_ID=bc8ba97c-c476-4996-9d49-c92ccfe258f2 | |
6. To import all the existing resources from your Azure account | |
Here "test_gourp" is the resource group in ur Azure account | |
terraformer import azure -R test_group -r "*" | |
specific resource | |
terraformer import azure -R test_group -r virtual_machine | |
7. This will generate Terraform files for the existing resources (instance) | |
├── generated | |
│ └── azurerm | |
│ └── virtual_machine | |
│ ├── linux_virtual_machine.tf | |
│ ├── outputs.tf | |
│ ├── provider.tf | |
│ └── terraform.tfstate | |
└── provider.tf | |
8. Now we can control the exisitng resources | |
cd generated/azurerm/virtual_machine/ | |
terraform state replace-provider -auto-approve "registry.terraform.io/-/azurerm" "hashicorp/azurerm" | |
terraform init | |
terraform refresh | |
9. To change the setting of a resource after editing the respective resource tf file | |
terraform plan | |
terraform apply | |
ref | |
https://brew.sh/ | |
https://docs.brew.sh/Homebrew-on-Linux | |
https://github.com/GoogleCloudPlatform/terraformer | |
https://learn.hashicorp.com/tutorials/terraform/state-import?in=terraform/state&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS#limitations-and-other-considerations | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment