Terraform Notes – Day 2 – 19 Sept 2023

DevOps

MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
🚀 Everyone wins.

Start Your Journey with Motoshare

Assignment

Publish a code on www.Debug.School using CODE Block.

Write a terraform code would create following resources
- keypair  (Pub - ON AWS - PVT - Local)
- Display a pvt on Console
- Create a Security group must open 80 Port
- Create a Ec2 instance Ubuntu using the same Key & SG which you created above.
- You must install/Start apache2 in EC2 instance
	$ apt-get update
	$ apt-get install apache2 -y
	$ systemctl start apache2
Code language: JavaScript (javascript)

  • https://registry.terraform.io/browse/modules
  • https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/latest

How to pass values from on terraform module to another

  • https://www.devopsschool.com/blog/how-to-use-one-modules-variable-in-another-module-in-terraform/
What is Module?
--------------------------
Is a dir structure
	contains
		- .tf
		- .tfvars
-===========================
YES - root module
	- Also would call child modules

child module
Is a dir structure
	contains
		- .tf
		- .tfvars
============================================
DevOpsX
	main.tf
		<module>webserver</module>
		<module>network</module>
		<module>dbserver</module>
	.tfvars
	webserver
		- .tf
		- .tfvars
	network
		- .tf
		- .tfvars
	dbserver
		- .tf
		- .tfvars
	appserver
		- .tf
		- .tfvarsCode language: HTML, XML (xml)

Root Module Code

module "webserver" {
  source      = "./webserver"
}

module "dbserver" {
  source      = "./dbserver"
}

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"

  name = "my-vpc"
  cidr = "10.0.0.0/16"

  azs             = ["us-east-1a", "us-east-1b", "us-east-1c"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]

  enable_nat_gateway = false
  enable_vpn_gateway = false

  tags = {
    Terraform = "true"
    Environment = "dev"
  }
}Code language: JavaScript (javascript)
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x