2

When we were building our AWS account, we did not think about using cloud formation or terraform. Now we have our environmemt all setup but don't want to tear down everything and build using cloud formation or terraform. So is there a way we can get our infrastructure to be imported and managed through one of them?

Thanks,

Karthik
  • 339
  • 1
  • 7
  • 24

3 Answers3

4

Terraform supports import, but that only supports the present state into state file. You still need to write the code. Cloudformation does not support import.

Something like https://github.com/dtan4/terraforming can be of help but YMMV.

Anshu Prateek
  • 3,011
  • 1
  • 18
  • 33
  • Thanks for letting me discover terraforming! – marco.m Oct 13 '17 at 17:06
  • @AnshuPrateek Sorry for the late response. I have tried importing the exisiting infrastructure via terraform import command but how do I exactly have everything written into main.tf and have the infra managed through one file? – Karthik Oct 22 '17 at 21:58
  • import will only add it to your state file. To generate the main.tf , you need to use terraforming. – Anshu Prateek Oct 23 '17 at 04:23
  • +1 for terraforming : ) very neat tool, and I agree YMMV, and yes, TF doc is here they say they will in the future: https://www.terraform.io/docs/import/index.html – Fabio Pedrazzoli Grazioli Feb 09 '18 at 10:28
1

A pretty complete answer could be found at AWS Export configuration as cloudformation template, which also covers Terraform for this purpose.

TL;DR

AWS Import/Export configuration as code (CloudFormationn | Terraform).

Based on our Infrastructure as Code (IaC) experience we found several ways to translate existing manually deployed (from Web Console UI) AWS infra to Cloudformation (CF) and / or Terraform (TF) code. Posible solutions are listed below:

AWS Cloudformation Templates

Terraform Code / Modules


Related Article: https://medium.com/@exequiel.barrirero/aws-export-configuration-as-code-cloudformation-terraform-b1bca8949bca

Exequiel Barrirero
  • 4,998
  • 1
  • 36
  • 27
0

As per October 2019, AWS supports importing legacy resources into CloudFormation. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import.html for examples.

Dennis
  • 779
  • 4
  • 14