0
votes

I have created a Terraform module (that installs jenkins, but that is out of this questions' scope)

I want to be able to conditionally install it.

I have tried the count approach:

module "jenkins" {
  count = "${var.install_jenkins}"
  source        = "../../../../modules-terraform/jenkins"
  project_id         = "${google_project.service.project_id}"
  zone = "${var.zone}"
  org_name = "${var.org_name}"
}

but it is throwing the error below:

Error: module "jenkins": "count" is not a valid argument

Is there a way to conditionally install a Terraform module?

Working with Terraform 0.11.14

1
There's a few related questions on this but the answer is no. You could use something like jenkins_count or install_jenkins as a variable and pass that into every resource in the module to conditionally create those but that will be a mess and probably cause you other issues around non lazily evaluated ternary statements in pre 0.12 Terraform. The best bet is to compose things instead so you only include the module definition in places you want to create a Jenkins.ydaetskcoR

1 Answers