top of page
  • Facebook
  • Twitter
  • Linkedin

Automating AWS Infrastructure with Terraform

Aug 2

3 min read

2

59

1

What’s Covered in This Blog Post?


  • Step 1: Install Visual Studio Code

  • Step 2: Install AWS CLI

  • Step 3: Install Terraform

  • Step 4: Install VS Code Extensions

  • Step 5: Set Up AWS IAM

  • Step 6: Configure Terraform to Create AWS VPC and Subnet

  • Step 7: Verify VPC and Subnet in AWS Console

  • Step 8: Destroy Resources


Please Note: I've pasted the screenshots from my lab for your reference.


Step 1: Install Visual Studio Code


First, download and install Visual Studio Code for your operating system. It’s a lightweight, powerful editor that’s widely used for writing and managing scripts. While VS Code offers a rich development experience with extensions and syntax support, you can also use PowerShell or Command Prompt (CMD) for executing Terraform commands if you prefer a simpler interface.


Step 2: Install AWS CLI


Next, install the AWS Command Line Interface (CLI). This tool allows you to interact with AWS services directly from your terminal. Below is the link to download it:

Download AWS CLI


Step 3: Install Terraform


Now, download Terraform from the official HashiCorp website. Follow the installation instructions specific to your operating system. The site provides installers and detailed setup guides for Windows, macOS, and Linux platforms.

Download Terraform


After installation, verify it by running the following command:

```bash

terraform -v

```


Step 4: Install VS Code Extensions


To enhance your development experience, install the following extensions in VS Code:


  • AWS Toolkit

  • Terraform by HashiCorp


These extensions provide syntax highlighting, auto-completion, and integration with AWS services.


ree

Step 5: Set Up AWS IAM


Ensure you have an IAM user with programmatic access and necessary permissions to provision and manage resources. Follow the instructions and screenshots below:


  1. Go to AWS Management Console

  2. Navigate to IAM and create a user.

  3. Set permissions and create the user.

  4. Under Security Credentials, create an Access Key.


Note: Make sure to save the generated Access Key and Secret Key for later use.


ree
ree
ree
ree
ree
ree

Step 6: Configure Terraform to Create AWS VPC and Subnet


Create a Terraform configuration file (e.g., `main.tf`) with the complete syntax you need. Here’s how to set it up:


  1. Run the command to configure AWS with your IAM Access Key and Secret Key:

    ```bash

    aws configure

    ```

  2. Prepare your Terraform code for provisioning.

  3. Initialize Terraform with:

    ```bash

    terraform init

    ```

  4. Apply the configuration with:

    ```bash

    terraform apply

    ```

  5. Confirm the creation by typing "yes" when prompted.


ree

Below is the code I used to provision AWS VPC and Subnet:


ree
ree
ree
ree

Step 7: Verify VPC and Subnet in AWS Console


After applying the Terraform configuration, verify that your VPC and Subnet have been created successfully in the AWS Management Console.


ree
ree

Step 8: Destroy Resources


When you're done testing, you can clean up your resources. To delete the previously provisioned resources, run the following command:

```bash

terraform destroy

```

Confirm the deletion by typing "yes" when prompted.


ree

Once the destruction is complete, verify from the AWS Management Console to ensure all resources have been removed.


Conclusion


With Terraform, you can automate AWS infrastructure efficiently and consistently. This hands-on guide helps you get started with IaC and lays the foundation for more advanced automation workflows. I hope this helps you on your journey! Good luck!



By following these steps, you’ll be well on your way to mastering Infrastructure as Code with Terraform. Enjoy the process, and don't hesitate to reach out if you have any questions!

Related Posts

Comments (1)

nazs
Sep 03

Thank you for this article. nicely explained.

Like

Contact Us

Thanks for submitting!

 Address. 500 Terry Francine Street, San Francine, CA 94158

Tel. 123-456-7890

© 2035 by ITG. Powered and secured by Wix

bottom of page