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
41.42k stars 9.36k forks source link

`ReferenceTransformer` hangs in plan when module has `depends_on` #35154

Closed ryancragun closed 2 weeks ago

ryancragun commented 2 weeks ago

Terraform Version

Terraform v1.8.3
on darwin_amd64
+ provider registry.terraform.io/hashicorp-forge/enos v0.5.2
+ provider registry.terraform.io/hashicorp/aws v5.49.0
+ provider registry.terraform.io/hashicorp/random v3.6.1

Terraform Configuration Files

A commit containing necessary files for reproduction: https://github.com/hashicorp/vault-enterprise/commit/1f634aea1611faedcf26a4070c4289b0c28f04f2

Debug Output

https://github.com/hashicorp/vault-enterprise/blob/1f634aea1611faedcf26a4070c4289b0c28f04f2/enos/trace.txt

Expected Behavior

The module, with line 550 uncommented, should plan

Actual Behavior

While planning the ReferenceTransformer hangs forever.

2024-05-13T13:41:42.442-0600 [DEBUG] ReferenceTransformer: "module.create_primary_cluster_backend_targets.local.instance_type (expand)" references: [module.create_primary_cluster_backend_targets.local.instance_types (expand) module.create_primary_cluster_backend_targets.data.aws_ami.ami (expand)]
2024-05-13T13:41:42.442-0600 [DEBUG] ReferenceTransformer: "module.verify_secondary_cluster_is_unsealed_after_enabling_replication (close)" references: []

Steps to Reproduce

  1. Check out the reproduction branch
  2. cd enos
  3. Uncomment line 550 in scenario.tf
  4. terraform init
  5. terraform plan

Additional Context

We've found a situtation where a module that plans as expected with 1.7.5 gets stuck planning forever with 1.8.3.

In the enos directory you'll find scenario.tf, which is stripped down version of the module that is auto-generated.

I bisected to the module that was causing the infinite plan and then bisected to the depends_on reference in it that causes it:

module "add_additional_nodes_to_primary_cluster" {
  depends_on = [
    module.create_primary_backend_cluster,
    module.create_primary_cluster,
    module.create_primary_cluster_additional_targets,
    module.create_vpc,
    // Uncomment this depends_on and we get stuck building the graph forever
    // module.verify_replicated_data
  ]
  // ...
}

It appears that this explicit depends_on causes our issue. With it left out both 1.7.5 and 1.8.3 plan as expected.

References

No response

hend0012 commented 2 weeks ago

We are experiencing the exact same issue. version 1.8.0 is still working as expected, after that we run into the same issue