Ignore_changes - but only when changed outside of Terraform


Is it possible to configure so that changes made outside of Terraform wont be corrected in upcoming Terraform runs, but if a change is done within the Terraform configuration it will actually apply it?

Consider the following:

resource "azurerm_windows_virtual_machine_scale_set" "windows_scale_set" {
  lifecycle {
    ignore_changes = [

source_image_id = "source_image_id_1"

Then the VMSS gets created with source_image_id_1 and later, when changed outside of Terraform, the next Terraform run will not try to fix it (change it back to what’s inside of the configuration). However, I’d like for Terraform to change it if the value is not the same inside of the Terraform configuration anymore, for example if the attribute value of source_image_id was manually changed within the configuration to source_image_id_2.

In other words, if the attribute included in the ignore_changes lifecycle block gets changed manually, inside of the Terraform configuration, it will actually get updated accordingly. But if it stays the same it will never try to fix it back to that same value, in consecutive Terraform runs, when changes have done outside of Terraform.

Would this be possible? I don’t necessarily need to use the ignore_changes or lifecycle block for this, if there’s another way, I’m open for suggestions. :slight_smile:

Hi @aleqsss,

The ignore_changes feature effectively tells Terraform to treat the desired state for a particular argument as being whatever is in the prior state rather than what was evaluated in the configuration. At the point where ignore_changes is evaluated Terraform has already updated the prior state to match the real target system (“refreshing”) and so the information about differences between the remote system and the previous run state are not available.

With that said then, I don’t think there is any way to achieve what you’ve described. Terraform only compares desired state to prior state when deciding what changes to propose.

Thank you for the explaining answer, appreciated! :slightly_smiling_face:

Then I guess I have to handled this logic outside of Terraform. Thank you for clarifying this thus letting me know why, which is really important for me to be able to make informed design decisions.