0
votes

When I define terraform code for AWS resources I have not used before, I am sometimes unsure about how to define my components. I then often just apply any component and modify it using the AWS GUI. Then I use terraform plan to see my changes and adapt my code, so that it corresponds to the existing AWS infrastructure.

I wonder whether there is a more direct way to use the AWS GUI to define terraform code. Is there any way to just map an existing AWS infrastructure to terraform code?

1

1 Answers

1
votes

What you want is terraform import

Terraform is able to import existing infrastructure. This allows you take resources you've created in aws via the GUI and bring it under Terraform management. The current implementation of Terraform import can only import resources into the state file. It does not generate configuration. This will however enable you to then configure your resources

This is how to import an instance with ID i-abcd1234 to address aws_instance.bar

terraform import aws_instance.bar i-abcd1234

https://www.terraform.io/docs/import/