Skip to content

Commit

Permalink
Merge pull request #19 from arnavrneo/dev
Browse files Browse the repository at this point in the history
feat/tf-integration
  • Loading branch information
arnavrneo authored Apr 21, 2024
2 parents 026106c + 19ac65a commit 696dcf4
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
*.next
*node_modules
*package-lock.json
*.terraform
*.tfstate
*.tfstate.backup
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ This project uses:
- `MongoDB` as non-relational db for authentication
- `Redis` as in-memory key-value db for url keys management

- For scalability and portability, both the frontend and backend are containerized using Docker and can be spun-up easily using docker-compose.
- Ansible playbooks and roles are used for automating the service setup & infrastructure creation of single (or multiple) EC2 on AWS. They are used for:
- Creation of a security group (with relevant properties) for EC2 instances
- Creation of EC2 instances & attaching of the defined security group
- For scalability and portability, both the frontend and backend are containerized using Docker and can be spun-up easily using docker-compose and can be orchestrated using the Kubernetes (the manifest files have been provided).
- Terraform is used for Infrastructure creation and Ansible playbooks and roles are used for configuring EC2 instances created on AWS providing:
- Installation of Docker on those instances
- Running of the url-shortener service through user input


4 changes: 4 additions & 0 deletions url-shortener/playbook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Creates a security group & an ubuntu-ami backed EC2 instance using the specified

Updates the machine as well as installs the docker required in the next step for running the application.


> [!IMPORTANT]
> The above two playbooks are now replaced by the `terraform`. Either run the above playbooks or use the provided terraform code for infrastructure setup.
### `3_docker_book.yaml`

This provides functionalities for setting up the application files, running the application in the docker as well as the ability to remove the containers on the remote servers.
Expand Down
24 changes: 24 additions & 0 deletions url-shortener/tf/services/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions url-shortener/tf/services/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}

provider "aws" {
region = "us-east-1"
profile = "arnav" # enter relevant aws profile
}

# security group creation
resource "aws_security_group" "urlSG" {
name = "urlshortener-sg"

ingress {
cidr_blocks = ["0.0.0.0/0"]
from_port = 22
to_port = 22
protocol = "tcp"
}

ingress {
cidr_blocks = ["0.0.0.0/0"]
from_port = 3000
to_port = 3000
protocol = "tcp"
}

tags = {
Name = "proj-sg"
}
}

# ec2 instance creation
resource "aws_instance" "urlShortener" {
ami = "ami-080e1f13689e07408"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.urlSG.id]
}

resource "aws_ec2_tag" "ec2_tag" {
key = "Ansible"
resource_id = aws_instance.urlShortener.id
value = "urlShortenerServer"
}


data "aws_caller_identity" "current" {}

output "caller_user" {
description = "AWS Calling user: "
value = data.aws_caller_identity.current.user_id
}

output "public_ip" {
description = "Public IP: "
value = aws_instance.urlShortener.public_ip
}

output "public_dns" {
description = "Public DNS: "
value = aws_instance.urlShortener.public_dns
}

0 comments on commit 696dcf4

Please sign in to comment.