/terraform-aws-infra

Create infra AWS with Terraform

Primary LanguageHCL

CASE STUDY TERRAFORM AWS

This case study, I will be create enviroment in AWS usyng EC2, Security Groups, S3 and DynamoDB.

SUMMARY

  • Create dynamic EC2 Instances Ubuntu
  • Add access SSH for Instances
  • Create EC2 Instance in another region and usyng the same ssh key
  • Create Bucket S3 and associate a Instance EC2
  • Create Database Dynamodb

Screen Shot 2022-09-08 at 11 42 29

Create AWS account

This link set a tutorial Create AWS Account

AWS CLI configure

This link set a tutorial AWS CLI configure.

Download TERRAFORM CLI

This link download Terraform CLI.

Create Key to SSH access

cd ~/.ssh
ssh-keygen
Enter file in which to save the key (/home/schacon/.ssh/id_rsa): terraform-aws

In AWS Console, access EC2 Service then in sidebar look for Key pair. Select Option> Import Key Pair.

Screen Shot 2022-09-08 at 11 51 32

cd ~/.ssh && cat terraform-aws.pub

Import yout public key. You need repeat this Step in each EC2 Service diferent region

VPC / SUBNET / YOUR IP ACCESS

In file .vars.example rename to vars.tf and set your config data.

TERRAFORM ( PLAN / APPLY )

Now, in terminal run command terraform plan

Screen Shot 2022-09-08 at 12 09 01

Run terraform apply

Screen Shot 2022-09-08 at 12 11 44

SSH ACCESS EC2

Access your EC2 instance and Connect.

Screen Shot 2022-09-08 at 12 13 28

This connect SSH example, in your terminal change to

ssh -i ~/.ssh/terraform-aws ubuntu@ec2-3-23-95-102.us-east-2.compute.amazonaws.com

( ͡❛ ͜ʖ ͡❛)

Result

Screen Shot 2022-09-08 at 12 17 05

REMEMBER DESTROY YOUR ENVIROMENT IN AWS CLOUD

Now run command terraform destroy if you don't, you're going to be in trouble. 💸💸💸💸