1
votes

In my AWS infrasructure, I have several environments existing under an an application, i.e:

  • foo-application (AWS elasticbeanstalk app)
  • foo-application-dev (tomcat envs)
  • foo-application-int
  • foo-application-sys

Of these envs, SYS is closest to the architecture and configuration I need. I want to be able to re-create the other environments to look like sys (but named dev, int). I have terraform scripts that were originally used to create some envs, but these have now deviated from current state. I would like to take the current state from SYS, and apply that to dev and int. I am a newbie to terraform, and stackoverflow, so please cut me some slack :)

All of the envs have a state file, this what I am trying to do but not sure how to go about it..

  • delete all state files
  • create a new state file from the SYS env in SYS workspace
  • copy state to dev and int workspaces
  • apply the dev and int plans and get the envs in synch.

I hope this makes sense.

I ran a terraform plan against the dev env and it looked like it was going to do a lot more than I expected. My research tells me that terraform compares current state to the last time terraform was run - so things done manually in the env may cause issues. I am not confident enough to run apply for fear it will damage my SYS env which I can't have.

what I want: three environments that are very identical except for naming conventions.

1

1 Answers

2
votes

You should use the terraform import workflow to align your SYS environment's state file with the actual infrastructure you created. Note that this will take a lot of work if you've manually created a significant amount of infrastructure in the SYS environment.

However, at the end of this process, you'll have a complete set of Terraform code for the SYS environment which you can turn into a module of reusable components. You can then use this module to create the DEV and INT environments as clones of the SYS environment, but with different naming conventions.