Skip to content

on destroy: dependency order wrong #422

Description

@TobiPeterG

Bug report

I try to create VMs in proxmox, which should be added to a pool. The pool and the VM are configured through terragrunt, but different opentofu configs. I added a "dependency" in the VM terragrunt.hcl on the pool config to make sure that the pool is created before the VM is, so the VM can be added to the pool. Creation works perfectly, however, destroying VMs with their pool is a bit difficult: the pool is always tried to be destroyed first, then the VM. This however fails as the pool is not empty. After the VM has been destroyed, the pool can then be destroyed. My guess is that when a destroy is planned, the dependency order is not reverted (so on destroy the pool should depend on the VM plan being executed first).
I plan the destroy using "atlantis plan -- -destroy".

To Reproduce

Summarize how to reproduce the behavior. For example:

  1. Create 2 terragrunt configs
  2. Let one depend on the other
  3. Apply
  4. Run "atlantis plan -- -destroy" to plan a destroy
  5. Apply

Expected behavior

No error. I expected the depending plan to be applied first

Actual behavior

The dependency tree is not inverted and applying fails

Relevant Terragrunt files
VM config:

include {
  path = find_in_parent_folders("backend.hcl")
}

terraform {
  source = find_in_parent_folders("tf_vm_config")
}

dependency "pve_pool" {
  config_path  =  "../"
  skip_outputs = true
}

locals {
  defaults     = read_terragrunt_config(find_in_parent_folders("config.hcl"))

  current_dir  = basename(get_terragrunt_dir())
  dir_parts    = split("_", local.current_dir)
  vm_date      = length(local.dir_parts) > 0 ? local.dir_parts[0] : "000000"
  nb_name      = length(local.dir_parts) > 1 ? local.dir_parts[1] : "default-name"
  proxmox_pool = basename(dirname(get_terragrunt_dir()))
}

inputs = merge(
  local.defaults.inputs,
  {
    nb_name               = local.nb_name
    vm_name               = "${local.vm_date}-${local.nb_name}"
    vm_networks           = ["network-name"]
    proxmox_vm_pool       = local.proxmox_pool
    vm_root_disk_size          = 80
    vm_cpu                = 8
    vm_memory             = 8
  }
)

pool config:

include {
  path = find_in_parent_folders("backend.hcl")
}

terraform {
  source = find_in_parent_folders("tf_pool_config")
}

locals {
  defaults     = read_terragrunt_config(find_in_parent_folders("pool_config.hcl"))

  current_dir  = basename(get_terragrunt_dir())
}

inputs = merge(
  local.defaults.inputs,
  {
    proxmox_vm_pool       = local.current_dir
  }
)

Should you need more information, please let me know :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions