-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Empty destroy fails on conditional modules #31838
Copy link
Copy link
Closed
Labels
bugconfirmeda Terraform Core team member has reproduced this issuea Terraform Core team member has reproduced this issue
Description
Terraform Version
Terraform v1.3.0
on darwin_amd64
+ provider registry.terraform.io/hashicorp/null v3.1.1Terraform Configuration Files
main.tf:
locals {
enable = true
value = local.enable ? module.example[0].thing : null
}
module "example" {
count = local.enable ? 1 : 0
source = "./example"
}The contents of .example/main.tf:
resource "null_resource" "thing" {
}
output "thing" {
value = null_resource.thing
}
Debug Output
https://gist.github.com/jta/4b9bd020354d470c6d1f006b7baf7341
Expected Behavior
Destroying where there is no state should be a no-op.
Actual Behavior
Terraform can apply and destroy the provided config correctly. However, issuing a destroy when the state is empty triggers an error:
Error: Invalid index
on main.tf line 3, in locals:
3: value = local.enable ? module.example[0].thing : null
├────────────────
│ module.example is empty tuple
The given key does not identify an element in this collection value: the collection has no elements.
Steps to Reproduce
terraform initterraform destroy
Additional Context
This is a regression introduced by v1.3.0.
References
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugconfirmeda Terraform Core team member has reproduced this issuea Terraform Core team member has reproduced this issue