Description • Pre-requisites • How it works • Tech Stack • Author • License
This project provisions a VPC and an EC2 instance on AWS through Terraform. In this project, the terraform.tfstate file is stored remotely in an S3 bucket. In addition, we have the creation of a Subnet, AWS Internet Gateway, Route Table and AWS Security Group. Finally, an EC2 instance is created within the Subnet. All resources will be created in the us-east-1 region.
Before you begin, you will need to have the following tools installed on your machine: [Terraform] (https://www.terraform.io/) and [Git] (https://git-scm.com). You will need to have a [AWS Account] (https://aws.amazon.com/). In addition, it is good to have an editor to work with the code like [VSCode] (https://code.visualstudio.com/).
1 - Clone this repository.
git clone [email protected]:diogofiaminghi/terraform-project-01.git
2 - Create an S3 bucket on AWS manually.
3 - Open de Project Folder in VSCode
4 - Edit the main.tf file. On line 13, paste the name of your S3 bucket.
bucket = "your-S3-bucket-name-here"
5 - Open a new bash terminal in VSCode. Create an SSH key pair named 'aws-key'.
ssh-keygen
6 - You must now configure your AWS Access Keys using the bash terminal.
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7 - Terraform Commands in Project Folder
terraform init
terraform fmt
terraform validate
terraform plan -out=plan.out
terraform apply plan.out
8 - Now, to prove that everything worked, get the 'vm_ip' in 'output' and let's connect via ssh to the newly created instance.
ssh -i "aws-key" ubuntu@the-public-ip-here
exit
9 - Do not forget to destroy the provisioned structure otherwise you will be able to receive invoices.
terraform destroy
The following tools were used in the construction of the project:
This project is under the license MIT.
Made with love by Diogo Fiaminghi 👋🏽 Get in Touch!