Skip to content

transitive dependencies can be missed when there are no instances to apply #33370

@jbardin

Description

@jbardin

Terraform Version

Terraform v1

Terraform Configuration Files

resource "terraform_data" "one" {
}

resource "terraform_data" "two" {
  count = 0
  depends_on = [terraform_data.one]
}

resource "terraform_data" "three" {
  depends_on = [terraform_data.two]
}

Debug Output

  provider["terraform.io/builtin/terraform"] - *terraform.NodeApplyableProvider
  provider["terraform.io/builtin/terraform"] (close) - *terraform.graphNodeCloseProvider
    terraform_data.one - *terraform.NodeApplyableResourceInstance
    terraform_data.three - *terraform.NodeApplyableResourceInstance
  root - *terraform.nodeCloseModule
    provider["terraform.io/builtin/terraform"] (close) - *terraform.graphNodeCloseProvider
  terraform_data.one - *terraform.NodeApplyableResourceInstance
    terraform_data.one (expand) - *terraform.nodeExpandApplyableResource
  terraform_data.one (expand) - *terraform.nodeExpandApplyableResource
    provider["terraform.io/builtin/terraform"] - *terraform.NodeApplyableProvider
  terraform_data.three - *terraform.NodeApplyableResourceInstance
    terraform_data.three (expand) - *terraform.nodeExpandApplyableResource
    terraform_data.two (expand) - *terraform.nodeExpandApplyableResource
  terraform_data.three (expand) - *terraform.nodeExpandApplyableResource
    provider["terraform.io/builtin/terraform"] - *terraform.NodeApplyableProvider
  terraform_data.two (expand) - *terraform.nodeExpandApplyableResource
    provider["terraform.io/builtin/terraform"] - *terraform.NodeApplyableProvider

Expected Behavior

The instances should always be created in the order terraform_data.one -> terraform_data.three

Actual Behavior

There is no order enforced between the creation of instances one and three,

Steps to Reproduce

terraform apply

Additional Context

What is happening is that terraform_data.three does depend on the terraform_data.two configuration being evaluated, but there are no instances planned to go long with that evaluation. Because there are no terraform_data.two instances there is nothing to connect the terraform_data.three instances with the terraform_data.one instances. The terraform_data.two config (the config is represented by (expand) here) does depend on terraform_data.one (expand) node, but that does not depend on the terraform_data.one instances because that dependency travels in the inverse direction.

This results in the configuration evaluation happening in the correct order, but the actual resource instances may be applied in a different order. This doesn’t normally matter because once once the configuration is complete most resources can be applied without a problem, but depends_on is also used to represent dependencies outside of terraform which are not visible via the instance configuration.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions