# Trigger module based on input

**URL:** <https://discuss.hashicorp.com/t/trigger-module-based-on-input/6383>\
**Category:** Terraform\
**Created:** [February 28, 2020, 10:29am UTC](https://discuss.hashicorp.com/t/trigger-module-based-on-input/6383 "2020-02-28T10:29:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhineshbabuelango](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/dhineshbabuelango/32/2223_2.png) [@dhineshbabuelango](https://discuss.hashicorp.com/u/dhineshbabuelango)\
**Post date:** [February 28, 2020, 10:29am UTC](https://discuss.hashicorp.com/t/trigger-module-based-on-input/6383/1 "2020-02-28T10:29:59Z")

</div>

I need to trigger a module only if a variable is present, is that achievable in terraform

so the module should run only if the var.lbname has some value.

module “record\_set\_creation” {  
source = “…/r53-private-hosted-zone/record-set”  
enable = var.create\_subdomain  
private\_zone\_id = var.private\_zone\_id  
record\_set\_name = var.record\_set\_name  
elb\_hostname = var.lbname

---

<div class="post-metadata">

**Author:** ![gtirloni](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/gtirloni/32/1363_2.png) [@gtirloni](https://discuss.hashicorp.com/u/gtirloni)\
**Post date:** [February 28, 2020, 1:22pm UTC](https://discuss.hashicorp.com/t/trigger-module-based-on-input/6383/2 "2020-02-28T13:22:12Z")

</div>

If elb\_hostname doesn’t have a default value, the module should fail, right? Do you want to silently skip it? I don’t think it’s possible to put a giant IF around that module statement. Maybe if you play with `count`?

If you’re using Terraform \>= 0.12.20, you can use the experimental validation rules to ensure that elb\_hostname is properly specified. But I’m afraid that’s not what you’re looking for here.

> **[Input Variables - Configuration Language - Terraform by HashiCorp](https://www.terraform.io/docs/configuration/variables.html#custom-validation-rules)**
>
> Input variables are parameters for Terraform modules. This page covers configuration syntax for variables.

---

<div class="post-metadata">

**Author:** ![dhineshbabuelango](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/dhineshbabuelango/32/2223_2.png) [@dhineshbabuelango](https://discuss.hashicorp.com/u/dhineshbabuelango)\
**Post date:** [February 28, 2020, 1:53pm UTC](https://discuss.hashicorp.com/t/trigger-module-based-on-input/6383/3 "2020-02-28T13:53:10Z")

</div>

Thanks @gtirloni for your response.  
I was looking for terraform to skip that module if the elb doesnot have a value.

---

<div class="post-metadata">

**Author:** ![kpfleming](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/kpfleming/32/3376_2.png) [@kpfleming](https://discuss.hashicorp.com/u/kpfleming)\
**Post date:** [February 28, 2020, 7:49pm UTC](https://discuss.hashicorp.com/t/trigger-module-based-on-input/6383/4 "2020-02-28T19:49:51Z")

</div>

Unfortunately `module` blocks don’t support meta parameters like `count` and `for_each`, so you can’t use the usual tricks to suppress a module completely.

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [March 3, 2020, 10:55pm UTC](https://discuss.hashicorp.com/t/trigger-module-based-on-input/6383/5 "2020-03-03T22:55:10Z")

</div>

Hi @dhineshbabuelango,

It looks like the module you’re using there already has a mechanism to “enable” it, in which case perhaps you can just extend the value of that argument:

```auto
module “record_set_creation” {
  source = “…/r53-private-hosted-zone/record-set”

  enable = var.create_subdomain && var.lbname != ""
  private_zone_id = var.private_zone_id
  record_set_name = var.record_set_name
  elb_hostname = var.lbname
}

```

I’m assuming here that inside the module it’s using conditional expressions to produce zero of all of the resources when `var.enable` is false. If that’s not already true, then making it true is the best answer to this question with the Terraform language features as they exist today.
