From 4f5ea463693e20e819fa2a4135f2bb03c6f30190 Mon Sep 17 00:00:00 2001 From: Franklin Foko Date: Wed, 13 Sep 2023 20:04:59 +0100 Subject: [PATCH 1/5] Add tp-1 forlder --- tp-1/README.md | 16 +++++++ tp-1/ec2.tf | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 tp-1/README.md create mode 100644 tp-1/ec2.tf diff --git a/tp-1/README.md b/tp-1/README.md new file mode 100644 index 0000000..7bcfb9a --- /dev/null +++ b/tp-1/README.md @@ -0,0 +1,16 @@ +Installing minikube on an EC2 machine with Terrafirm + +1. Create and download a public key from AWS and put it in the same directory as the ec2.tf file +2. Creat access key and secret key +3. Go to the directory which contains your public key and the ec2.tf file, then execute the following commands: +``` +terraform init +``` +``` +terraform plan +``` +``` +terraform aplly --auto-approve +``` + +4. Once the execution of the terraform apply command is complete, open the newly created infos_ec2.txt file to retrieve the public IP of EC2 \ No newline at end of file diff --git a/tp-1/ec2.tf b/tp-1/ec2.tf new file mode 100644 index 0000000..9fd7419 --- /dev/null +++ b/tp-1/ec2.tf @@ -0,0 +1,117 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } + } +} + +provider "aws" { + region = "us-east-1" + access_key = "YOUR OWN" + secret_key = "YOUR OWN" +} + + +resource "aws_instance" "myec2" { + ami = "ami-0d71ca6a78e324f68" # CentOS 7 + instance_type = "t3.large" + key_name = "your-public-key.pem" + security_groups = ["franklin-sg"] + + root_block_device { + volume_size = 100 # you can change this value + } + + + connection { + type = "ssh" + user = "centos" + private_key = file("./your-public-key.pem") + host = self.public_ip + } + + provisioner "remote-exec" { + inline = [ + "sudo yum update -y", + "sudo yum -y install epel-release", + "sudo yum -y install nano git libvirt qemu-kvm virt-install virt-top libguestfs-tools bridge-utils", + "sudo yum install socat -y", + "sudo yum install -y conntrack", + "sudo curl -fsSL https://get.docker.com -o get-docker.sh", + "sudo sh get-docker.sh", + "sudo usermod -aG docker centos", + "suudo systemctl start docker", + "suudo systemctl enable docker", + "sudo yum -y install wget", + "sudo wget https://storage.googleapis.com/minikube/releases/v1.11.0/minikube-linux-amd64", + "sudo chmod +x minikube-linux-amd64", + "sudo mv minikube-linux-amd64 /usr/bin/minikube", + "sudo curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.23.0/bin/linux/amd64/kubectl", + "sudo chmod +x kubectl", + "sudo mv kubectl /usr/bin/", + "sudo echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables", + "sudo systemctl enable docker.service", + "sudo systemctl start docker.service", + + ] + } + + +} + +resource "aws_security_group" "allow_http_https" { + name = "foko-sg" + description = "Allow http and https inbound traffic" + + ingress { + description = "https from vpc" + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + description = "http from vpc" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + description = "http from vpc" + from_port = 8080 + to_port = 8080 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + description = "ssh from vpc" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } + +} + +resource "aws_eip" "lb" { + instance = aws_instance.myec2.id + domain = "vpc" + provisioner "local-exec" { + command = "echo PUBLIC IP: ${self.public_ip} > infos_ec2.txt" + } +} + From 5b8110cf7b5d96994de095074a29da9ddb1b16e2 Mon Sep 17 00:00:00 2001 From: Franklin Foko Date: Wed, 13 Sep 2023 20:08:42 +0100 Subject: [PATCH 2/5] Add tp-1 forlder --- tp-1/README.md | 4 ++-- tp-1/ec2.tf | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tp-1/README.md b/tp-1/README.md index 7bcfb9a..82820c6 100644 --- a/tp-1/README.md +++ b/tp-1/README.md @@ -1,4 +1,4 @@ -Installing minikube on an EC2 machine with Terrafirm +Installing minikube on an EC2 machine with Terraform 1. Create and download a public key from AWS and put it in the same directory as the ec2.tf file 2. Creat access key and secret key @@ -10,7 +10,7 @@ terraform init terraform plan ``` ``` -terraform aplly --auto-approve +terraform apply --auto-approve ``` 4. Once the execution of the terraform apply command is complete, open the newly created infos_ec2.txt file to retrieve the public IP of EC2 \ No newline at end of file diff --git a/tp-1/ec2.tf b/tp-1/ec2.tf index 9fd7419..0401e7e 100644 --- a/tp-1/ec2.tf +++ b/tp-1/ec2.tf @@ -16,12 +16,12 @@ provider "aws" { resource "aws_instance" "myec2" { ami = "ami-0d71ca6a78e324f68" # CentOS 7 - instance_type = "t3.large" + instance_type = "t3.large" # you can change this key_name = "your-public-key.pem" security_groups = ["franklin-sg"] - + root_block_device { - volume_size = 100 # you can change this value + volume_size = 100 # you can change this value } From fee8c7e85776927c0dfb9a08e41419674f864076 Mon Sep 17 00:00:00 2001 From: Franklin Foko Date: Wed, 13 Sep 2023 20:12:56 +0100 Subject: [PATCH 3/5] Add tp-1 forlder --- tp-1/README.md | 5 +++++ tp-1/ec2.tf | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tp-1/README.md b/tp-1/README.md index 82820c6..27b766f 100644 --- a/tp-1/README.md +++ b/tp-1/README.md @@ -13,4 +13,9 @@ terraform plan terraform apply --auto-approve ``` +to delete all resources +``` +terraform apply --auto-approve +``` + 4. Once the execution of the terraform apply command is complete, open the newly created infos_ec2.txt file to retrieve the public IP of EC2 \ No newline at end of file diff --git a/tp-1/ec2.tf b/tp-1/ec2.tf index 0401e7e..25094e8 100644 --- a/tp-1/ec2.tf +++ b/tp-1/ec2.tf @@ -17,7 +17,7 @@ provider "aws" { resource "aws_instance" "myec2" { ami = "ami-0d71ca6a78e324f68" # CentOS 7 instance_type = "t3.large" # you can change this - key_name = "your-public-key.pem" + key_name = "your-public-key.pem" # the name of your public key security_groups = ["franklin-sg"] root_block_device { @@ -28,7 +28,7 @@ resource "aws_instance" "myec2" { connection { type = "ssh" user = "centos" - private_key = file("./your-public-key.pem") + private_key = file("./your-public-key.pem") # the public key must be in the same folder as ec2.tf host = self.public_ip } From 707d661c534c3804b46328ca88104700831e1d70 Mon Sep 17 00:00:00 2001 From: Franklin Foko Date: Wed, 13 Sep 2023 20:14:15 +0100 Subject: [PATCH 4/5] Add tp-1 forlder --- tp-1/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tp-1/README.md b/tp-1/README.md index 27b766f..08af148 100644 --- a/tp-1/README.md +++ b/tp-1/README.md @@ -13,9 +13,9 @@ terraform plan terraform apply --auto-approve ``` +4. Once the execution of the terraform apply command is complete, open the newly created infos_ec2.txt file to retrieve the public IP of EC2 + to delete all resources ``` -terraform apply --auto-approve -``` - -4. Once the execution of the terraform apply command is complete, open the newly created infos_ec2.txt file to retrieve the public IP of EC2 \ No newline at end of file +terraform destroy --auto-approve +``` \ No newline at end of file From f3b3938c83294826ddce9c680cac0aafd3689ed2 Mon Sep 17 00:00:00 2001 From: Franklin Foko Date: Wed, 13 Sep 2023 20:15:42 +0100 Subject: [PATCH 5/5] Add tp-1 forlder --- tp-1/ec2.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tp-1/ec2.tf b/tp-1/ec2.tf index 25094e8..84b6a69 100644 --- a/tp-1/ec2.tf +++ b/tp-1/ec2.tf @@ -62,7 +62,7 @@ resource "aws_instance" "myec2" { } resource "aws_security_group" "allow_http_https" { - name = "foko-sg" + name = "franklin-sg" description = "Allow http and https inbound traffic" ingress {