How input variables force instance replacement?

So, we have a Terraform module that builds an AWS instance. We pass in the AMI. If we change the AMI then it forces the resource to be replaced.

We want to add an input variable of our own that will work in a similar way. The tricky part is that we’d want to use the varaible in a provision rather than the resource definition itself. That said, if necessary, we could add it as a tag.

Is there any way to mark a resource variable as destructive? Eg:

variable "ami" {
    type = string
}

variable "custom_var" {
    type = string
}

resource "aws_instance" "ec2_instance" {
    ami  = var.ami

    provisioner "local-exec" {
        command = "ansible-playbook -i hosts playbook.yml -e "custom_var=${var.custom_var}"
    }
}

anyone?

xxxxxxxxxxxxx