hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.35k stars 9.49k forks source link

panic: no expansion has been registered for module.log_indexes on v1.8.0 #35509

Closed robotparty closed 1 month ago

robotparty commented 1 month ago

Terraform Version

❯ terraform --version
Terraform v1.8.0
on linux_amd64
+ provider registry.terraform.io/datadog/datadog v3.38.0
+ provider registry.terraform.io/hashicorp/aws v5.44.0

Terraform Configuration Files

Using datadog terraform provider to build indexes. Had just added outputs to each layer of modules to get debugging info output.

Module call log_indexes is looping thru a datastructure and calling module logs_index to build each resource:

  for_each = var.indexes
  source   = "../logs_index"
  env      = var.env
  name     = each.key
  index    = each.value
}
...
resource "datadog_logs_index" "this" {
  name        = var.env == "noenv" ? "${var.name}" : "${var.env}-${var.name}"
  daily_limit = var.index.daily_limit
  daily_limit_reset {
    reset_time       = var.index.daily_limit_reset_time
    reset_utc_offset = var.index.daily_limit_reset_utc_offset
  }
  daily_limit_warning_threshold_percentage = var.index.daily_limit_warning_threshold_percentage
  retention_days                           = var.index.retention_days
  filter {
    query = var.index.query
  }
}

output "index_id" {
  value = datadog_logs_index.this.id
}

Debug Output

❯ tfp

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
Please report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version, the stack trace
shown below, and any additional information which may help replicate the issue.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

panic: no expansion has been registered for module.log_indexes
goroutine 960 [running]:
runtime/debug.Stack()
        /opt/hostedtoolcache/go/1.22.1/x64/src/runtime/debug/stack.go:24 +0x5e
github.com/hashicorp/terraform/internal/logging.PanicHandler()
        /home/runner/work/terraform/terraform/internal/logging/panic.go:84 +0x18b
panic({0x2e00120?, 0xc00361e450?})
        /opt/hostedtoolcache/go/1.22.1/x64/src/runtime/panic.go:770 +0x132
github.com/hashicorp/terraform/internal/instances.(*Expander).ExpandAbsModuleCall(0x2f3a180?, {{0x0, 0x0, 0x0}, {{}, {0xc00071bd50, 0xb}}})
        /home/runner/work/terraform/terraform/internal/instances/expander.go:171 +0x265
github.com/hashicorp/terraform/internal/terraform.(*evaluationStateData).GetModule(0xc0028255f0, {{}, {0xc00071bd50?, 0x0?}}, {{0xc000808d68, 0x11}, {0x2f, 0xb, 0x5f1}, {0x2f, ...}})
        /home/runner/work/terraform/terraform/internal/terraform/evaluate.go:398 +0x788
github.com/hashicorp/terraform/internal/lang.(*Scope).evalContext(0xc002825680, {0xc0012949c0, 0x1, 0x1}, {0x0, 0x0})
        /home/runner/work/terraform/terraform/internal/lang/eval.go:381 +0x1112
github.com/hashicorp/terraform/internal/lang.(*Scope).EvalContext(...)
        /home/runner/work/terraform/terraform/internal/lang/eval.go:245
github.com/hashicorp/terraform/internal/lang.(*Scope).EvalExpr(0xc002825680, {0x3d75900, 0xc0009b65a0}, {{0x3d75ce0?, 0x5891580?}})
        /home/runner/work/terraform/terraform/internal/lang/eval.go:170 +0x9e
github.com/hashicorp/terraform/internal/terraform.(*BuiltinEvalContext).EvaluateExpr(0x0?, {0x3d75900, 0xc0009b65a0}, {{0x3d75ce0?, 0x5891580?}}, {0x0?, 0x0?})
        /home/runner/work/terraform/terraform/internal/terraform/eval_context_builtin.go:322 +0xab
github.com/hashicorp/terraform/internal/terraform.(*NodeApplyableOutput).Execute(0xc0043f0f00, {0x3d984a8, 0xc002b2c3c0}, 0x70?)
        /home/runner/work/terraform/terraform/internal/terraform/node_output.go:376 +0x6cc
github.com/hashicorp/terraform/internal/terraform.(*ContextGraphWalker).Execute(0xc00422ea00, {0x3d984a8, 0xc002b2c3c0}, {0x72122b33c028, 0xc0043f0f00})
        /home/runner/work/terraform/terraform/internal/terraform/graph_walk_context.go:153 +0xbb
github.com/hashicorp/terraform/internal/terraform.(*Graph).walk.func1({0x32a43c0, 0xc0043f0f00})
        /home/runner/work/terraform/terraform/internal/terraform/graph.go:112 +0x62a
github.com/hashicorp/terraform/internal/dag.(*Walker).walkVertex(0xc0043f0fc0, {0x32a43c0, 0xc0043f0f00}, 0xc0043829c0)
        /home/runner/work/terraform/terraform/internal/dag/walk.go:384 +0x2d7
created by github.com/hashicorp/terraform/internal/dag.(*Walker).Update in goroutine 1465
        /home/runner/work/terraform/terraform/internal/dag/walk.go:307 +0xff3

Expected Behavior

Terraform plan should have run...

Actual Behavior

Crash above

Steps to Reproduce

  1. terraform plan

Additional Context

I was able to stop the crash by removing the main module index_ids output: `` module "log_indexes" { for_each = local.log_indexes source = "./modules/log_indexes" env = each.key indexes = each.value }

output "index_ids" {

value = module.log_indexes.index_ids

}



I see now that the problem was likely caused by having 2 module calls named `log_indexes` with outputs from the child module mentioned in the output of the caller/parent.

### References

_No response_
jbardin commented 1 month ago

Duplicate of #34976

github-actions[bot] commented 3 weeks ago

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.