Skip to content

Commit

Permalink
Rename folders (#281)
Browse files Browse the repository at this point in the history
* rename aws folder to resources

* update readme.md folder name
  • Loading branch information
DaMandal0rian authored Mar 19, 2024
1 parent 7cefd17 commit 37bf5a6
Show file tree
Hide file tree
Showing 48 changed files with 586 additions and 5 deletions.
10 changes: 5 additions & 5 deletions aws/README.md → resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Before using this framework, ensure you have the following installed:

We use **Terraform** and **AWS** to provision the infrastructure.

Clone the repository and navigate to the testing framework directory **aws**:
Clone the repository and navigate to the testing framework directory **resources**:

### Terraform AWS Folder Structure:
### Terraform Resources Folder Structure:

```
.
Expand Down Expand Up @@ -77,7 +77,7 @@ Clone the repository and navigate to the testing framework directory **aws**:

## Getting started.

- Go to **aws/<network_name>/**
- Go to **resources/<network_name>/**
- rename the terraform.tfvars.example file inside the child module to terraform.tfvars.
- modify the main.tf file if any further changes are needed to customize
- Add your personal AWS access and secret in the terraform.tfvars file
Expand All @@ -88,7 +88,7 @@ Clone the repository and navigate to the testing framework directory **aws**:

## Generate Node keys

Each network will need it's own keys, which you can gather from bitwarden, and extract the zip folder into **aws/<network_name>/**. The files should be named the following.
Each network will need it's own keys, which you can gather from bitwarden, and extract the zip folder into **resources/<network_name>/**. The files should be named the following.

```
.
Expand All @@ -105,7 +105,7 @@ Each network will need it's own keys, which you can gather from bitwarden, and e

## Deploy resources.

1. Go to **aws/<network_name>/** directory and run the following commands to init terraform:
1. Go to **resources/<network_name>/** directory and run the following commands to init terraform:

```
terraform init
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions resources/telemetry/ec2/base/ami.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Data for AWS module
data "aws_ami" "ubuntu_amd64" {
most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

filter {
name = "architecture"
values = ["x86_64"]
}

filter {
name = "root-device-type"
values = ["ebs"]
}

owners = ["099720109477"]
}
9 changes: 9 additions & 0 deletions resources/telemetry/ec2/base/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
cloud {
organization = "subspace-sre"

workspaces {
name = "telemetry-aws"
}
}
}
11 changes: 11 additions & 0 deletions resources/telemetry/ec2/base/dns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data "cloudflare_zone" "cloudflare_zone" {
name = "subspace.network"
}

resource "cloudflare_record" "telemetry_subspace_node" {
zone_id = data.cloudflare_zone.cloudflare_zone.id
name = "${var.domain_prefix}-new"
value = module.telemetry_subspace_node.public_ip
type = "A"
ttl = "3600"
}
49 changes: 49 additions & 0 deletions resources/telemetry/ec2/base/instances.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
resource "aws_instance" "telemetry_subspace_node" {
ami = data.aws_ami.ubuntu_amd64.image_id
instance_type = var.instance_type
subnet_id = aws_subnet.public_subnets.id
availability_zone = var.azs
# Security Group
vpc_security_group_ids = ["${aws_security_group.telemetry-subspace-sg.id}"]
# the Public SSH key
key_name = var.aws_key_name
associate_public_ip_address = true
ebs_optimized = true
ebs_block_device {
device_name = "/dev/sda1"
volume_size = var.telemetry-subspace-node-config.disk-volume-size
volume_type = var.telemetry-subspace-node-config.disk-volume-type
iops = 3000
throughput = 250
}

tags = {
name = "telemetry-subspace-node"
role = "telemetry server"
os_name = "ubuntu"
os_version = "22.04"
arch = "x86_64"
}

depends_on = [
aws_subnet.public_subnets,
aws_internet_gateway.gw
]

lifecycle {

create_before_destroy = true

}

# Setting up the ssh connection
connection {
type = "ssh"
host = self.public_ip
user = "ubuntu"
agent = true
private_key = file("${var.private_key_path}")
timeout = "90s"
}

}
File renamed without changes.
23 changes: 23 additions & 0 deletions resources/telemetry/ec2/base/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Output Variables

output "telemetry_subspace_node_server_id" {
value = aws_instance.telemetry_subspace_node.id
}

output "telemetry_subspace_node_public_ip" {
value = aws_instance.telemetry_subspace_node.public_ip
}

output "telemetry_subspace_node_private_ip" {
value = aws_instance.telemetry_subspace_node.private_ip
}

output "telemetry_subspace_node_ami" {
value = aws_instance.telemetry_subspace_node.ami
}

output "dns-records" {
value = [
cloudflare_record.telemetry_subspace_node.hostname,
]
}
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions resources/telemetry/ec2/base/scripts/installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

# updates
export DEBIAN_FRONTEND=noninteractive
sudo apt update -y

#install nginx, certbot and base packages
sudo apt install curl git openssl gnupg --no-install-recommends -y

# install docker & Docker Compose
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --yes --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update -y
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

# set max socket connections
if ! (grep -iq "net.core.somaxconn" /etc/sysctl.conf && sed -i 's/.*net.core.somaxconn.*/net.core.somaxconn=65535/' /etc/sysctl.conf); then
sudo echo "net.core.somaxconn=65535" >> /etc/sysctl.conf
fi

sudo sysctl -p /etc/sysctl.conf
File renamed without changes.
24 changes: 24 additions & 0 deletions resources/telemetry/ec2/modules/telemetry/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module "telemetry" {
source = "../../base/"
path_to_scripts = "../../base/scripts"
path_to_configs = "../../base/config"

telemetry-subspace-node-config = {
domain-prefix = "telemetry"
instance-type = var.instance_type
deployment-version = 1
regions = var.aws_region
instance-count = var.instance_count
disk-volume-size = var.disk_volume_size
disk-volume-type = var.disk_volume_type
}

cloudflare_api_token = var.cloudflare_api_token
cloudflare_email = var.cloudflare_email
access_key = var.access_key
secret_key = var.secret_key
vpc_id = var.vpc_id
instance_type = var.instance_type
vpc_cidr_block = var.vpc_cidr_block
public_subnet_cidrs = var.public_subnet_cidrs
}
9 changes: 9 additions & 0 deletions resources/telemetry/ec2/modules/telemetry/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "telemetry_subspace_node_ipv4_addresses" {
value = module.telemetry.*.telemetry_subspace_node_public_ip
description = "telemetry node IPv4 Addresses"
}

output "dns-records" {
value = module.telemetry.*.dns-records
description = "DNS records"
}
File renamed without changes.
80 changes: 80 additions & 0 deletions resources/telemetry/ec2/modules/telemetry/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
variable "instance_type" {
default = "m6a.4xlarge"
type = string
}

variable "vpc_id" {
default = "telemetry-vpc"
type = string
}

variable "vpc_cidr_block" {
type = string
}

variable "azs" {
type = string
description = "Availability Zones"
default = "us-west-2c"
}

variable "instance_count" {
type = number
default = 1
}

variable "aws_region" {
description = "aws region"
type = string
default = "us-west-2"
}

variable "public_subnet_cidrs" {
type = string
description = "Public Subnet CIDR values"
default = "172.31.1.0/24"
}

variable "disk_volume_size" {
type = number
}

variable "disk_volume_type" {
type = string
default = "gp3"
}

variable "secret_key" {
type = string
sensitive = true
}

variable "access_key" {
type = string
sensitive = true
}

variable "aws_key_name" {
default = "deployer"
type = string
}

variable "ssh_user" {
default = "ubuntu"
type = string
}

variable "private_key_path" {
type = string
default = "~/.ssh/deployer.pem"
}

variable "cloudflare_email" {
type = string
description = "cloudflare email address"
}

variable "cloudflare_api_token" {
type = string
description = "cloudflare api token"
}
File renamed without changes.
Loading

0 comments on commit 37bf5a6

Please sign in to comment.