# Executing a module according to a variable value

**URL:** <https://discuss.hashicorp.com/t/executing-a-module-according-to-a-variable-value/3727>\
**Category:** Terraform\
**Created:** [November 6, 2019, 9:38am UTC](https://discuss.hashicorp.com/t/executing-a-module-according-to-a-variable-value/3727 "2019-11-06T09:38:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkelnermishal](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/mkelnermishal/32/2978_2.png) [@mkelnermishal](https://discuss.hashicorp.com/u/mkelnermishal)\
**Post date:** [November 6, 2019, 9:38am UTC](https://discuss.hashicorp.com/t/executing-a-module-according-to-a-variable-value/3727/1 "2019-11-06T09:38:26Z")

</div>

Hey

I would like to execute a module only when a certain variable is set to specific value:  
pseudo-code  
if ok\_to\_exec == true  
exec module stuff

Please advise on how to do that, I found something that might be similar, but not exactly:  
in the module, add the following line:  
to\_exec\_count = "${var.ok\_to\_exec ? 0 : 1}  
default for ok\_to\_exec is “false”  
when set to true, all resources related to the module will be executed.  
Is that correct ?

thank you in advance,  
Michal
