Very similar to this old post, I have Terraform code but the state file was stored locally on someone’s laptop and is long gone. Re-creating the state file, or creating a plan to match existing infrastructure bringing it into Terraform, is certainly possible. We know that some unknown portion of the infrastructure has been changed outside of Terraform, so it’s not completely in sync.
My issue is that terraform plan
does a great job of saying what TF thinks it needs to do. However, terraform plan -json
is sparse and lacks any of the detail of the non-json output. It is missing crucial information like name
property, tags, or other context that would help trying to match a TF-declared resource with the existing AWS resource it belongs to.
terraform plan -out=somefile
is also not helpful because the plan file inside the generated zip is itself a binary file. Terraform code as a whole is not parsable HCL (says the hcl
rubygem), so that’s out as well.
Is there something I’m doing wrong with Terraform that I could get machine-readable output from some form of terraform plan
? Alternatively, is there a parser (preferably Ruby or Python) that can read Terraform code into native rb/py objects?
So far my best idea is a token parser that grabs the resource ...
block, and parses everything between that resource’s {
and }
as HCL. Surely I’m making this much harder than it needs to be?