7

I have an AWS environment that was built 100% with Terraform. I haven't touched it in a few days, but today when I went to make what I thought was a fairly trivial change, Terraform has decided that it wants to build me an entire new AWS infrastructure. Backing out of the change made no difference, no matter what I do, Terraform now wants to build new infrastructure.

It does not want to tear the old infrastructure down, it wants to build this new infrastructure side-by-side with it.

It's basically acting like all my pre-existing infrastructure just doesn't exist.

I suspect it's because everything is tied to a VPC, and because it thinks it needs to create a new VPC everything downstream of the VPC (i.e. everything) is also re-created so the IDs match.

I'm very new to Terraform, so is there any way I can "force" Terraform back into its old state?

Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
  • 1
    sounds like your state file was removed or it can't find where it is. So its trying to re-build everything – Mike Mar 19 '18 at 01:58
  • That or you have selected a new workspace. Double check with terraform workspace list – SnIpY Mar 19 '18 at 15:00
  • @Mike how does one go about getting the state file re-populated from an existing environment? – Mark Henderson Mar 19 '18 at 20:16
  • If you lost the state file then there is no easy way unless you go resource by resource and importing it – Mike Mar 20 '18 at 00:50

1 Answers1

2

It would appear an errant global find and replace was to blame for this problem - it modified the Terraform state file, which cause this cascading issue.

Restoring a version of the state file that did not have this issue has fixed the issue.

I think it's time to get the terraform state file into S3 so this doesn't happen again.

Mark Henderson
  • 68,316
  • 31
  • 175
  • 255