# Conditional null resource

**URL:** <https://discuss.hashicorp.com/t/conditional-null-resource/3988>\
**Category:** Terraform\
**Created:** [November 18, 2019, 12:25pm UTC](https://discuss.hashicorp.com/t/conditional-null-resource/3988 "2019-11-18T12:25:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![manishingole-coder](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/manishingole-coder/32/3183_2.png) [@manishingole-coder](https://discuss.hashicorp.com/u/manishingole-coder)\
**Post date:** [November 18, 2019, 12:25pm UTC](https://discuss.hashicorp.com/t/conditional-null-resource/3988/1 "2019-11-18T12:25:34Z")

</div>

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
