0

I have a terraform repo and infrastructure and its state in s3. But its 0.11 version of terraform and all the modules used in the code were never upgraded. Now it has become a useless piece of code and a bottleneck. Here is my plan:

  1. Create a new terraform repo with new folder structure with latest modules.
  2. Create the code with latest terraform version
  3. Create a statefile for the existing infrastructure from old statefile. with UIDs and etc.
  4. Terraform plan and apply but there should be no resource recreation or changes.

Now i have two terraform repos for the same infrastructure and i retire the old one.

Is it possible?

Prasanna P
  • 114
  • 4
  • Not sure what the 3rd step represents. Do you mean import existing resources ? – Marko E Aug 07 '22 at 06:09
  • apply the new code once . generate a new statefile for the new structure. then copy each resource from the existing statefile to the newone. – Prasanna P Aug 07 '22 at 06:49
  • I don't think you should do that, especially if you are planning to move to Terraform version 1.x.x. There are steps you can take to migrate from 0.11 to 1.x.x. But manual changes to state file are almost always a bad idea. – Marko E Aug 07 '22 at 07:01
  • 1
    You can either follow the [upgrade paths](https://www.terraform.io/language/upgrade-guides) through each version to present, or you can just import things into your fancy new state. That would be simply write it until the plan represents your current resources, then import each one, until the plan shows no changes. No applies necessary. – theherk Aug 07 '22 at 11:14

0 Answers0