Book Image

Getting Started with Terraform

By : Kirill Shirinkin
Book Image

Getting Started with Terraform

By: Kirill Shirinkin

Overview of this book

Terraform is a tool used to efficiently build, configure, and improve production infrastructure. It can manage existing infrastructure as well as create custom in-house solutions. This book shows you when and how to implement infrastructure as a code practices with Terraform. It covers everything necessary to set up complete management of infrastructure with Terraform, starting with the basics of using providers and resources. This book is a comprehensive guide that begins with very small infrastructure templates and takes you all the way to managing complex systems, all using concrete examples that evolve over the course of the book. It finishes with the complete workflow of managing a production infrastructure as code – this is achieved with the help of version control and continuous integration. At the end of this book, you will be familiar with advanced techniques such as multi-provider support and multiple remote modules.
Table of Contents (15 chapters)
Getting Started with Terraform
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Importing resources


Sometimes, the resource was created manually. For example, you might have had an existing AWS infrastructure in place before you decided to introduce Terraform to your company. Now you need to move it somehow under Terraform's control. One option is, of course, to just recreate everything. Not all the resources are that easy to recreate though. That's where the terraform import command will help us.

If you destroyed it before, then rerun the template to create a new VPC. Then, create a new NAT gateway manually from AWS Management Console:

To import it, we need to know the ID of this gateway:

Copy it and go back to console. To add this gateway to the state file, you need to execute the following command:

$> terraform import aws_nat_gateway.imported_gateway nat-034caa3c2000cd7fb      
provider.aws.region
aws_nat_gateway.imported_gateway: Importing from ID "nat-034caa3c2000cd7fb"...
aws_nat_gateway.imported_gateway: Import complete!
  Imported aws_nat_gateway (ID: nat-034caa3c2000cd7fb...