recover .tf config from .tfstate

413 views
Skip to first unread message

phalient

unread,
Mar 27, 2015, 5:34:17 PM3/27/15
to terrafo...@googlegroups.com
Hi guys

Just started with Terraform so nothing serious and not backing up my work.

I just hit a bump where my .tf file is hosed (by my own doing) but my .tfstate is fine (still reflective of my island) and terraform plan/refresh

Probably won't happen when I start getting real work done (version control, backups etc) but curious what you guys do if ever this situation eventuated for you. ie .tf file not usable/too hard to rebuild but .tfstate is still ok.

Or have I missed something about the inherent workflow in terraform?

cheers

Mitchell Hashimoto

unread,
Mar 27, 2015, 5:39:27 PM3/27/15
to phalient, <terraform-tool@googlegroups.com>
Hi,

This isn't possible right now but this is planned as a major feature, likely for 0.6+, not for 0.5.

Best,
Mitchell

--
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To post to this group, send email to terrafo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/9d77e616-e7db-4825-87ba-6cf6886f15f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Cunningham

unread,
Mar 30, 2015, 7:25:40 AM3/30/15
to Mitchell Hashimoto, phalient, <terraform-tool@googlegroups.com>
I think there is information lost in the tf -> tfstate process but not sure exactly what:

Variables?  Interpolation code?  Modules?

Even so it should be possible to generate something useful from the tfstate (analogous to reverse engineering a compiled executable) and then that tf file could then be refactored manually.

Armon Dadgar

unread,
Mar 30, 2015, 12:56:02 PM3/30/15
to David Cunningham, Mitchell Hashimoto, 'David Cunningham' via Terraform, phalient, <terraform-tool@googlegroups.com>
Hey David,

The state file contains a snapshot of the world view of Terraform, where the TF files themselves
are the desired state. Inside the TF file, attributes of resources may be specified as a constant,
a variable, interpolation, or allowed to be computed. But once the state file is created that information
is lost and only the value is retained. For example an instance will have a “vpc_id” but there is no sane way
to reverse from that how it was populated.

It would be possible to generate TF config from a state file, but it would be a very lossy transformation.

Best Regards,
Armon Dadgar

David Cunningham

unread,
Mar 30, 2015, 1:01:42 PM3/30/15
to Armon Dadgar, Mitchell Hashimoto, 'David Cunningham' via Terraform, phalient
Does it also lose the module structure (flatten the resources)?

Mitchell Hashimoto

unread,
Mar 30, 2015, 1:06:23 PM3/30/15
to David Cunningham, Armon Dadgar, 'David Cunningham' via Terraform, phalient
David,

The module structure is encoded in the state.

Best,
Mitchell
Reply all
Reply to author
Forward
0 new messages