Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy time depends_on missing order on destroying #52

Closed
VickyWinner opened this issue Dec 4, 2020 · 2 comments
Closed

Destroy time depends_on missing order on destroying #52

VickyWinner opened this issue Dec 4, 2020 · 2 comments

Comments

@VickyWinner
Copy link

VickyWinner commented Dec 4, 2020

Hi there,
I have two null_resources create1 and create2 and two destroy time null_resources delete1 and delete2. I want delete1 and delete2 to run when create1 and create2 are deleted when I run terraform destroy. am I wrong in the code or is it by design or bug?

when I run terraform apply I see that create1 ran before create2 which is perfect.

#> terraform apply -auto-approve                                                                                                                  null_resource.create1: Creating...
null_resource.create1: Provisioning with 'local-exec'...
null_resource.create1 (local-exec): Executing: ["pwsh" "-Command" "Write-Output 'Create 1'"]
null_resource.create1 (local-exec): Create 1
null_resource.create1: Creation complete after 5s [id=3984634756973961301]
null_resource.delete1: Creating...
null_resource.create2: Creating...
null_resource.delete1: Creation complete after 0s [id=2672729497423318944]
null_resource.create2: Provisioning with 'local-exec'...
null_resource.create2 (local-exec): Executing: ["pwsh" "-Command" "Write-Output 'Create 2'"]
null_resource.create2 (local-exec): Create 2
null_resource.create2: Creation complete after 4s [id=5236526839634656700]
null_resource.delete2: Creating...
null_resource.delete2: Creation complete after 0s [id=5226889765845627431]

I don't see any timestamp to say what ran first but based on the output and its order, I am thinking this is what the order being followed.

#> terraform destroy -auto-approve                                                                                                                null_resource.create1: Refreshing state... [id=3984634756973961301]
null_resource.create2: Refreshing state... [id=5236526839634656700]
null_resource.delete1: Refreshing state... [id=2672729497423318944]
null_resource.delete2: Refreshing state... [id=5226889765845627431]
null_resource.delete1: Destroying... [id=2672729497423318944]
null_resource.delete2: Destroying... [id=5226889765845627431]
null_resource.delete1: Provisioning with 'local-exec'...
null_resource.delete2: Provisioning with 'local-exec'...
null_resource.delete2 (local-exec): Executing: ["pwsh" "-Command" "Write-Output 'Delete 2'"]
null_resource.delete1 (local-exec): Executing: ["pwsh" "-Command" "Write-Output 'delete 1'"]
null_resource.delete1 (local-exec): delete 1
null_resource.delete2 (local-exec): Delete 2
null_resource.delete1: Destruction complete after 5s
null_resource.delete2: Destruction complete after 5s
null_resource.create2: Destroying... [id=5236526839634656700]
null_resource.create2: Destruction complete after 0s
null_resource.create1: Destroying... [id=3984634756973961301]
null_resource.create1: Destruction complete after 0s

Terraform Version

#> terraform -v
Terraform v0.13.1

  • provider registry.terraform.io/hashicorp/null v3.0.0

Affected Resource(s)

null_resource

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource null_resource create1 {
    provisioner local-exec {
    command = "Write-Output 'Create 1'"
    interpreter = ["pwsh", "-Command"]
  }
}

resource null_resource create2 {
    provisioner local-exec {
    command = "Write-Output 'Create 2'"
    interpreter = ["pwsh", "-Command"]
  }
  depends_on = [null_resource.create1]
}

resource null_resource delete1 {
    provisioner local-exec {
    when = destroy
    command = "Write-Output 'delete 1'"
    interpreter = ["pwsh", "-Command"]
  }
  depends_on = [null_resource.create1]
}

resource null_resource delete2 {
    provisioner local-exec {
    when = destroy
    command = "Write-Output 'Delete 2'"
    interpreter = ["pwsh", "-Command"]
  }
  depends_on = [null_resource.create2]
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

Terraform should run delete1 after destroying create1 and delete2 after destroying create2 respectively.

Actual Behavior

see output above

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

References

@bflad
Copy link
Contributor

bflad commented Mar 8, 2023

Hi @VickyWinner 👋 Thank you for raising this issue and apologies for the delayed response. We use this issue tracker for bug reports and feature requests, while the null provider itself does not tend to have too much traffic for its maintainers to regularly re-check through the issues.

If you haven't had this question answered already or it hasn't already been fixed with Terraform updates since this issue was created, it would be best to raise a topic in HashiCorp Discuss, where there is a large community of practitioners better equipped to answer them. The lifecycle block functionality is wholly implemented in Terraform core (outside of individual providers). If you believe there is a bug in that handling, it would be best to create an issue in the Terraform core issue tracker.

@bflad bflad closed this as completed Mar 8, 2023
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants