Skip to content

Commit

Permalink
ci: Create bench server with Terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelburnham committed Jun 7, 2024
1 parent f1df3b3 commit fbcd417
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 0 deletions.
116 changes: 116 additions & 0 deletions .github/server-setup/proof-server.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}

provider "aws" {
access_key = var.aws_access_key_id
secret_key = var.aws_secret_access_key
region = "us-east-2"
}

variable "aws_access_key_id" {
type = string
}

variable "aws_secret_access_key" {
type = string
}

resource "aws_key_pair" "deployer" {
key_name = "server-key"
public_key = var.server_pub_key
}

variable "server_pub_key" {
type = string
}

variable "server_private_key" {
type = string
}

resource "aws_security_group" "allow_ssh" {
name_prefix = "allow_ssh"

ingress {
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"]
}
}

resource "aws_instance" "example_server" {
# Ubuntu 24.04 image provided by AWS
ami = "ami-09040d770ffe2224f"
instance_type = "r7iz.metal-16xl"
key_name = aws_key_pair.deployer.key_name
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
#user_data = file("${path.module}/setup.sh")

connection {
type = "ssh"
user = "ubuntu"
private_key = var.server_private_key
host = self.public_dns
}

root_block_device {
volume_size = 50 # disk size in GB
volume_type = "gp3"
}

#provisioner "file" {
# source = "./setup.sh"
# destination = "/home/ubuntu/setup.sh"
#}

#provisioner "file" {
# source = "./add-user.sh"
# destination = "/home/ubuntu/add-user.sh"
#}

#provisioner "file" {
# source = "./tailscale-key"
# destination = "/home/ubuntu/tailscale-key"
#}

#provisioner "remote-exec" {
# inline = [
# "chmod +x /home/ubuntu/*.sh"

# ]
#}

tags = {
Name = "Example-Server"
}
}


#resource "aws_eip" "example_ip" {
# domain = "vpc"
#}
#
#resource "aws_eip_association" "example_eip_assoc" {
# instance_id = aws_instance.example_server.id
# allocation_id = aws_eip.example_ip.id
#}
#
## Print the Elastic IP
#output "instance_ip" {
# value = aws_eip.example_ip.public_ip
# description = "The public IP of the instance."
#}
33 changes: 33 additions & 0 deletions .github/workflows/bench-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deploy AWS Server with Terraform

on:
push:
branches: ci-bench-server

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- name: Initialize Terraform
run: terraform -chdir=${{ github.workspace }}/.github/server-setup init
- name: Apply Terraform changes
run: terraform -chdir=${{ github.workspace }}/.github/server-setup apply -auto-approve -input=false
env:
TF_VAR_aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
TF_VAR_aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_server_pub_key: ${{ secrets.SERVER_PUB_KEY }}
TF_VAR_server_private_key: ${{ secrets.SERVER_PRIVATE_KEY }}
- run: terraform -chdir=${{ github.workspace }}/.github/server-setup destroy -auto-approve -input=false
env:
TF_VAR_aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
TF_VAR_aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_server_pub_key: ${{ secrets.SERVER_PUB_KEY }}
TF_VAR_server_private_key: ${{ secrets.SERVER_PRIVATE_KEY }}
#- name: Tailscale
# uses: tailscale/github-action@v2
# with:
# oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
# oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
# tags: tag:ci

0 comments on commit fbcd417

Please sign in to comment.