terraform import existing resources - not quite with 1.5.x with generated output
Terraform import can be quite interesting thing to do. So let's start with us trying to import a storage account. So we will start off using hcl import statement to import this.
As you can see here, we are trying to import to "azurerm_storage_account" "imported_storage" . and we just need to specify the azure resource id.
And when we run "terraform apply". we can see the output here.
And the state already imported. And of course we can change it to say GRS. So running "terraform plan" after code change will give us this results.
Then terraform will import and change the state file for you. For example, lets change our storage account replication type to GRS. Then we import the state file. As you can see, terraform will
What if you run terraform refresh with a drift - for example in the code we have replication type as LRS, then someone change that to GRS?
Running terraform refresh updates the drift between Azure resources to the state file. When we run terraform plan/apply, it uses the code as a source of truth.
How does this compare to cli terraform import?
The achieve the same purpose. terraform cli import does have its use-case but tedious to do if you have many different environment with many different state files
You can replicate the import block with this command here:-
terraform import azurerm_storage_account.imported_storage2 /subscriptions/your-subscription--id/resourceGroups/mytest-kv-rg/providers/Microsoft.Storage/storageAccounts/saforimort
And you would have something like this.
Comments