Terraform Notes – Day 2 – 19 Sept 2023
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
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
- 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
- .tfvars
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"
}
}