Create VPC Using Terraform AWS | Create AWS VPC Using Terraform | Terraform Create VPC

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello friends and welcome back to my channel I am your friend ashpak in our last video we had installed the terraform on the windows 11. and in today's video we will deploy the AWS VPC using terraform and then we will deploy the ec2 instance on that VPC using terraform let's get started if I go to my AWS console and inside the VPC you can see I am not having any VPC as of now and we are going to create the VPC using terraform first of all I will have to install the AWS CLI in my system my system is 64-bit so I will download this MSI file I will install this EXE finish I will go to command prompt and I will give you the command AWS hyphen F1 version so AWS CLI has been installed in my system in my local system I will create one folder for the terraform files I will open the Visual Studio code I will open the created folder I will create the file and give the name main.tf now actually I have to register the AWS provider in the terraform so I will give this commands in the terraform to register the AWS provider this would be the source this is the version and our provider would be registered for the region AP South 1. I will save this file I will open the terminal and I will first of all do the terraform init Okay so AWS provider has been registered now I will go to my AWS console I will go to IM users add user I will give the name Cloud admin next attach policies I will give the administrator access next create user so Cloud admin user has been created I will go to user security credentials under the access keys I will click on create access key CLI I will take here next create accessory I will copy the access key I will go to vs code and I will give here the command AWS configure I will paste the access key and hit enter I will now copy the secret key and I will paste it here and hit enter so we have successfully logged into the AWS through the CLI now I have to create the VPC so I will give this commands resources AWS VPC and this would be the name of our UPC and this is the cidr block for our VPC 10.0.0.016 and tenancy would be default I will save the file and I will give you the command terraform apply I will give the value yes and hit enter okay so one resource added if I go to console and I will type here VPC so you can see here we have one VPC available which we have just created and this cidr block is 10.0.0.0 16. okay now I have to create the public and private subnet so with this script we will be creating the public subnet resources AWS subnet this would be the name of our subnet and VPC ID it has taken from the previously created VPC this is the name of the VPC sorry this is the resource for the VPC and this is the name of the VPC which we had given during the creation and this would be the script for the private subnet resources AWS subnet and this would be the name of our private subnet lab private subnet VPC ID and cidr block for the private subnet would be 10.0.2.0 24. I will save the file and here I will give the command terraform apply enter value yes so resource created to if I go to AWS console and go to subnets so these are the two subnets which has been created just now with the cidr block to create the Security Group I will give this code in which resources AWS Security Group and this will be the name of our Security Group and our security group will actually allow the Port 22 Port 22 for the neip and this code will allow the port 22. from anywhere and this will allow the output traffic 4 any port s any IP so this is the complete code to create the security group and to add the inbound and outbound rules to it I will save the file and I will give the command data form apply yes so one added main Security Group has been added on the AWS console if I go to Security Group so you can see here our secret group has been created to create the internet gateway I will give this code resources AWS internet gateway and this will be the name of our internet gateway this is the VPC ID and this would be the tag so this is my complete code to create the internet gateway I will save the file and I will give the command terraform apply yes so resource one added if I go to AWS console and if I go to internet gateways you can see here internet gateway has been created now I have to create the elastic IP and the Knight Gateway net Gateway will actually map the private IP to the public IP for the internet access to our subnet so to create the elastic IP I will give this code resource AWS EIP and this this will be the name of our elastic IP and to create the net Gateway I will give the code resources AWS net Gateway and this will be the name of our Nat Gateway and allocation ID is AWS EIP which is the resource for the elastic IP and this is the name of our elastic IP and subnet ID this is the resource name AWS underscore subnet and this is the name of our public subnet and we are going to tag to our net Gateway as lab net Gateway to ensure proper ordering it is recommended to add a explicit dependency on the internet gateway for the VPC to add the dependency I will give this command in the code so this is actually resource for the internet AWS internet gateway and this is the name of our internet gateway so this is the complete Command to create the elastic IP and the net Gateway I will save the file and I will give the command terraform apply yes so two resource has been added if I go to AWS console and go to Nat Gateway so this is the lab net Gateway which has been created just now and this is the elastic IP which has been created just now now I have to create the public and private root table so I will give this code to create the public root table this is the resource AWS root table and this will be the name of our root table lab VPC public root table this is the VPC ID and all the traffic for the internet would be forwarded to the internet gateway and this is the tag which we are doing I will now give the code for the private root table resource is AWS root table and this will be the name of our root table private VPC lab VPC private root table and this is the VPC ID all the Trap traffic for the private root table will be forwarded to our net Gateway and this is the name of our net Gateway and this is this is the tag which we are giving to private root table I will save the file and I will give the command terraform apply yes so two resource has been added which means our public and private root table has been created to create the public root table Association I will give this code in which this is our resource AWS root table Association and this will be the name of our root table Association and this is the subnet ID for our public subnet and this is the ID for our public root table this code will actually associate our public subnet with the public root table I will now give the code for the private root table Association in which this is the resource AWS root table Association and this will be the name of our private root table Association this is the ID for the private subnet and this is the ID for the private root table and this code will actually associate our private subnet with the private root table I will save the file and I will give the command terraform apply yes so two resource has been added which means public and private root table Association has been created to create the ec2 instance using terraform I will give the code in this code this is the AWS resource AWS instance and this would be the name for our resource lab web server and this is the Mi ID if you go to AWS console and if you go to ec2 instance launch in launch instance and you select your instance so you you can find the Mi ID here and this Mi ID is region specific if you select the some another region this would get changed and this is the Mi ID we are using here in the code instance type T2 micro and keeper name this is the keeper name which which is available in my account you will have to use the keeper name which is available in your account this is the of ID of the public subnet and this is the ID for the Security Group which we had created previously associate public IP address true volume size would be 20 GB and it will delete on termination true it will delete the volume when the instance is deleted and this would be the tag which we we should get assigned to our ec2 instance so this is the complete code to create the ec2 instance in this VPC I will save the file and I will give the command terraform apply yes it gave me the error I will retry but this time in my code instance type I will select P3 micro I will save the file and I will try again yes okay one resource added I will go to my AWS console I will go to ec2 [Music] instances so you can see our instance is available which is initializing I will select the created easy to instance connect connect I have allowed the password Authentication for the ec2 instance I will now reset the password for my username I will now restart the SSD service I will copy the public IP address of the ec2 instance and I will open the putty [Music] I am able to access the ec2 instance through the putty using public IP which means all the routing are working properly as I am able to access the ec2 instance from my system through the public IP by this way you can create the AWS VPC using terraform code and you can also create the ec2 instance in that VPC using the terraform code the link to download this complete code I will provide you in the description hope you find this video helpful lot of effort went behind this video so do subscribe to my channel to encourage my work like the video share it with the friends and spread the knowledge I will see you in the next video thank you
Info
Channel: Virtual TechBox
Views: 104
Rating: undefined out of 5
Keywords: create aws vpc with terraform, create vpc using terraform aws, create aws vpc using terraform, terraform create vpc, aws vpc using terraform, terraform create vpc aws, terraform code to create vpc and subnets, deploy vpc using terraform, terraform code to create vpc, aws vpc terraform code, terraform create vpc and ec2, terraform code to create vpc and ec2, terraform create vpc and subnets, aws vpc terraform, how to create vpc using terraform, terraform aws tutorial
Id: J42nTIzcnvA
Channel Id: undefined
Length: 31min 30sec (1890 seconds)
Published: Thu May 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.