Conditional null resource

Hi Team,

I would like someone to help me with the below use case.

I have a null resource created which will run some bash script on a remote server. If the bash script failed it should trigger another script which will revert changes made by the previous script.

I have tried writing terraform config file like this

resource “null_resource” “efm” {
triggers = {
the_trigger = “${var.always_switch}”
}

connection {
host = “{aws_instance.myfirstec2instance.public_ip}" private_key = "{file(var.pem_file_path)}”
user = “${var.ssh_user}”
}

provisioner “local-exec” {
# Bootstrap script called with private_ip of each node in the clutser
command = “/bin/bash {path.module}/utilities/scripts/setup.sh '{local.ssh_ip_list}’ '{local.config_ip_list}' {var.pemserverip} {var.ssh_user} {var.pem_file_path} {var.region_name} {aws_instance.myfirstec2instance.private_ip} ${aws_instance.myfirstec2instance.public_ip}”

on_failure = "fail"

}

provisioner “local-exec” {
# Bootstrap script called with private_ip of each node in the clutser

command = "var.always_switch == false ? /bin/bash -xxx ${path.module}/utilities/scripts/revert.sh  '${local.ssh_ip_list}' '${local.config_ip_list}'  ${var.pemserverip} ${var.ssh_user} ${var.pem_file_path} ${var.region_name} ${aws_instance.myfirstec2instance.private_ip} ${aws_instance.myfirstec2instance.public_ip} : echo wrongstpes"

}

}

Can someone help me to achieve the above use case?

Terraform version: 0.12.9