0

Summary: depends_on of Terraform works fine, BUT when I have an incremental update with new resources going in-between then it causes the new resources to run in parallel (which will NOT if I run it from scratch)

Example Terraform (Run 1) Works fine

resource "null_resource" "one" {
  provisioner "local-exec" {
    command = "NAME='one'; echo $NAME; sleep 1; echo $NAME; sleep 1; echo $NAME; sleep 1;"
  }
}

resource "null_resource" "two" {
  depends_on = [null_resource.one]
  provisioner "local-exec" {
    command = "NAME='one'; echo $NAME; sleep 1; echo $NAME; sleep 1; echo $NAME; sleep 1;"
  }
}

Example Terraform (Run 2)

Problem: before_one and after_two are getting started in parallel :(

Expected Flow: complete before_one and then start after_two

resource "null_resource" "before_one" {
  provisioner "local-exec" {
    command = "NAME='before_one'; echo $NAME; sleep 1; echo $NAME; sleep 1; echo $NAME; sleep 1;"
  }
}

resource "null_resource" "one" {
  depends_on = [null_resource.before_one]
  provisioner "local-exec" {
    command = "NAME='one'; echo $NAME; sleep 1; echo $NAME; sleep 1; echo $NAME; sleep 1;"
  }
}

resource "null_resource" "two" {
  depends_on = [null_resource.one]
  provisioner "local-exec" {
    command = "NAME='one'; echo $NAME; sleep 1; echo $NAME; sleep 1; echo $NAME; sleep 1;"
  }
}

resource "null_resource" "after_two" {
  depends_on = [null_resource.two]
  provisioner "local-exec" {
    command = "NAME='after_two'; echo $NAME; sleep 1; echo $NAME; sleep 1; echo $NAME; sleep 1;"
  }
}

Output

null_resource.before_one: Creating...
null_resource.before_one: Provisioning with 'local-exec'...
null_resource.after_two: Creating...
null_resource.after_two: Provisioning with 'local-exec'...
null_resource.after_two (local-exec): Executing: ["/bin/sh" "-c" "NAME='after_two'; echo $NAME; sleep 1; echo $NAME; sleep 1; echo $NAME; sleep 1;"]
null_resource.after_two (local-exec): after_two
null_resource.before_one (local-exec): Executing: ["/bin/sh" "-c" "NAME='before_one'; echo $NAME; sleep 1; echo $NAME; sleep 1; echo $NAME; sleep 1;"]
null_resource.before_one (local-exec): before_one
null_resource.after_two (local-exec): after_two
null_resource.before_one (local-exec): before_one
null_resource.after_two (local-exec): after_two
null_resource.before_one (local-exec): before_one
null_resource.after_two: Creation complete after 3s [id=3913800421589569159]
null_resource.before_one: Creation complete after 3s [id=9135396498225807226]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.