Architecting Your AWS Cloud: A Comprehensive Guide to Deploying VPC, Subnet, RDS, and S3

Creating the VPC and Subnet from Terraform:                We can create the VPC and subnet by using terraform, using the terraform registry...

Creating the VPC and Subnet from Terraform:

               We can create the VPC and subnet by using terraform, using the terraform registry taking the code, change the code for our case. run the terraform commands. build the AWS VPC and subnet.


VPC code:

resource "aws_vpc" "main" {

  cidr_block       = "10.0.0.0/16"

  instance_tenancy = "default"


  tags = {

    Name = "main"

  }

}

“main” need to change our aws custom VPC name, here I am going to give as “techiev-vpc”

For the Cidr_block,  I am going to use the network 192.0.0.0/16

Instance tendency, tags kept the same default, main


Subnet code: 

resource "aws_subnet" "main" {

  vpc_id     = aws_vpc.main.id

  cidr_block = "10.0.1.0/24"


  tags = {

    Name = "Main"

  }

}


Code explanation:

“Main” needs to change our aws custom subnet name, here I am going to give as “techiev-subnet”

For the VPC id need to use our custom VPC name as “aws_vpc.techiev-vpc.id”

For the Cidr_block, I am going to use the network 192.0.0.0/17 so that we can use the 32766 IP address. Tags kept leave it as main only.



Now will run the code using the below commands

terraform init

terraform plan

terraform apply

In this step, it asks for verification, so need to give “yes”.



For the Verification, check the AWS VPC services.



So we successfully created the AWS VPC, subnet using terraform. If we don’t want this VPC and subnet use the terraform destroy command to delete it.

Creating the RDS using Terraform:

RDS is one of the services used for database provisioning. I am going to take the basic usage code from the terraform registry to create the RDS.


RDS code:

resource "aws_db_instance" "default" {

  allocated_storage    = 10

  engine               = "mysql"

  engine_version       = "5.7"

  instance_class       = "db.t3.micro"

  name                 = "mydb"

  username             = "foo"

  password             = "foobarbaz"

  parameter_group_name = "default.mysql5.7"

  skip_final_snapshot  = true

}


Code explanation:

The resource “aws_db_instance”- we are going to create the RDS, It was basically a database instance, so will define as aws_db_instance.

For the DB instance name use our custom name instead of the default, here going to mention “Techiev-DB”.

Allocated storage needs to be defined in the numbers, it takes the numbers in gibibytes.

The engine need to mention the database engine name, Aws has several engines such as mysql, MariaDB, postsql, Oracle, Amazon aurora. So choose anyone for our use cases, 

For us going to use the mysql.

Every engine has versions, so we need to define the version, here I am going to use mysql 8.0.

AWS has the DB instance types(standard, memory-optimized, Burstable), we need to choose the type for our requirements.

For the name, we need to provide the database name. Username and password also set a custom name and password.

Parameter groups can give the default. if already have the custom parameter groups, we can use the custom parameter instead of the default one.

If we want to skip the snapshot of the database, we can give the option “true” in the skip_final_snapshot.



After adding the code inside the terraform file save and run the commands.

terraform init

terraform plan

terraform apply



Now check the AWS console, it definitely automatically created the rds instance.



Now other settings in the RDS kept using the default one, we can customize all the settings using terraform itself, In the next blogs will see to configure RDS as a customized Terraform code.


Creating the S3 Bucket:

 We can create the S3 bucket using the terraform, going to use the example terraform code from the terraform registry.

S3 code:

resource "aws_s3_bucket" "b" {

  bucket = "my-tf-test-bucket"

  acl    = "private"


  tags = {

    Name        = "My bucket"

    Environment = "Dev"

  }

}


Code explanation:

Resource “aws_s3_bucket” kept as same for “b” we can give anything, in my case give as my_first_bucket.

   Bucket name, we need to mention the name of our bucket.

   ACL means access control list, it enables the buckets and objects. for the security reason kept private.

   For the Tags, we can give them to our used case.

   The environment can be given as dev, QA, prod, and pre-prod.

Once all the above codes are updated save them and be ready to run the terraform command.



Run the below commands.

terraform init

terraform plan

terraform plan



Check the aws console to whether the s3 bucket was created.



We can destroy the s3 bucket anytime using the terraform destroy.



So, now we learned the basics of terraforming, creating the AWS services such as EC2, S3, RDS, and VPC using terraform. 

Now we have created the aws services using the basics only will see the advanced level of all the aws services one by one. 

----------------------------------------!!!! Happy Learning with Techiev !!!!!!!!----------------------------------

-------------------------Subscribe our Youtube Channel by clicking the below link---------------------- ----------------------------!!https://www.youtube.com/@techieview729!!---------------------


                                                












Name

AWS,14,Devops,23,linux,9,
ltr
item
Techie View: Architecting Your AWS Cloud: A Comprehensive Guide to Deploying VPC, Subnet, RDS, and S3
Architecting Your AWS Cloud: A Comprehensive Guide to Deploying VPC, Subnet, RDS, and S3
https://1.bp.blogspot.com/-OTm5UKHTNUo/YNIPlwDIthI/AAAAAAAAAZo/phadzgX9LPIKnrQrgTJR9MxcDtphhP3CQCLcBGAsYHQ/w400-h193/Blank%2Bdiagram%2B%25282%2529.jpeg
https://1.bp.blogspot.com/-OTm5UKHTNUo/YNIPlwDIthI/AAAAAAAAAZo/phadzgX9LPIKnrQrgTJR9MxcDtphhP3CQCLcBGAsYHQ/s72-w400-c-h193/Blank%2Bdiagram%2B%25282%2529.jpeg
Techie View
https://www.techiev.com/2021/06/deploying-aws-services-vpc-subnet-rds-s3.html
https://www.techiev.com/
https://www.techiev.com/
https://www.techiev.com/2021/06/deploying-aws-services-vpc-subnet-rds-s3.html
true
7013663511659419322
UTF-8
Loaded All Posts Not found any posts VIEW ALL View Full Article Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy