DEV Community

Luis Miguel Guerra Quispe for AWS UG Peru

Posted on

3

AWS: Create VPCs, Subnet's, NatGateway and InternetGateways with Terraform

Install Terraform and create a custom VPC

I am learning to create Infrastructure with Terraform from scratch, I decided to apply what I learned and be able to share it with you.
Any comments on how to improve these instructions let me know.
I hope you find this helpful

The instructions below are for Windows .

  1. Install VSCode from https://code.visualstudio.com/
  2. Install Terraform from https://chocolatey.org/install
  3. Install GIT from https://git-scm.com/downloads
  4. Install AWS CLI from https://awscli.amazonaws.com/AWSCLIV2.msi

We will proceed to configure our AWS Credentials with CLI.
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html

After having the necessary tools, we will proceed to clone the repository.
https://github.com/lguerraq/AWS-VPC

We will open the cloned folder with VSCode.

We will place the name of the configured profile in the Credentials file (/.aws/credentials)

variable "profile" {
  description = "Profile for providers"
  type        = string
  default     = "NameProfile"
}
Enter fullscreen mode Exit fullscreen mode

With the aforementioned we will proceed to apply the Terraform commands for the deployment.

### Init terraform
 *  terraform init

 ### Validate terraform
 *  terraform validate

 ### Fmt terraform
 *  terraform fmt

### Plan terraform by environment
 *  terraform plan -var-file environment-vars/prd.tfvars

### Apply terraform by environment
 *  terraform apply -var-file environment-vars/prd.tfvars

### Destroy terraform by environment
 *  terraform destroy -var-file environment-vars/prd.tfvars
Enter fullscreen mode Exit fullscreen mode

https://www.terraform.io/cli/commands

Until the execution of Terraform apply we will validate that our VPC was created correctly.

To destroy the VPC we will execute Terraform destroy.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more