Reputation: 745
Due to some technical issues during a migration we had to do some changes to our Azure resource directly into the portal. In order to get our Terraform State files again up to date we plan to import some resources.
But, when doing a trial on a POC environment with just 1 recource group we already run into trouble.
I'm having these instructions executed.
TerraForm import -var-file="T:\_config\%SIB_Subscription%\%Core%\terraform.tfvars" "module.provision_resourcegroup.module.rg_create[\"edw-10\"].azurerm_resource_group.rg" /subscriptions/8dc72845-b367-4dcc-98f9-d9a4a933defc/resourceGroups/rg-poc-edw-010
TerraForm plan -var-file="T:\_config\%SIB_Subscription%\%Core%\terraform.tfvars" -out "T:\_CommandLine\_Logs\planfile.log"
environment variables are set correctly as the state files is created on the blob storage. But when looking into the output on screen I see this.
# module.provision_resourcegroup.module.rg_create["edw-1"].azurerm_resource_group.rg will be destroyed
- - resource "azurerm_resource_group" "rg" {
- id = "/subscriptions/oooooo-zzzz-xxxx-yyyy-zzzz/resourceGroups/rg-poc-edw-001" -> null
- location = "westeurope" -> null
- name = "rg-poc-edw-001" -> null
- tags = {
- "APMId" = "00000"
- "CMDBApplicationId" = "tbd"
- "CMDBApplicationURL" = "tbd"
- "Capability" = "DAS - Data Analytics Services"
- "Das_Desc" = "DAS Common Purpose"
- "Solution" = "EDW"
} -> null
- timeouts {}
}
# module.provision_resourcegroup[0].module.rg_create["edw-1"].azurerm_resource_group.rg will be created
+ resource "azurerm_resource_group" "rg" {
+ id = (known after apply)
+ location = "westeurope"
+ name = "rg-poc-edw-001"
+ tags = {
+ "APMId" = "00000"
+ "CMDBApplicationId" = "tbd"
+ "CMDBApplicationURL" = "tbd"
+ "Capability" = "DAS - Data Analytics Services"
+ "Das_Desc" = "DAS Common Purpose"
+ "Solution" = "EDW"
}
}
So this can't be used as the Apply would delete the RG before creating the new one. Is there a way that I can see WHY TF wants to recreate ?
This is my code to create the module .
resource "azurerm_resource_group" "rg" {
name = "rg-${module.subscription.environment}-${local.rg_name_solution}-${var.rg_name_seqnr}"
location = module.location.azure
tags = {
"Das_Desc" = var.tag_Desc
"Capability" = var.tag_capability
"Solution" = var.tag_solution
"APMId" = var.tag_APMId
"CMDBApplicationURL" = var.tag_CMDBApplicationURL
"CMDBApplicationId" = var.tag_CMDBApplicationId
}
}
Upvotes: 1
Views: 662
Reputation: 28739
It appears that your outer module declaration now has a count
meta-argument, so you need to rename the resource path in your state according to the new namespace. You can rename resources in your state with terraform state mv <former name> <current name>
:
terraform state mv 'module.provision_resourcegroup.module.rg_create["edw-1"].azurerm_resource_group.rg' 'module.provision_resourcegroup[0].module.rg_create["edw-1"].azurerm_resource_group.rg'
Upvotes: 1