Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added terrafrom files #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# maven-standalone-application
This barch contains the necessary terrafrorm codes for creating resources in aws
21 changes: 21 additions & 0 deletions terraform-eks/db/db.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
resource "aws_instance" "db" {
ami = "ami-03a0c45ebc70f98ea"
instance_type = "t2.micro"
# subnet_id = module.eip.aws_subnet.demo.id
tags = {
Name = "DB Server"
}
}

# module "eip" {
# source = "../eip" // child module is called becoz subnet_id is referencing it as module.eip
# instance_id = aws_insatnce.db.id // declaring instance.id from the eip module
# }

# module "sg" {
# source = "../sg"
# }

output "PrivateIP" {
value = aws_instance.db.private_ip
}
44 changes: 44 additions & 0 deletions terraform-eks/eip/eip.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
variable "instance_id" {
type = string
}

resource "aws_eip" "web_ip" {
instance = var.instance_id
# depends_on = [
# aws_internet_gateway.demo
# ]
}

# resource "aws_vpc" "demo" {
# cidr_block = "10.0.0.0/16"

# tags = {
# Name = "myDemoVPC"
# }
# }

# resource "aws_internet_gateway" "demo" {
# vpc_id = aws_vpc.demo.id // the .id is attached because vpc is being called inside igw

# tags = {
# Name = "myDemoIGW"
# }
# }

# resource "aws_subnet" "demo" {

# availability_zone = us-east-2a
# cidr_block = "10.0.0.0/24"
# map_public_ip_on_launch = true
# vpc_id = aws_vpc.demo.id

# // depends_on = [aws_internet_gateway.gw]

# tags = {
# Name = "Public Subnet"
# }
# }

output "PublicIP" {
value = aws_eip.web_ip.public_ip
}
36 changes: 36 additions & 0 deletions terraform-eks/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* this is the main module block created in the current and parent directory.
From this module block, child blocks can be called in the main.tf module and should be
referenced properly.
*/
//Terraform block
terraform {
required_version = "~> 1.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0" # Optional but recommended in production
}
}
}

//Provider block
provider "aws" {
region = "us-east-2"
profile = "terence"
}

module "db" { //this is initializing the db module/directory
source = "./db"
}

module "web" { // eip and sg were ran as child modules inside this module
source = "./web"
}

output "PrivateIP" {
value = module.db.PrivateIP // this specified in the db module/directory
}

output "PublicIP" {
value = module.web.pub_ip //calling the web eip
}
45 changes: 45 additions & 0 deletions terraform-eks/sg/sg.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
variable "ingress" {
type = list(number)
default = [80, 443]
}

variable "egress" {
type = list(number)
default = [0]
}

resource "aws_security_group" "web_traffic" {
name = "Allow Web Traffic"
# vpc_id = module.eip.aws_vpc.demo.id

dynamic "ingress" {
iterator = port
for_each = var.ingress
content {
from_port = port.value
to_port = port. value
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
}

dynamic "egress" {
iterator = port
for_each = var.egress
content {
from_port = port.value
to_port = port. value
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
}
}

# module "eip" {
# source = "../eip"
# instance_id = aws_vpc.demo.id
# }

output "sg_name" {
value = aws_security_group.web_traffic.name
}
8 changes: 8 additions & 0 deletions terraform-eks/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 4,
"terraform_version": "1.0.11",
"serial": 10,
"lineage": "f999bcf5-b749-4305-0dcd-f536b16a3751",
"outputs": {},
"resources": []
}
Loading