Short answer: Unsure.
Longer answer:
Dug into it a bit. Considered a simple vpc and a security group. Here’s an example repo to help: https://github.com/tongueroo/infra-replace
Here’s some debugging to look at the plan. Deployed everything. And then changed the VPC CIDR and ran these commands to see what info was available in the plan.
terraspace build vpc
cd .terraspace-cache/us-west-2/dev/stacks/vpc
terraform plan --out plan.binary
terraform show -json plan.binary | jq -r '.' > plan.json
cd - # back to terraspace project
terraspace build sg
cd .terraspace-cache/us-west-2/dev/stacks/sg
vim 1-dev.auto.tfvars # change to "(known after apply)"
terraform show -json plan.binary | jq -r '.' > plan.json
It looks like the plan.json has info about resource that will need to be “replaced”. So Terraspace would be able to see, to a degree, if resources require “replacement”, IE: ["delete", "create"]
.
Note: The terraspace dependency calculation currently happens as part of the compile phase, and outputs are recalculated as part of each batch run and “refeed” into each batch since outputs are not known until after apply. So there is some runtime processing element as part of terraspace all
already.
Thinking as part of the terraspace dependency graph calculation would have to do some additional passes.
- Pass 1: Resolve the graph based on inputs and outputs wiring. The way it’s currently done.
- Pass 2: Additional pass does a
plan
within the order from the first resolved pass 1.
- Pass 3: Using the additional info, recalculate the final graph with additional
terraspace down
operations at the beginning.
Terraspace could run terraspace down
on the child sg stack first and then run terraspace up
on the vpc and then sg.
However, Terraspace might have make some additional assumptions. The example repo has some random_pet resources to kind of help illustrate this. Let’s say those resources need to be replaced. Terraspace might have to assume any resources within the stack that require replacement will result in the whole stack being flagged as a possible candidate for a terraspace down
. Unsure if it’s possible to know to which resource is being replaced and consider that without making it even more complicated.
Would like to attempt this. Unsure when, though. It’s a matter of time Attempted terraspace all
several times before eventually figuring it out. Hoping it’s possible without it being too complex Unsure.
Wondering if there are examples from other tools or someone that has done something similar that could help. I don’t believe there are, but if so, it might be worth studying. Maybe terraform source itself? Will review and consider PRs. Of course. No sweat either way.