-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Create bench server with Terraform
- Loading branch information
1 parent
f1df3b3
commit fbcd417
Showing
2 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |