Skip to content

Commit

Permalink
Baseline terraforms
Browse files Browse the repository at this point in the history
  • Loading branch information
xmppjingle committed Jan 22, 2023
1 parent ab2a14c commit c5041cb
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .create.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
provider "aws" {
region = "us-east-1"
}

resource "aws_key_pair" "banda" {
key_name = "banda"
public_key = file("~/.ssh/banda.pub")
}

resource "aws_security_group" "banda" {
name = "banda"
description = "Banda security group"

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

ingress {
from_port = 8080
to_port = 8080
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"]
}
}

resource "aws_instance" "banda" {
ami = "ami-0ff8a91507f77f867"
instance_type = "t2.micro"
key_name = aws_key_pair.banda.key_name
security_groups = [aws_security_group.banda.name]

connection {
type = "ssh"
host = aws_instance.banda.public_ip
user = "ec2-user"
private_key = file("~/.ssh/banda")
}

provisioner "remote-exec" {
inline = [
"sudo yum install -y amazon-linux-extras",
"sudo amazon-linux-extras enable",
"sudo amazon-linux-extras install -y docker",
"sudo service docker start",
"sudo usermod -a -G docker ec2-user"
]
}
}
60 changes: 60 additions & 0 deletions beanstalk.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
resource "aws_elastic_beanstalk_application" "banda" {
name = "banda"
}

resource "aws_iam_role" "banda" {
name = "banda-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "elasticbeanstalk.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}

resource "aws_elastic_beanstalk_environment" "banda" {
name = "banda-env"
application = aws_elastic_beanstalk_application.banda.name
platform = "Docker"
service_role = aws_iam_role.banda.arn

setting {
namespace = "aws:elasticbeanstalk:application:environment"
name = "REDIS_URL"
value = "redis://username:password@host:port"
}

setting {
namespace = "aws:elasticbeanstalk:application:environment"
name = "AWS_ACCESS_KEY"
value = "yourkey"
}

setting {
namespace = "aws:elasticbeanstalk:application:environment"
name = "AWS_SECRET_KEY"
value = "yoursecret"
}
}

resource "aws_security_group" "banda" {
name = "banda"
description = "Allow incoming traffic on port 8080"
}

resource "aws_security_group_rule" "banda_http" {
type = "ingress"
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.banda.id
}

0 comments on commit c5041cb

Please sign in to comment.