pkaramol
pkaramol

Reputation: 19322

Provide dependency among modules in Terraform

I am using to Terraform modules in a main.tf file as follows:

module "jenkins" {
  install_jenkins = "${var.install_jenkins}"
  jenkins_plugins_list = "${var.jenkins_plugins_list}"
}

module "kube" {
  source        = "../../../../modules-terraform/kube_internal"
  cluster_count = "${var.gke_cluster_create}"

}

I want the jenkins module to execute after the kube module.

Is there a way to do so in Terraform 0.11.14 (or even a workaround)?

I couldn't find anything relevant in the documentation.

Upvotes: 0

Views: 44

Answers (1)

Blokje5
Blokje5

Reputation: 4993

The hacky workaround available in 0.11.14 is to have the jenkins module create a resource based on output of the kube module, and have the other resources depend on that resource, e.g.

variable "cluster_id" {
  descripion = "passed by kube module to create dependency on kube module"
}

resource "null_resource" "cluster" {
  provisioner "local-exec" {
    # Create dependency on kubernetes cluster by calling variable
    command = "echo ${var.cluster_id}"
  }
}

resource "some_other_resource" "other" {
  depends_on = ["null_resource.cluster"]
}

Upvotes: 1

Related Questions