<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Roger Filomeno</title>
    <description>The latest articles on DEV Community by Roger Filomeno (@rpfilomeno).</description>
    <link>https://dev.to/rpfilomeno</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F800601%2Fdf17fd1b-45e6-4d05-8982-9f95ee58a20c.jpeg</url>
      <title>DEV Community: Roger Filomeno</title>
      <link>https://dev.to/rpfilomeno</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rpfilomeno"/>
    <language>en</language>
    <item>
      <title>Importing Existing AWS Infrastructure to Terraform</title>
      <dc:creator>Roger Filomeno</dc:creator>
      <pubDate>Fri, 21 Jan 2022 12:01:59 +0000</pubDate>
      <link>https://dev.to/rpfilomeno/importing-existing-aws-infrastructure-to-terraform-5hda</link>
      <guid>https://dev.to/rpfilomeno/importing-existing-aws-infrastructure-to-terraform-5hda</guid>
      <description>&lt;p&gt;We all know about Terraform, the leading Infrastructure as Code platform, however what will you do if you already built the infrastructure? How will you still be able to leverage Terraform without needing to rewrite hundreds of definitions from scratch. As of this time in writing there is no existing way to import all resources at once using Terraform: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The terraform import command is used to import existing infrastructure.&lt;/p&gt;

&lt;p&gt;The command currently can only import one resource at a time. This means you can't yet point Terraform import to an entire collection of resources such as an AWS VPC and import all of it. This workflow will be improved in a future version of Terraform.&lt;/p&gt;

&lt;p&gt;--- &lt;a href="https://www.terraform.io/docs/cli/import/usage.html'"&gt;https://www.terraform.io/docs/cli/import/usage.html'&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thats where &lt;a href="https://github.com/GoogleCloudPlatform/terraformer"&gt;Terraformer&lt;/a&gt; comes useful: A CLI tool that generates tf/json and tfstate files based on existing infrastructure (reverse Terraform). On this guide we will be using Terraformer and Terraform in Windows to show you all the fixes for the quirks installation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation of Terraformer
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For Windows using &lt;a href="https://chocolatey.org/"&gt;Chocolatey&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Install as admininstrator &lt;code&gt;choco install terraformer&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Download the provvider plugin at &lt;a href="https://releases.hashicorp.com/terraform-provider-aws/3.63.0/terraform-provider-aws_3.63.0_windows_amd64.zip"&gt;https://releases.hashicorp.com/terraform-provider-aws/3.63.0/terraform-provider-aws_3.63.0_windows_amd64.zip&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Crate the provider directory at &lt;code&gt;C:\.terraform.d\plugins\windows_amd64&lt;/code&gt; and unzip the downloaded plugin here.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installation of Terraform
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For Windows using &lt;a href="https://chocolatey.org/"&gt;Chocolatey&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Install as admininstrator &lt;code&gt;choco install terraform&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Credentials
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create the &lt;code&gt;C:\Users\USERNAME\.aws\config&lt;/code&gt; with the following content:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[default]
region = ap-southeast-2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create the &lt;code&gt;C:\Users\USERNAME\.aws\credentials&lt;/code&gt; withh th following content:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[default]
aws_access_key_id = XXXXXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXXXXXXXXXX
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating an Import Plan
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Execute &lt;code&gt;terraform init&lt;/code&gt; where providers.tf file is loccated, add flag &lt;code&gt;-reconfigure&lt;/code&gt; if updating versions of the provider plugins.&lt;/li&gt;
&lt;li&gt;Execute &lt;code&gt;terraformer  plan aws --output hcl --resources="*" --verbose&lt;/code&gt; to create an import plan saved at &lt;code&gt;.\generated\aws\terraformer\plan.json&lt;/code&gt; for all resources located at AWS default region.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Importing using Terraformer
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Execute &lt;code&gt;terraformer import plan .\generated\aws\terraformer\plan.json&lt;/code&gt; to begin importing the resources information and storing their states.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Validating/Applying changes with Terraform
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Change to the generated direvtory such as &lt;code&gt;.\generated\aws\dynamodb&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Execute &lt;code&gt;terraform state replace-provider -- -/aws hashicorp/aws&lt;/code&gt; to update provider in state file.&lt;/li&gt;
&lt;li&gt;Execute &lt;code&gt;terraform init&lt;/code&gt; to reinitialize.&lt;/li&gt;
&lt;li&gt;Execute &lt;code&gt;terraform validate&lt;/code&gt; to check errors in the configuration under this directory.&lt;/li&gt;
&lt;li&gt;Execute &lt;code&gt;terraform plan&lt;/code&gt; to check for changes or &lt;code&gt;terraform apply&lt;/code&gt; to plan and apply changes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;EDIT:&lt;/p&gt;

&lt;p&gt;I'm happy to receive a feedback from Jacob Schulz (DevOps Community Manager @ Spacelift) pointing out that this guide doesn't explain much about &lt;code&gt;terraform import&lt;/code&gt; which will allow you to &lt;a href="https://spacelift.io/blog/importing-exisiting-infrastructure-into-terraform"&gt;import existing resources&lt;/a&gt; as well, Terraformer basically serves as a wrapper for the bulk operations.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To read more blogs on other topics, feel free to visit &lt;a href="https://rpfilomeno.me/blog/"&gt;https://rpfilomeno.me/blog/&lt;/a&gt; or if you are seeking help in AWS join our community at &lt;a href="https://web.facebook.com/groups/AWSUGPH"&gt;https://web.facebook.com/groups/AWSUGPH&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>aws</category>
      <category>terraform</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
