How can I prevent terraform from destroying and recreating azure vm extensions? Life cycle code block isn’t working. Terraform persists on destroying the resources and fails when I have the locks enabled. Please can someone tell me where I am going wrong with this
This is my code
resource "azurerm_virtual_machine_extension" "dsc" {
for_each = var.dsc_agent_name
name = each.key
virtual_machine_id = each.value
publisher = "Microsoft.Powershell"
type = "DSC"
type_handler_version = "2.0"
auto_upgrade_minor_version = "true"
tags = local.tags
lifecycle {
prevent_destroy = true
}
settings = <<SETTINGS
{
"ModulesUrl":"",
"SasToken":"",
"WmfVersion": "latest",
"Privacy": {
"DataCollection": ""
},
"ConfigurationFunction":""
}
SETTINGS
}
3
Answers
Managed to resolve this - I basically used ignore changes on all the properties Massive thanks to @MarkoE and AC81
Try removing the lifecycle block and then run ‘terraform plan’ – it should then show you which configuration item is causing it to be destroyed / re-created
You can try to put an ignore section in:
That way it will ignore what has been set on the resource in Azure with what is being declared (if anything for this section) in TF