We have a case which Terraform seems acting inconsistently when it destroyed the deposed resource (create_before_destroy = true), we expected that the deposed one will be destroyed right after the new resource is created and provisioned completely, before other resources are created, it has been always like that when we used TF 0.11.14, just now we upgraded to 0.12.16 and see that the behaviors are inconsistent, sometimes the deposed one is destroyed right away (as expected), and sometimes it’s destroyed only at the end of the apply, which cause confusions for some of our null_resource as the provisioner’s script will run on wrong instance (the old one instead of the new one).
Is there any way to control or to be sure when the deposed resource will be destroyed?
Example config
provider "aws" {
region = "ap-southeast-1"
}
resource "aws_instance" "facade" {
ami = "ami-05aeed009111ced5a" #"ami-035b66f30d1b28072" # "ami-05aeed009111ced5a"
instance_type = "t3.small"
key_name = "ondemand_aws_int"
vpc_security_group_ids = [
"sg-ceadd8a9"
]
subnet_id = "subnet-04c29a60"
associate_public_ip_address = true
root_block_device {
volume_type = "gp2"
volume_size = 20
}
tags = {
Name = "khiem-test-facade"
Source = "Terraform"
ActiveResource = "true"
}
lifecycle {
create_before_destroy = true
}
}
resource "null_resource" "configure_platform" {
triggers = {
facade_id = "${aws_instance.facade.id}"
}
provisioner "local-exec" {
command = <<EOT
echo Hello
sleep 60
echo Goodbye
EOT
}
}