From 3f1d8d822b30ebe2fc64cd9914114abaece17813 Mon Sep 17 00:00:00 2001 From: arunodhayamsam <108027-arunodhayamsam@users.noreply.framagit.org> Date: Mar 25 2022 11:15:28 +0000 Subject: Add the dir name --- diff --git a/.provision/README.md b/.provision/README.md index 5f0a68b..ec3712f 100644 --- a/.provision/README.md +++ b/.provision/README.md @@ -2,6 +2,6 @@ An ansible role deploy the application on host machine(Ubuntu 20.04) -## terraform-aws-deploy +## terraform-aws-lufi -A terraform plan creates necessary AWS infrastructure and deploy the lufi. This terraform plan uses the above ansible roles `ansible-role-lufi` to configure the application on AWS. \ No newline at end of file +A terraform plan creates necessary AWS infrastructure and deploy the lufi. This terraform plan uses the above ansible roles `ansible-role-lufi` to configure the application on AWS. diff --git a/.provision/terraform-aws-deploy/README.md b/.provision/terraform-aws-deploy/README.md deleted file mode 100644 index 6565b5a..0000000 --- a/.provision/terraform-aws-deploy/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Terraform-AWS-Deploy - - This terraform plan create the resourcess of EC2 instance - -## Terraform Variables - Edit the `vars.tf` file to add the variables as per your need. - -| Variable name | Value | Description | -| ------------- | ----- | ----------- | -| `aws_region` | us-east-1 | Set the region | -| `vpc_cidr` | 10.0.0.0/16 | Set the cidr value for the vpc | -| `public_subnet_cidr` | 10.0.2.0/24 | Set the cidr value for the public subnet | -| `user` | ubuntu | Set the EC2 instance user name | -| `public_key` | /home/user_name/.ssh/id_rsa_pub | Set the publickey value for the ec2 instance from the host machine | -| `private_key` | /home/user_name/.ssh/id_rsa | Set the private key value for the ec2 instance from the hostmachine | -| `aws_access_key` | AWSACCESSKEY | Enter your aws access key | -| `aws_secrete_key` | AWSSECRETEKEY | Enter your aws secrete key | -| `instance_name` | Lufi_app_instance | Set the name for instance | diff --git a/.provision/terraform-aws-deploy/main.tf b/.provision/terraform-aws-deploy/main.tf deleted file mode 100644 index f4b7de5..0000000 --- a/.provision/terraform-aws-deploy/main.tf +++ /dev/null @@ -1,126 +0,0 @@ -#Create the VPC -resource "aws_vpc" "MAIN" { - cidr_block = "${var.vpc_cidr}" - enable_dns_hostnames = true - enable_dns_support = true - instance_tenancy = "default" - tags = { - Name = "lufi-master-vpc" - } -} - -# Create InternetGateWay and attach to VPC - -resource "aws_internet_gateway" "IGW" { - vpc_id = "${aws_vpc.MAIN.id}" - tags = { - "Name" = "lufi-master-igw" - } -} - -# Create a public subnet - -resource "aws_subnet" "publicsubnet" { - vpc_id = "${aws_vpc.MAIN.id}" - cidr_block = "${var.public_subnet_cidr}" - map_public_ip_on_launch = true - tags = { - Name = "lufi-master-us-east-1-public" - } -} - -# Create routeTable -resource "aws_route_table" "publicroute" { - vpc_id = "${aws_vpc.MAIN.id}" - route { - cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.IGW.id}" - } - - tags = { - Name = "lufi-master-us-east-1-public-rt" - } -} - -resource "aws_main_route_table_association" "mainRTB" { - vpc_id = "${aws_vpc.MAIN.id}" - route_table_id = "${aws_route_table.publicroute.id}" -} -## Create security group -resource "aws_security_group" "security" { - name = "lufi-master-sg" - description = "allow all traffic" - vpc_id = "${aws_vpc.MAIN.id}" - - ingress { - description = "allow all traffic" - from_port = "0" - to_port = "65535" - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } - ingress { - description = "allow port SSH" - 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"] - } - -} - -#Create key_pair for the instance - -resource "aws_key_pair" "genkey" { - key_name = "lufi.webapp" - public_key = "${file(var.public_key)}" -} - -# Craete ec2 instance -resource "aws_instance" "ec2_instance" { - ami = "ami-04505e74c0741db8d" - instance_type = "t2.medium" - associate_public_ip_address = "true" - subnet_id = "${aws_subnet.publicsubnet.id}" - vpc_security_group_ids = ["${aws_security_group.security.id}"] - key_name = "lufi.webapp" - - connection { - agent = false - type = "ssh" - host = aws_instance.ec2_instance.public_dns - private_key = "${file(var.private_key)}" - user = "${var.user}" - } - - provisioner "remote-exec" { - inline = [ - "sudo apt update -y", - "sudo apt install python3.9 -y", - ] - } - - provisioner "local-exec" { - command = < hosts && \ - echo "[Lufi]" | tee -a hosts && \ - echo "${aws_instance.ec2_instance.public_ip} ansible_user=${var.user} ansible_ssh_private_key_file=${var.private_key}" | tee -a hosts && \ - export ANSIBLE_HOST_KEY_CHECKING=False && \ - ansible-playbook -u ${var.user} --private-key ${var.private_key} -i hosts site.yml - EOT - } - - tags = { - Name = "${var.instance_name}" - } -} - - - diff --git a/.provision/terraform-aws-deploy/output.tf b/.provision/terraform-aws-deploy/output.tf deleted file mode 100644 index 52c6607..0000000 --- a/.provision/terraform-aws-deploy/output.tf +++ /dev/null @@ -1,7 +0,0 @@ -output "public_ip" { - value = "${aws_instance.ec2_instance.public_ip}" -} - -output "App_running_at" { - value = "http://${aws_instance.ec2_instance.public_ip}:8081" -} diff --git a/.provision/terraform-aws-deploy/provider.tf b/.provision/terraform-aws-deploy/provider.tf deleted file mode 100644 index 22f192f..0000000 --- a/.provision/terraform-aws-deploy/provider.tf +++ /dev/null @@ -1,5 +0,0 @@ -provider "aws" { -access_key = "${var.aws_access_key}" -secret_key = "${var.aws_secret_key}" -region = "${var.aws_region}" -} \ No newline at end of file diff --git a/.provision/terraform-aws-deploy/vars.tf b/.provision/terraform-aws-deploy/vars.tf deleted file mode 100644 index f2bfde5..0000000 --- a/.provision/terraform-aws-deploy/vars.tf +++ /dev/null @@ -1,36 +0,0 @@ -variable "aws_region" { - default = "aws_region" -} -variable "vpc_cidr" { - default = "cidr_value" -} -variable "public_subnet_cidr" { - default = "cidr_value" -} -variable "public_subnet1_cidr" { - default = "cidr_value" -} - -variable "user" { - default = "user_of_instance" -} - -variable "public_key" { - default = "$PWD_publickey" -} -variable "private_key" { - default = "$PWD_privatekey" -} -variable "aws_access_key" { - default = "aws_access_key" -} - -variable "aws_secret_key" { - default = "aws_secrete_key" -} - -variable "instance_name" { - default = "instance_name" -} - - diff --git a/.provision/terraform-aws-lufi/README.md b/.provision/terraform-aws-lufi/README.md new file mode 100644 index 0000000..e3b9d26 --- /dev/null +++ b/.provision/terraform-aws-lufi/README.md @@ -0,0 +1,18 @@ +# Terraform-AWS-Lufi + + This terraform plan create the resourcess of EC2 instance + +## Terraform Variables + Edit the `vars.tf` file to add the variables as per your need. + +| Variable name | Value | Description | +| ------------- | ----- | ----------- | +| `aws_region` | us-east-1 | Set the region | +| `vpc_cidr` | 10.0.0.0/16 | Set the cidr value for the vpc | +| `public_subnet_cidr` | 10.0.2.0/24 | Set the cidr value for the public subnet | +| `user` | ubuntu | Set the EC2 instance user name | +| `public_key` | /home/user_name/.ssh/id_rsa_pub | Set the publickey value for the ec2 instance from the host machine | +| `private_key` | /home/user_name/.ssh/id_rsa | Set the private key value for the ec2 instance from the hostmachine | +| `aws_access_key` | AWSACCESSKEY | Enter your aws access key | +| `aws_secrete_key` | AWSSECRETEKEY | Enter your aws secrete key | +| `instance_name` | Lufi_app_instance | Set the name for instance | diff --git a/.provision/terraform-aws-lufi/main.tf b/.provision/terraform-aws-lufi/main.tf new file mode 100644 index 0000000..f4b7de5 --- /dev/null +++ b/.provision/terraform-aws-lufi/main.tf @@ -0,0 +1,126 @@ +#Create the VPC +resource "aws_vpc" "MAIN" { + cidr_block = "${var.vpc_cidr}" + enable_dns_hostnames = true + enable_dns_support = true + instance_tenancy = "default" + tags = { + Name = "lufi-master-vpc" + } +} + +# Create InternetGateWay and attach to VPC + +resource "aws_internet_gateway" "IGW" { + vpc_id = "${aws_vpc.MAIN.id}" + tags = { + "Name" = "lufi-master-igw" + } +} + +# Create a public subnet + +resource "aws_subnet" "publicsubnet" { + vpc_id = "${aws_vpc.MAIN.id}" + cidr_block = "${var.public_subnet_cidr}" + map_public_ip_on_launch = true + tags = { + Name = "lufi-master-us-east-1-public" + } +} + +# Create routeTable +resource "aws_route_table" "publicroute" { + vpc_id = "${aws_vpc.MAIN.id}" + route { + cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.IGW.id}" + } + + tags = { + Name = "lufi-master-us-east-1-public-rt" + } +} + +resource "aws_main_route_table_association" "mainRTB" { + vpc_id = "${aws_vpc.MAIN.id}" + route_table_id = "${aws_route_table.publicroute.id}" +} +## Create security group +resource "aws_security_group" "security" { + name = "lufi-master-sg" + description = "allow all traffic" + vpc_id = "${aws_vpc.MAIN.id}" + + ingress { + description = "allow all traffic" + from_port = "0" + to_port = "65535" + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + ingress { + description = "allow port SSH" + 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"] + } + +} + +#Create key_pair for the instance + +resource "aws_key_pair" "genkey" { + key_name = "lufi.webapp" + public_key = "${file(var.public_key)}" +} + +# Craete ec2 instance +resource "aws_instance" "ec2_instance" { + ami = "ami-04505e74c0741db8d" + instance_type = "t2.medium" + associate_public_ip_address = "true" + subnet_id = "${aws_subnet.publicsubnet.id}" + vpc_security_group_ids = ["${aws_security_group.security.id}"] + key_name = "lufi.webapp" + + connection { + agent = false + type = "ssh" + host = aws_instance.ec2_instance.public_dns + private_key = "${file(var.private_key)}" + user = "${var.user}" + } + + provisioner "remote-exec" { + inline = [ + "sudo apt update -y", + "sudo apt install python3.9 -y", + ] + } + + provisioner "local-exec" { + command = < hosts && \ + echo "[Lufi]" | tee -a hosts && \ + echo "${aws_instance.ec2_instance.public_ip} ansible_user=${var.user} ansible_ssh_private_key_file=${var.private_key}" | tee -a hosts && \ + export ANSIBLE_HOST_KEY_CHECKING=False && \ + ansible-playbook -u ${var.user} --private-key ${var.private_key} -i hosts site.yml + EOT + } + + tags = { + Name = "${var.instance_name}" + } +} + + + diff --git a/.provision/terraform-aws-lufi/output.tf b/.provision/terraform-aws-lufi/output.tf new file mode 100644 index 0000000..52c6607 --- /dev/null +++ b/.provision/terraform-aws-lufi/output.tf @@ -0,0 +1,7 @@ +output "public_ip" { + value = "${aws_instance.ec2_instance.public_ip}" +} + +output "App_running_at" { + value = "http://${aws_instance.ec2_instance.public_ip}:8081" +} diff --git a/.provision/terraform-aws-lufi/provider.tf b/.provision/terraform-aws-lufi/provider.tf new file mode 100644 index 0000000..22f192f --- /dev/null +++ b/.provision/terraform-aws-lufi/provider.tf @@ -0,0 +1,5 @@ +provider "aws" { +access_key = "${var.aws_access_key}" +secret_key = "${var.aws_secret_key}" +region = "${var.aws_region}" +} \ No newline at end of file diff --git a/.provision/terraform-aws-lufi/vars.tf b/.provision/terraform-aws-lufi/vars.tf new file mode 100644 index 0000000..f2bfde5 --- /dev/null +++ b/.provision/terraform-aws-lufi/vars.tf @@ -0,0 +1,36 @@ +variable "aws_region" { + default = "aws_region" +} +variable "vpc_cidr" { + default = "cidr_value" +} +variable "public_subnet_cidr" { + default = "cidr_value" +} +variable "public_subnet1_cidr" { + default = "cidr_value" +} + +variable "user" { + default = "user_of_instance" +} + +variable "public_key" { + default = "$PWD_publickey" +} +variable "private_key" { + default = "$PWD_privatekey" +} +variable "aws_access_key" { + default = "aws_access_key" +} + +variable "aws_secret_key" { + default = "aws_secrete_key" +} + +variable "instance_name" { + default = "instance_name" +} + +