You’re on-call for a fintech platform migrating Terraform state across dozens of modules (core ledger, payments, risk, checkout). A bad move order can break production deploys, causing revenue-impacting outages and compliance incidents.
You are given:
moves: a list of Terraform state move operations. Each move is [from_addr, to_addr, module].dependencies: a list of module dependencies [parent, child] meaning parent must be processed before child.Your job is to produce a deterministic list of move indices describing a safe execution order.
Return a list of indices (0-based) into moves such that:
dependencies (a topological order).to_addr.[] if the plan is invalid:
from_addr repeats, or any to_addr repeats.to_addr is also present as a from_addr anywhere (would imply moving into an address that is later moved away).to_addr ends with the suffix ".same", treat it as a reserved address and return [].Example 1
dependencies = [["core","payments"],["core","risk"],["payments","checkout"]],
moves = [["aws_iam_role.old","module.core.aws_iam_role.new","core"], ["aws_kms_key.pay","module.payments.aws_kms_key.pay","payments"], ["aws_s3_bucket.logs","module.risk.aws_s3_bucket.logs","risk"], ["aws_lb.front","module.checkout.aws_lb.front","checkout"]][0, 1, 2, 3]core must come before payments and risk; payments must come before checkout. With lexicographic tie-breaks and one move per module, indices follow that module order.Example 2
dependencies = [], moves = [["a","module.m.z","m"],["b","module.m.a","m"],["c","module.m.m","m"]][1, 2, 0]to_addr: a, m, z.