top of page
  • Facebook
  • Twitter
  • Linkedin

Automation - Terraform IaC with VS Code on AWS Cloud: A Step-by-Step Guide

Aug 2

2 min read

1

26

0

Infrastructure as Code (IaC) has revolutionized how we manage cloud resources. In this blog, we’ll walk through automating AWS infrastructure using Terraform, starting from setting up your local system, environment to provisioning and tearing down resources like VPCs and subnets.


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

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

Install the AWS Command Line Interface (CLI) to interact with AWS services from your terminal. Below is the link to download.

https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html


Step 3: Install Terraform

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

https://developer.hashicorp.com/terraform/install


Make sure to verify the installation by running # 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 provide syntax highlighting, auto-completion, and integration with AWS services.



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 instruction and screenshots below.

  • Go to https://console.aws.amazon.com/

  • Region >> IAM >> Create user >> Set Permissions >> Create User

  • User >> Security Credentials >> Create Access Key


    Note - Make sure you save generated Access Key and Secret Key to use later.




Step 6: Configure Terraform to Create AWS VPC and Subnet

Create a Terraform configuration file (xxx.tf) with the complete syntax as you need.

  • # aws configure (Configure with IAM Access key + Secret key)

  • Make your code ready for provisioning or manage

  • # terraform init (Initialize)

  • # terraform apply (Apply)

  • Confirm creation by typing yes when prompted



Below was the code, I used to provion AWS VPC & Subnet.




Step 7: Verify VPC and Subnet in AWS GUI Console



Step 8: Destroy Resources

  • # terraform destroy (To delete/destroy previous provisioned)

  • Confirm deletion/destroy by typing yes when prompted


Once, destroy is complete, you can verify from AWS GUI console.



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. Hope this help, Good luck!

Related Posts

Comments

Share Your ThoughtsBe the first to write a comment.

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